Search code examples
meteoryahoo-finance

Yahoo Finance Meteor Package, difficulty with stock symbol


I have successfully hooked up a Meteor Yahoo finance package. When I use a stock symbol like this "GOOG" it works fine, however when I use something like this "ENW.V" it fails.

Here is my stock Template

<template name="stock">
  <h2>{{stock.symbol}}</h2>
    <ul>
    <li><strong>Name</strong> {{stock.name}}</li>
    <li><strong>Ask</strong> {{stock.ask}}</li>
    <li><strong>Bid</strong> {{stock.bid}}</li>
  </ul>
</template>

Here is my client side code.

Template.stock.rendered = function (){

  if ( _.isEmpty(Session.get('ENW.V')) ) {
    Meteor.call('getQuote', 'ENW.V', function(err, result) {
                Session.set('ENW.V', result.ENW.V); // I think this is the error          });
    }
}

Template.stock.helpers({
    stock: function() {
        return Session.get('ENW.V');
    }
})

Here is my Server side code

Meteor.methods({
  getQuote: function( stockname ) {
    return YahooFinance.snapshot({symbols: [stockname] });
  }
});

My assumption is the result.ENW.V is causing the error, I am guessing that the result is coming from the getQuote method and that there must be a way to grab the result.ENW.V without having to have the ".V" part.

I am more than happy to add more info if needed. Here is the stock I am looking at in YQL Console search. https://goo.gl/hJvkSs

New Error with bracket notation added

Exception in delivering result of invoking 'getQuote': ReferenceError: ENW is not defined


Solution

  • Use bracket notation to access properties which are not valid identifiers:

    result['ENW.V']