pilwon / node-yahoo-finance

Yahoo Finance historical quotes and snapshot data downloader written in Node.js
488 stars 123 forks source link

(Error: Failed to download data) after trying to run this program in a loop #84

Open destroyer22719 opened 2 years ago

destroyer22719 commented 2 years ago
Error: Failed to download data (404 - {"quoteSummary":{"result":null,"error":{"code":"Not Found","description":"No fundamentals data found for any of the summaryTypes=summaryDetail,financialData,defaultKeyStatistics,summaryProfile"}}})
    at /home/nathan/Downloads/Code_Projects/investing/node_modules/yahoo-finance/lib/quote.js:146:15
    at tryCatcher (/home/nathan/Downloads/Code_Projects/investing/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/nathan/Downloads/Code_Projects/investing/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/home/nathan/Downloads/Code_Projects/investing/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/home/nathan/Downloads/Code_Projects/investing/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/home/nathan/Downloads/Code_Projects/investing/node_modules/bluebird/js/release/promise.js:725:18)
    at _drainQueueStep (/home/nathan/Downloads/Code_Projects/investing/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/home/nathan/Downloads/Code_Projects/investing/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/home/nathan/Downloads/Code_Projects/investing/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/home/nathan/Downloads/Code_Projects/investing/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:456:21)

My code:

const getData = async (name, symbol, loc) => {
    try {
        const data = await yahooFinance.quote({
            symbol,
            modules: [
                "summaryDetail",
                "defaultKeyStatistics",
                "financialData",
                "summaryProfile",
            ],
        });

       return data

     } catch (err) {
        console.log(err)
    }
};

...

for (const stock of rows) {
   const data = await getData(stock.symbol)
  console.log(data)
}

That above isn't exactly my code but more or less what it is.

gadicc commented 2 years ago

Hey @destroyer22719. This error is because you're asking for data that doesn't exist for one of the symbols you're fetching in your loop. You should wrap the call in a try...catch and then I guess then try loop over each individual module type (also in a try...catch) if you want to get the max amount of information possible).

I have a feeling in v2 (see the README) the errors are more descriptive and it will be easier to tell which symbols are generating these errors.