node-yahoo-finance2 icon indicating copy to clipboard operation
node-yahoo-finance2 copied to clipboard

quoteCombine: ❌ Error fetching BTC-USD: Failed Yahoo Schema validation

Open Sireini opened this issue 11 months ago • 1 comments

Validation Error

❌ Error fetching BTC-USD: Failed Yahoo Schema validation

Minimal Reproduction

private trackedAssets = new Set<string>(['AAPL', 'TSLA', 'BTC-USD']);
async fetchPrices() {
  for (const asset of this.trackedAssets) {
    try {
      const result = await yahooFinance.quoteCombine(asset, {
        fields: ['symbol', 'regularMarketPrice'],
      });
      const price = result.regularMarketPrice;
      console.log(`📈 ${asset} - ${price}`);
    } catch (error) {
      console.error(`❌ Error fetching ${asset}:`, error.message);
    }
  }
}

Symbol(s) that it happened for

  • BTC-USD
  • ETH-USD
  • HASHAI-USD
  • SOL-USD

Error Message


❌ Error fetching SOL-USD: Failed Yahoo Schema validation

"message": "Expected union value"

Environment

Browser or Node: 22.13.0 Node version (if applicable): 22.13.0 Npm version: 10.9.2 Browser version (if applicable): Library version (e.g. 1.10.1): 2.13.3

Additional Context

I did clone the repo and run the tests with those symbols but all seem to pass..

Sireini avatar Feb 05 '25 20:02 Sireini

I have the same issue.

marinsarbulescu avatar Apr 24 '25 22:04 marinsarbulescu

I am having the same issue. It was working fine until yesterday.

unav4ila8le avatar Jun 27 '25 16:06 unav4ila8le

I switched to a different API for the BTC-USD price fetch.

marinsarbulescu avatar Jun 27 '25 16:06 marinsarbulescu

Hi all. I do apologise for the late reply, especially this year while I've been travelling extensively.

A few things:

  1. A reminder that you can disable validation for any request (see https://github.com/gadicc/node-yahoo-finance2/blob/devel/docs/validation.md#skip-validation-completely - the link is also given in the validation error itself). But of course, we still recommend to rather catch errors and then decide what to do.

  2. Please, if someone experiences this again, if they could provide the full error. All these symbols are passing for me. These kind of errors can be temporary intermittent errors from Yahoos servers, or temporary market data that differs by timezone and region, or changes in the data structure. It's impossible to guess.

  3. v3 is also available. Although not "official" yet, a lot of people are using it, and it includes fixes that I simply don't have the time to backport to the v2 branch, unfortunately.

Thanks everyone 🙏

gadicc avatar Jun 27 '25 23:06 gadicc

@gadicc I am also getting the same error and it's not intermittent, but has occurred every time I request the BTC-USD pair.

I tried v3 and get the same error.

I attached the output errors for each version. yf2-stringified.log is the JSON.stringify()-ed v2 output which is extremely long. The direct error output in all the logs is towards the bottom after "Validation error:"

I am calling it with this line:

const quotes = yahooFinance.quote(['BTC-USD', { fields: ['regularMarketPrice', 'symbol', 'currency'] })

Disabling validation works for me as a stopgap

Error logs: yf2-stringified.log yf2.log yf3.log

borisjoffe avatar Jun 28 '25 01:06 borisjoffe

Hey @borisjoffe - thanks so much, that was hugely helpful.

So, looking at yf3.log, the relevant part is:

      {
        "schemaPath": "#/definitions/QuoteCryptoCurrency/required",
        "instancePath": "/0",
        "message": "Missing required properties",
        "params": {
          "missing": [
            "circulatingSupply",
            "fromCurrency",
            "lastMarket",
            "priceHint",
            "toCurrency"
          ]
        }
      },

i.e., those fields were missing. And notably, only sometimes... whether it's a timezone or region thing. Or perhaps they get the data from multiple sources and some of those sources don't provide the above, so Yahoo just doesn't provide them when it doesn't have them.

It's a bit disappointing that we can't always rely on things like circulatingSupply but I guess it's better to not require it rather than have these surprise fails. Of course, for anyone using typescript, the compiler will make sure that your code is still safe even after this update.

Just published to 3.3.7 - can you confirm if this solves this for you?

gadicc avatar Jun 28 '25 02:06 gadicc

I know other people must have said this a thousand times, but thank you guys so much for making this API available for free. Cheers to you and others that keep the open source coming. Thank you!

marinsarbulescu avatar Jun 28 '25 16:06 marinsarbulescu

Thanks so much, @marinsarbulescu. Maintaining the project can be quite draining at times, so, it's really great to get messages like this 🙏 Thanks for your support and kind words.

gadicc avatar Jun 29 '25 00:06 gadicc

@gadicc Upgrading to 3.3.7 works. Thank you

Also, this is somewhat unrelated, but is yahooFinance.suppressNotices(['yahooSurvey']) not available in v3?

I monkeypatched console.log for now to suppress the survey text. Do you want me to create a new issue for it, or are you aware of it?

borisjoffe avatar Jun 29 '25 21:06 borisjoffe

Hey @borisjoffe, thanks for confirming!

Right you are about supressNotices - addressed in #927 - thanks for raising that. If you notice anythign else missing in v3, please do feel free to open a new issue 🙏

gadicc avatar Jun 30 '25 01:06 gadicc