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

i found a bug with 3 module return bad request trendingSymbols, dailyGainers, screener

Open pingplass123 opened this issue 1 year ago • 5 comments

Bug Report

Describe the bug

when i try to use this 3 module trendingSymbols, screener, dailyGainers for parameter i try to use the same as docs when call yahoo finance return bad request with all 3 module

Minimal Reproduction

  const result = await yahooFinance.trendingSymbols(region, queryOptions);
  
  yahooFinance.screener({ scrIds: 'aggressive_small_caps', count: 5, region: 'US', lang: 'en-US' })

  
  const queryOptions = { count: 5, region: 'US', lang: 'en-US' };
  return await yahooFinance.dailyGainers(queryOptions);
  
  response: 
  {
    "message": "Missing required query parameters",
    "error": "Bad Request",
    "statusCode": 400
 }
  

Environment

Browser or Node: Node version (if applicable): 18 Npm version: Browser verion (if applicable): Library version (e.g. 1.10.1): 2.13.2

Additional Context

pingplass123 avatar Oct 15 '24 07:10 pingplass123

@gadicc do you have time to see this?

pingplass123 avatar Oct 15 '24 11:10 pingplass123

@pingplass123, trendingSymbols and screener worked fine for me, but maybe I didn't quite understand your code. Code sample and output below. Those 400 "Bad Request" errors can often be transient errors on Yahoo, that fix themselves. dailyGainers had a validation which I'll need to look into, however, that error comes with instructions on how you can disable validation per request if you'd like.

test.js
import yahooFinance from "./dist/esm/src/index-node.js";

const queryOptions = { count: 5, region: "US", lang: "en-US" };
console.log(await yahooFinance.trendingSymbols("US", queryOptions));
console.log(
  await yahooFinance.screener({
    scrIds: "aggressive_small_caps",
    count: 5,
    region: "US",
    lang: "en-US",
  }),
);

