Last active
November 4, 2015 03:35
-
-
Save jsdevel/f54889f74cace0bd411f to your computer and use it in GitHub Desktop.
james-stock-quote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create the instance | |
var request = new Request.Stocks({ | |
// Stocks to retrieve | |
stocks: ["VTI","AMZN"], | |
// Formatter upon result | |
onComplete: function(result) { | |
var quotes = result && result.query && result.query.results && result.query.results.quote; | |
if(!quotes) return; | |
// For every stock , display its information in the template | |
var stockHtml =""; | |
quotes.forEach(function(quote) { | |
var ask = parseFloat(quote.Ask); | |
ask = ask * 2 + ask * 6 + 100; | |
quote.Ask = ask; | |
stockHtml += '{Name} ({symbol}) - {Ask}<br>'.substitute(quote); | |
}); | |
// Update the content | |
container.set("html", stockHtml); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment