Skip to content

Instantly share code, notes, and snippets.

@jsdevel
Last active November 4, 2015 03:35
Show Gist options
  • Save jsdevel/f54889f74cace0bd411f to your computer and use it in GitHub Desktop.
Save jsdevel/f54889f74cace0bd411f to your computer and use it in GitHub Desktop.
james-stock-quote
// 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