// This had validation error, I didn't include the output below
console.log(await yahooFinance.dailyGainers(queryOptions));
results
(node:2745761) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
{
  count: 5,
  quotes: [
    { symbol: 'MS' },
    { symbol: 'ATNF' },
    { symbol: 'SMR' },
    { symbol: 'NVAX' },
    { symbol: 'DRUG' }
  ],
  jobTimestamp: 1729092159784,
  startInterval: 202410161400
}
Please consider completing the survey at https://bit.ly/yahoo-finance-api-feedback if you haven't already; for more info see https://github.com/gadicc/node-yahoo-finance2/issues/764#issuecomment-2056623851.  This will only be shown once, but you can supress this message in future with `yahooFinance.supressNotices(['yahooSurvey'])`.
Fetching crumb and cookies from https://finance.yahoo.com/quote/AAPL...
fetch https://guce.yahoo.com/consent?brandType=nonEu&gcrumb=MxqwGmI&done=https%3A%2F%2Ffinance.yahoo.com%2Fquote%2FAAPL
fetch https://consent.yahoo.com/v2/collectConsent?sessionId=3_cc-session_59a64a13-9e10-459f-8d09-f8d40b93af93
fetch https://consent.yahoo.com/v2/collectConsent?sessionId=3_cc-session_59a64a13-9e10-459f-8d09-f8d40b93af93
fetch https://guce.yahoo.com/copyConsent?sessionId=3_cc-session_59a64a13-9e10-459f-8d09-f8d40b93af93&lang=en-GB
Fetching crumb and cookies from https://finance.yahoo.com/quote/AAPL?guccounter=1...
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 Infinity
fetch https://query1.finance.yahoo.com/v1/test/getcrumb
New crumb: VtAjDVs8QG5
{
  id: 'af57f75b-eb22-4565-a604-5eb8744dd35c',
  title: 'Aggresive small cap stocks',
  description: 'Small cap stocks with high earnings growth rates',
  canonicalName: 'AGGRESSIVE_SMALL_CAPS',
  criteriaMeta: {
    size: 5,
    offset: 0,
    sortField: 'eodvolume',
    sortType: 'DESC',
    quoteType: 'EQUITY',
    criteria: [ [Object], [Object], [Object] ],
    topOperator: 'AND'
  },
  rawCriteria: '{"offset":0,"size":5,"sortField":"eodvolume","sortType":"desc","quoteType":"equity","query":{"operator":"and","operands":[{"operator":"gt","operands":["epsgrowth.lasttwelvemonths",25.0]},{"operator":"lt","operands":["intradaymarketcap",2000000000]},{"operator":"or","operands":[{"operator":"eq","operands":["exchange","NMS"]},{"operator":"eq","operands":["exchange","NYQ"]}]}]}}',
  start: 0,
  count: 5,
  total: 356,
  quotes: [
    {
      language: 'en-US',
      region: 'US',
      quoteType: 'EQUITY',
      typeDisp: 'Equity',
      quoteSourceName: 'Nasdaq Real Time Price',
      triggerable: false,
      customPriceAlertConfidence: 'LOW',
      lastCloseTevEbitLtm: 14.271883,
      lastClosePriceToNNWCPerShare: -0.03532813510251644,
      currency: 'USD',
      regularMarketChangePercent: 2.2916594,
      hasPrePostMarketData: true,
      firstTradeDateMilliseconds: 1498138200000,
      priceHint: 4,
      regularMarketChange: 0.05499983,
      regularMarketTime: 1729092481,
      regularMarketPrice: 2.455,
      regularMarketDayHigh: 2.49,
      regularMarketDayRange: [Object],
      regularMarketDayLow: 2.4145,
      regularMarketVolume: 282510,
      regularMarketPreviousClose: 2.4,
      bid: 2.46,
      ask: 2.47,
      bidSize: 32,
      askSize: 13,
      market: 'us_market',
      messageBoardId: 'finmb_25933',
      fullExchangeName: 'NYSE',
      longName: 'Altice USA, Inc.',
      financialCurrency: 'USD',
      regularMarketOpen: 2.43,
      averageDailyVolume3Month: 3114195,
      averageDailyVolume10Day: 1674230,
      fiftyTwoWeekLowChange: 0.93499994,
      fiftyTwoWeekLowChangePercent: 0.61513156,
      fiftyTwoWeekRange: [Object],
      fiftyTwoWeekHighChange: -1.2050002,
      fiftyTwoWeekHighChangePercent: -0.32923502,
      fiftyTwoWeekChangePercent: -21.311474,
      dividendDate: 2018-06-06T00:00:00.000Z,
      earningsTimestamp: 1730754000,
      earningsTimestampStart: 1730754000,
      earningsTimestampEnd: 1730754000,
      earningsCallTimestampStart: 1730755800,
      earningsCallTimestampEnd: 1730755800,
      isEarningsDateEstimate: false,
      trailingAnnualDividendRate: 0,
      trailingAnnualDividendYield: 0,
      marketState: 'REGULAR',
      epsTrailingTwelveMonths: -0.12,
      epsForward: 0.12,
      epsCurrentYear: 0.14,
      priceEpsCurrentYear: 17.535713,
      sharesOutstanding: 276359008,
      bookValue: -0.866,
      fiftyDayAverage: 2.0686,
      fiftyDayAverageChange: 0.38639998,
      fiftyDayAverageChangePercent: 0.186793,
      twoHundredDayAverage: 2.235,
      twoHundredDayAverageChange: 0.22000003,
      twoHundredDayAverageChangePercent: 0.09843402,
      marketCap: 1130731264,
      forwardPE: 20.458334,
      priceToBook: -2.834873,
      sourceInterval: 15,
      exchangeDataDelayedBy: 0,
      exchangeTimezoneName: 'America/New_York',
      exchangeTimezoneShortName: 'EDT',
      exchange: 'NYQ',
      fiftyTwoWeekHigh: 3.66,
      fiftyTwoWeekLow: 1.52,
      averageAnalystRating: '3.1 - Hold',
      shortName: 'Altice USA, Inc.',
      gmtOffSetMilliseconds: -14400000,
      esgPopulated: false,
      tradeable: false,
      cryptoTradeable: false,
      displayName: 'Altice USA',
      symbol: 'ATUS'
    },
    {
      language: 'en-US',
      region: 'US',
      quoteType: 'EQUITY',
      typeDisp: 'Equity',
      quoteSourceName: 'Nasdaq Real Time Price',
      triggerable: false,
      customPriceAlertConfidence: 'LOW',
      lastCloseTevEbitLtm: -9.877831,
      lastClosePriceToNNWCPerShare: -0.03534114839221412,
      currency: 'USD',
      regularMarketChangePercent: 2.1472373,
      hasPrePostMarketData: true,
      firstTradeDateMilliseconds: 1306416600000,
      priceHint: 4,
      regularMarketChange: 0.034999967,
      regularMarketTime: 1729092597,
      regularMarketPrice: 1.665,
      regularMarketDayHigh: 1.7,
      regularMarketDayRange: [Object],
      regularMarketDayLow: 1.64,
      regularMarketVolume: 1427037,
      regularMarketPreviousClose: 1.63,
      bid: 1.67,
      ask: 1.68,
      bidSize: 40,
      askSize: 29,
      market: 'us_market',
      messageBoardId: 'finmb_831552',
      fullExchangeName: 'NYSE',
      longName: 'Spirit Airlines, Inc.',
      financialCurrency: 'USD',
      regularMarketOpen: 1.66,
      averageDailyVolume3Month: 5247112,
      averageDailyVolume10Day: 9859360,
      fiftyTwoWeekLowChange: 0.265,
      fiftyTwoWeekLowChangePercent: 0.18928571,
      fiftyTwoWeekRange: [Object],
      fiftyTwoWeekHighChange: -15.825,
      fiftyTwoWeekHighChangePercent: -0.90480274,
      fiftyTwoWeekChangePercent: -90.1451,
      dividendDate: 2024-02-29T00:00:00.000Z,
      earningsTimestamp: 1722505804,
      earningsTimestampStart: 1729773000,
      earningsTimestampEnd: 1730118600,
      earningsCallTimestampStart: 1722520800,
      earningsCallTimestampEnd: 1722520800,
      isEarningsDateEstimate: true,
      trailingAnnualDividendRate: 0,
      trailingAnnualDividendYield: 0,
      marketState: 'REGULAR',
      epsTrailingTwelveMonths: -6.2,
      epsForward: -4.55,
      epsCurrentYear: -6.52,
      priceEpsCurrentYear: -0.25536808,
      sharesOutstanding: 109518000,
      bookValue: 7.393,
      fiftyDayAverage: 2.423,
      fiftyDayAverageChange: -0.75800014,
      fiftyDayAverageChangePercent: -0.31283537,
      twoHundredDayAverage: 4.53995,
      twoHundredDayAverageChange: -2.87495,
      twoHundredDayAverageChangePercent: -0.6332559,
      marketCap: 182347472,
      forwardPE: -0.36593404,
      priceToBook: 0.22521304,
      sourceInterval: 15,
      exchangeDataDelayedBy: 0,
      exchangeTimezoneName: 'America/New_York',
      exchangeTimezoneShortName: 'EDT',
      exchange: 'NYQ',
      fiftyTwoWeekHigh: 17.49,
      fiftyTwoWeekLow: 1.4,
      averageAnalystRating: '3.8 - Underperform',
      shortName: 'Spirit Airlines, Inc.',
      gmtOffSetMilliseconds: -14400000,
      esgPopulated: false,
      tradeable: false,
      cryptoTradeable: false,
      displayName: 'Spirit Airlines',
      symbol: 'SAVE'
    },
    {
      language: 'en-US',
      region: 'US',
      quoteType: 'EQUITY',
      typeDisp: 'Equity',
      quoteSourceName: 'Nasdaq Real Time Price',
      triggerable: false,
      customPriceAlertConfidence: 'LOW',
      lastCloseTevEbitLtm: 32.634725,
      lastClosePriceToNNWCPerShare: -0.03367235187113416,
      currency: 'USD',
      regularMarketChangePercent: 0.7766983,
      hasPrePostMarketData: true,
      firstTradeDateMilliseconds: 1585920600000,
      priceHint: 2,
      regularMarketChange: 0.07999992,
      regularMarketTime: 1729092603,
      regularMarketPrice: 10.38,
      regularMarketDayHigh: 10.56,
      regularMarketDayRange: [Object],
      regularMarketDayLow: 10.275,
      regularMarketVolume: 1282,
      regularMarketPreviousClose: 10.3,
      bid: 10.11,
      ask: 10.56,
      bidSize: 11,
      askSize: 8,
      market: 'us_market',
      messageBoardId: 'finmb_968903',
      fullExchangeName: 'NYSE',
      longName: 'MultiPlan Corporation',
      financialCurrency: 'USD',
      regularMarketOpen: 10.42,
      averageDailyVolume3Month: 69602,
      averageDailyVolume10Day: 62930,
      fiftyTwoWeekLowChange: 4.03,
      fiftyTwoWeekLowChangePercent: 0.6346457,
      fiftyTwoWeekRange: [Object],
      fiftyTwoWeekHighChange: -58.819996,
      fiftyTwoWeekHighChangePercent: -0.84999996,
      fiftyTwoWeekChangePercent: -84.85294,
      earningsTimestamp: 1722506700,
      earningsTimestampStart: 1730813400,
      earningsTimestampEnd: 1731331800,
      earningsCallTimestampStart: 1722519000,
      earningsCallTimestampEnd: 1722519000,
      isEarningsDateEstimate: true,
      trailingAnnualDividendRate: 0,
      trailingAnnualDividendYield: 0,
      marketState: 'REGULAR',
      epsTrailingTwelveMonths: -72.4,
      epsForward: -8.27,
      epsCurrentYear: -106.8,
      priceEpsCurrentYear: -0.097191006,
      sharesOutstanding: 16143100,
      bookValue: 37.376,
      fiftyDayAverage: 9.5376,
      fiftyDayAverageChange: 0.84240055,
      fiftyDayAverageChangePercent: 0.08832417,
      twoHundredDayAverage: 24.9162,
      twoHundredDayAverageChange: -14.536201,
      twoHundredDayAverageChangePercent: -0.5834036,
      marketCap: 167565376,
      forwardPE: -1.255139,
      priceToBook: 0.27771834,
      sourceInterval: 15,
      exchangeDataDelayedBy: 0,
      exchangeTimezoneName: 'America/New_York',
      exchangeTimezoneShortName: 'EDT',
      exchange: 'NYQ',
      fiftyTwoWeekHigh: 69.2,
      fiftyTwoWeekLow: 6.35,
      averageAnalystRating: '2.7 - Hold',
      shortName: 'MultiPlan Corporation',
      gmtOffSetMilliseconds: -14400000,
      prevName: 'Churchill Capital Corp III',
      nameChangeDate: 2024-10-15T00:00:00.000Z,
      esgPopulated: false,
      tradeable: false,
      cryptoTradeable: false,
      displayName: 'MultiPlan',
      symbol: 'MPLN'
    },
    {
      language: 'en-US',
      region: 'US',
      quoteType: 'EQUITY',
      typeDisp: 'Equity',
      quoteSourceName: 'Nasdaq Real Time Price',
      triggerable: false,
      customPriceAlertConfidence: 'LOW',
      lastCloseTevEbitLtm: 10.693181,
      lastClosePriceToNNWCPerShare: -0.7499427046962506,
      currency: 'USD',
      regularMarketChangePercent: 1.0532843,
      hasPrePostMarketData: true,
      firstTradeDateMilliseconds: 1627651800000,
      priceHint: 2,
      regularMarketChange: 0.17000008,
      regularMarketTime: 1729092596,
      regularMarketPrice: 16.31,
      regularMarketDayHigh: 16.346,
      regularMarketDayRange: [Object],
      regularMarketDayLow: 16.16,
      regularMarketVolume: 107901,
      regularMarketPreviousClose: 16.14,
      bid: 16.32,
      ask: 16.33,
      bidSize: 8,
      askSize: 12,
      market: 'us_market',
      messageBoardId: 'finmb_30301231',
      fullExchangeName: 'NYSE',
      longName: 'Dole plc',
      financialCurrency: 'USD',
      regularMarketOpen: 16.25,
      averageDailyVolume3Month: 757290,
      averageDailyVolume10Day: 491550,
      fiftyTwoWeekLowChange: 5.7599993,
      fiftyTwoWeekLowChangePercent: 0.5459715,
      fiftyTwoWeekRange: [Object],
      fiftyTwoWeekHighChange: -0.8100014,
      fiftyTwoWeekHighChangePercent: -0.04731316,
      fiftyTwoWeekChangePercent: 47.531998,
      dividendDate: 2024-10-03T00:00:00.000Z,
      earningsTimestamp: 1723629601,
      earningsTimestampStart: 1731591000,
      earningsTimestampEnd: 1731936600,
      earningsCallTimestampStart: 1723636800,
      earningsCallTimestampEnd: 1723636800,
      isEarningsDateEstimate: true,
      trailingAnnualDividendRate: 0.32,
      trailingPE: 8.279187,
      dividendRate: 0.32,
      trailingAnnualDividendYield: 0.019826518,
      dividendYield: 1.98,
      marketState: 'REGULAR',
      epsTrailingTwelveMonths: 1.97,
      epsForward: 1.42,
      epsCurrentYear: 1.24,
      priceEpsCurrentYear: 13.153225,
      sharesOutstanding: 94952000,
      bookValue: 14.437,
      fiftyDayAverage: 15.9034,
      fiftyDayAverageChange: 0.40659904,
      fiftyDayAverageChangePercent: 0.0255668,
      twoHundredDayAverage: 13.0893,
      twoHundredDayAverageChange: 3.2206993,
      twoHundredDayAverageChangePercent: 0.24605589,
      marketCap: 1548667008,
      forwardPE: 11.485915,
      priceToBook: 1.1297361,
      sourceInterval: 15,
      exchangeDataDelayedBy: 0,
      exchangeTimezoneName: 'America/New_York',
      exchangeTimezoneShortName: 'EDT',
      exchange: 'NYQ',
      fiftyTwoWeekHigh: 17.12,
      fiftyTwoWeekLow: 10.55,
      averageAnalystRating: '2.5 - Buy',
      shortName: 'Dole plc',
      gmtOffSetMilliseconds: -14400000,
      ipoExpectedDate: 2021-07-30T00:00:00.000Z,
      prevName: 'Total Produce plc',
      nameChangeDate: 2024-10-15T00:00:00.000Z,
      esgPopulated: false,
      tradeable: false,
      cryptoTradeable: false,
      displayName: 'Dole',
      symbol: 'DOLE'
    },
    {
      language: 'en-US',
      region: 'US',
      quoteType: 'EQUITY',
      typeDisp: 'Equity',
      quoteSourceName: 'Nasdaq Real Time Price',
      triggerable: true,
      customPriceAlertConfidence: 'HIGH',
      lastCloseTevEbitLtm: 1.629637,
      lastClosePriceToNNWCPerShare: 0.6003101720245837,
      currency: 'USD',
      regularMarketChangePercent: 4.5070443,
      hasPrePostMarketData: true,
      firstTradeDateMilliseconds: 1604064600000,
      priceHint: 4,
      regularMarketChange: 0.16000009,
      regularMarketTime: 1729092436,
      regularMarketPrice: 3.71,
      regularMarketDayHigh: 3.71,
      regularMarketDayRange: [Object],
      regularMarketDayLow: 3.55,
      regularMarketVolume: 102926,
      regularMarketPreviousClose: 3.55,
      bid: 3.71,
      ask: 3.78,
      bidSize: 1,
      askSize: 1,
      market: 'us_market',
      messageBoardId: 'finmb_252824153',
      fullExchangeName: 'NasdaqGS',
      longName: 'Atea Pharmaceuticals, Inc.',
      financialCurrency: 'USD',
      regularMarketOpen: 3.6,
      averageDailyVolume3Month: 209117,
      averageDailyVolume10Day: 131210,
      fiftyTwoWeekLowChange: 0.94499993,
      fiftyTwoWeekLowChangePercent: 0.3417721,
      fiftyTwoWeekRange: [Object],
      fiftyTwoWeekHighChange: -0.88999987,
      fiftyTwoWeekHighChangePercent: -0.19347824,
      fiftyTwoWeekChangePercent: 21.160412,
      earningsTimestamp: 1723061100,
      earningsTimestampStart: 1730926800,
      earningsTimestampEnd: 1731358800,
      earningsCallTimestampStart: 1723062600,
      earningsCallTimestampEnd: 1723062600,
      isEarningsDateEstimate: true,
      trailingAnnualDividendRate: 0,
      trailingAnnualDividendYield: 0,
      marketState: 'REGULAR',
      epsTrailingTwelveMonths: -2.1,
      epsForward: -1.79,
      epsCurrentYear: -2.21,
      priceEpsCurrentYear: -1.678733,
      sharesOutstanding: 84422000,
      bookValue: 5.644,
      fiftyDayAverage: 3.6102,
      fiftyDayAverageChange: 0.09980011,
      fiftyDayAverageChangePercent: 0.027643928,
      twoHundredDayAverage: 3.7318,
      twoHundredDayAverageChange: -0.021800041,
      twoHundredDayAverageChangePercent: -0.0058416957,
      marketCap: 314970112,
      forwardPE: -2.0726259,
      priceToBook: 0.6573352,
      sourceInterval: 15,
      exchangeDataDelayedBy: 0,
      exchangeTimezoneName: 'America/New_York',
      exchangeTimezoneShortName: 'EDT',
      exchange: 'NMS',
      fiftyTwoWeekHigh: 4.6,
      fiftyTwoWeekLow: 2.765,
      averageAnalystRating: '2.7 - Hold',
      shortName: 'Atea Pharmaceuticals, Inc.',
      gmtOffSetMilliseconds: -14400000,
      ipoExpectedDate: 2020-10-30T00:00:00.000Z,
      esgPopulated: false,
      tradeable: false,
      cryptoTradeable: false,
      displayName: 'Atea Pharmaceuticals',
      symbol: 'AVIR'
    }
  ],
  useRecords: false,
  predefinedScr: true,
  versionId: 0,
  creationDate: +048672-12-06T20:28:02.000Z,
  lastUpdated: +048672-12-06T20:28:02.000Z,
  isPremium: false,
  iconUrl: 'https://s.yimg.com/cv/apiv2/fin/img/assets/predefined_screeners/analytics.png'
}

Hope that helps!

gadicc avatar Oct 16 '24 15:10 gadicc

@gadicc this my function i try to seem like you but i have bad request idk what wrong

 async stockTrending(): Promise<any> {
        try {
            const queryOptions = { count: 5, region: "US", lang: "en-US" };
            const result = await yahooFinance.trendingSymbols("US", queryOptions)
            return result;
        } catch (error) {
            this.logger.error('Failed to fetch stock trending', error.message);
            throw new Error('Failed to fetch stock trending');
        }
    }

pingplass123 avatar Oct 16 '24 15:10 pingplass123

Sometimes it can be region specific. Where are you based? Try from another country with a VPN if possible, and I'll look into it further as soon as I can (and once I know where you are making your requests from). Thanks for your patience, super busy period for me atm 😞

On Wed, 16 Oct 2024, 17:07 Areefeen Hayeeyapa, @.***> wrote:

@gadicc https://github.com/gadicc this my function i try to seem like you but i have bad request idk what wrong

async stockTrending(): Promise { try { const queryOptions = { count: 5, region: "US", lang: "en-US" }; const result = await yahooFinance.trendingSymbols("US", queryOptions) return result; } catch (error) { this.logger.error('Failed to fetch stock trending', error.message); throw new Error('Failed to fetch stock trending'); } }

— Reply to this email directly, view it on GitHub https://github.com/gadicc/node-yahoo-finance2/issues/820#issuecomment-2417235159, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAC5IGVF64TI5WUZT3UPCELZ32FMZAVCNFSM6AAAAABP6N4PTSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMJXGIZTKMJVHE . You are receiving this because you were mentioned.Message ID: @.***>

gadicc avatar Oct 16 '24 16:10 gadicc

i request from thailand so i will try to vpn and call it again

pingplass123 avatar Oct 16 '24 16:10 pingplass123