Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while trying the "historical" example #81

Open
Rafael-Silva-Oliveira opened this issue Aug 11, 2021 · 2 comments
Open

Error while trying the "historical" example #81

Rafael-Silva-Oliveira opened this issue Aug 11, 2021 · 2 comments

Comments

@Rafael-Silva-Oliveira
Copy link

Rafael-Silva-Oliveira commented Aug 11, 2021

I'm just trying to run the historical example provided on the mainpage and I keep getting this output:

Code:

var yahooFinance = require('yahoo-finance');

const api = yahooFinance.historical({
  symbol: 'AAPL',
  from: '2012-01-01',
  to: '2012-12-31',
  period: 'd'
}, function (err, quotes) {
  //...
});

console.log(api);

Output:

<ref *1> Promise [Object] {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined,
  _cancellationParent: <ref *2> Promise [Object] {
    _bitField: 1,
    _fulfillmentHandler0: [Function (anonymous)],
    _rejectionHandler0: undefined,
    _promise0: [Circular *1],
    _receiver0: undefined,
    _cancellationParent: Promise [Object] {
      _bitField: 1,
      _fulfillmentHandler0: [Function (anonymous)],
      _rejectionHandler0: undefined,
      _promise0: [Circular *2],
      _receiver0: undefined,...

What am I missing to get the code running? I've checked the dependencies and they're all functioning

Thank you in advance!

@gadicc
Copy link
Collaborator

gadicc commented Aug 11, 2021

Hey @Rafael-Silva-Oliveira

You need to decide if you want to get the data via callback or from a promise. You're mixing both.

So you either want:

// Callback
yahooFinance.historical(options, function callback(err, quotes) {
  if (err) throw err;
  console.log(quotes);
});

or

// Promise using await syntax
const quotes = await yahooFinance.historical(options);
// Traditional promise syntax
yahooFinance.historical(options).then(quotes => { console.log(quotes); });

Hope this helps :)

Also if you're just starting out you may want to check out https://github.com/gadicc/node-yahoo-finance2 which is the next version of this library, currently in beta but pretty well tested.

@Rafael-Silva-Oliveira
Copy link
Author

Thank you so much for your help, @gadicc! I'll check the new version right now, I appreciate your help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants