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

ISSUE : Getting all quotes through loop condition #780

Open
kkh3868 opened this issue Jun 7, 2024 · 2 comments
Open

ISSUE : Getting all quotes through loop condition #780

kkh3868 opened this issue Jun 7, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@kkh3868
Copy link

kkh3868 commented Jun 7, 2024

Bug Report

Describe the bug

    for (const stock of stockInformation) {
      console.log(`Symbol: ${stock.symbol}, Quantity: ${stock.quantity}`);
      
      const quote = parseFloat(await yf2.quote(stock.symbol)); // this line may cause the error

      console.log(`quote : ${quote }`);
      const totalValuePerStock = quote * stock.quantity;

      totalValue += totalValuePerStock;
      symbols.push(stock.symbol);
      quantities.push(stock.quantity);
      totalValuePerStocks.push(totalValuePerStock);
    }

the result is.....

memberId : 1
Symbol: AAPL, Quantity: 14
Please consider completing the survey at https://bit.ly/yahoo-finance-api-feedback if you haven't already; for more info see #764 (comment).
Fetching crumb and cookies from https://finance.yahoo.com/quote/AAPL...
We expected a redirect to guce.yahoo.com, but got https://finance.yahoo.com/quote/AAPL/
We'll try to continue anyway - you can safely ignore this if the request succeeds
Success. Cookie expires on Sun Jun 08 2025 04:55:29 GMT+0900 (대한민국 표준시)
fetch https://query1.finance.yahoo.com/v1/test/getcrumb
New crumb: X2Q5c9WZbWY
quote : NaN
Symbol: TSLA, Quantity: 15
quote : NaN
Symbol: ALI=F, Quantity: 1
quote : NaN
Symbol: NVDA, Quantity: 6
quote : NaN

Minimal Reproduction

this yahoofinance.quote function occurs crumb error

Environment

Browser or Node:
Node version (if applicable): v20.11.1
Npm version: 10.8.1
Browser verion (if applicable): chrome 125.0.6422.142
Library version (e.g. 1.10.1): 2.11.3

Additional Context

@kkh3868 kkh3868 added the bug Something isn't working label Jun 7, 2024
@glaucoheitor
Copy link
Contributor

quote returns an object, Seems like you are trying to parseFloat that object instead of the current price.
The current price would be the regularMarketPrice

You need to do something like this:

const quote = await yf2.quote(stock.symbol)
const currentPrice = quote?.regularMarketPrice

See https://github.com/gadicc/node-yahoo-finance2/blob/devel/docs/modules/quote.md

@kkh3868
Copy link
Author

kkh3868 commented Jun 8, 2024

@glaucoheitor
thanks for your help! it really works!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants