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

International indices/stocks not working with same from/to; timezone issue #71

Open
anth87 opened this issue May 17, 2020 · 6 comments
Open

Comments

@anth87
Copy link

anth87 commented May 17, 2020

Hi, does anyone know if it is possible to access non-US indices/stocks using this API?

For example, neither "^AXJO" or "CBA.AX" seem to be working for me, yet these are quotes available on Yahoo Finance.

@gadicc
Copy link
Collaborator

gadicc commented May 17, 2020

Hey @anth87

Should be fine to access such stocks and indices. I tried now and had no problem, see results below.

The vast majority of problems people report here are due to caching issues on Yahoo's network or their system that resolve themselves with time. Try flushing your DNS cache, changing DNS servers, and if this is on a particular server try on your dev PC and vice versa, etc. And please do report back on your results either way 🙏

^AXJO
{
  summaryDetail: {
    maxAge: 1,
    priceHint: 2,
    previousClose: 5328.7,
    open: 5328.7,
    dayLow: 5328.7,
    dayHigh: 5412.4,
    regularMarketPreviousClose: 5328.7,
    regularMarketOpen: 5328.7,
    regularMarketDayLow: 5328.7,
    regularMarketDayHigh: 5412.4,
    volume: 0,
    regularMarketVolume: 0,
    averageVolume: 1121795,
    averageVolume10days: 824085,
    averageDailyVolume10Day: 824085,
    bid: 0,
    ask: 0,
    bidSize: 0,
    askSize: 0,
    fiftyTwoWeekLow: 4402.5,
    fiftyTwoWeekHigh: 7197.2,
    fiftyDayAverage: 5323.2817,
    twoHundredDayAverage: 6292.482,
    currency: 'AUD',
    fromCurrency: null,
    toCurrency: null,
    lastMarket: null,
    algorithm: null,
    tradeable: false
  },
  price: {
    maxAge: 1,
    regularMarketChangePercent: 0.014281083,
    regularMarketChange: 76.09961,
    regularMarketTime: 2020-05-15T07:03:45.000Z,
    priceHint: 2,
    regularMarketPrice: 5404.8,
    regularMarketDayHigh: 5412.4,
    regularMarketDayLow: 5328.7,
    regularMarketVolume: 0,
    averageDailyVolume10Day: 824085,
    averageDailyVolume3Month: 1121795,
    regularMarketPreviousClose: 5328.7,
    regularMarketSource: 'DELAYED',
    regularMarketOpen: 5328.7,
    exchange: 'ASX',
    exchangeName: 'ASX',
    exchangeDataDelayedBy: 0,
    marketState: 'CLOSED',
    quoteType: 'INDEX',
    symbol: '^AXJO',
    underlyingSymbol: null,
    shortName: 'S&P/ASX 200',
    longName: null,
    currency: 'AUD',
    currencySymbol: 'A$',
    fromCurrency: null,
    toCurrency: null,
    lastMarket: null
  }
}
CBA.AX
{
  summaryDetail: {
    maxAge: 1,
    priceHint: 2,
    previousClose: 58.9,
    open: 59.5,
    dayLow: 58.91,
    dayHigh: 59.76,
    regularMarketPreviousClose: 58.9,
    regularMarketOpen: 59.5,
    regularMarketDayLow: 58.91,
    regularMarketDayHigh: 59.76,
    dividendRate: 4,
    dividendYield: 0.0671,
    exDividendDate: 2020-02-19T00:00:00.000Z,
    payoutRatio: 0.9472,
    fiveYearAvgDividendYield: 5.56,
    beta: 0.72426,
    trailingPE: 10.80885,
    forwardPE: 10.758122,
    volume: 2537091,
    regularMarketVolume: 2537091,
    averageVolume: 5683757,
    averageVolume10days: 3539468,
    averageDailyVolume10Day: 3539468,
    bid: 65.67,
    ask: 59.6,
    bidSize: 0,
    askSize: 0,
    marketCap: 105506299904,
    fiftyTwoWeekLow: 53.44,
    fiftyTwoWeekHigh: 91.05,
    priceToSalesTrailing12Months: 4.5745015,
    fiftyDayAverage: 60.630287,
    twoHundredDayAverage: 74.78105,
    trailingAnnualDividendRate: 4.31,
    trailingAnnualDividendYield: 0.07317487,
    currency: 'AUD',
    fromCurrency: null,
    toCurrency: null,
    lastMarket: null,
    algorithm: null,
    tradeable: false
  },
  price: {
    maxAge: 1,
    regularMarketChangePercent: 0.0118844975,
    regularMarketChange: 0.69999695,
    regularMarketTime: 2020-05-15T06:10:33.000Z,
    priceHint: 2,
    regularMarketPrice: 59.6,
    regularMarketDayHigh: 59.76,
    regularMarketDayLow: 58.91,
    regularMarketVolume: 2537091,
    averageDailyVolume10Day: 3539468,
    averageDailyVolume3Month: 5683757,
    regularMarketPreviousClose: 58.9,
    regularMarketSource: 'DELAYED',
    regularMarketOpen: 59.5,
    exchange: 'ASX',
    exchangeName: 'ASX',
    exchangeDataDelayedBy: 0,
    marketState: 'CLOSED',
    quoteType: 'EQUITY',
    symbol: 'CBA.AX',
    underlyingSymbol: null,
    shortName: 'CWLTH BANK FPO',
    longName: 'Commonwealth Bank of Australia',
    currency: 'AUD',
    currencySymbol: 'A$',
    fromCurrency: null,
    toCurrency: null,
    lastMarket: null,
    marketCap: 105506299904
  }
}

@anth87
Copy link
Author

anth87 commented May 17, 2020

Thanks @gadicc - I can confirm that these also work for me using the .quote() endpoint, however am having no luck with the .historical() endpoint. Can you also confirm this - and is this to be expected?

@gadicc
Copy link
Collaborator

gadicc commented May 17, 2020

Hey @anth87, as of right now this is working for me:

yahooFinance.historical({
  symbol: '^CBA.AX',
  from: '2020-05-14'
}, function(err, history) {
  console.log(err);
  console.log(history);
});;
results
null
[
  {
    date: 2020-05-15T04:00:00.000Z,
    open: 59.5,
    high: 59.759998,
    low: 58.91,
    close: 59.599998,
    adjClose: 59.599998,
    volume: 2671452,
    symbol: 'CBA.AX'
  },
  {
    date: 2020-05-14T04:00:00.000Z,
    open: 59.400002,
    high: 59.59,
    low: 58.82,
    close: 58.900002,
    adjClose: 58.900002,
    volume: 4440061,
    symbol: 'CBA.AX'
  }
]
yahooFinance.historical({
  symbol: '^AXJO',
  from: '2020-05-14'
}, function(err, history) {
  console.log(err);
  console.log(history);
});;
results
null
[
  {
    date: 2020-05-15T04:00:00.000Z,
    open: 5328.700195,
    high: 5412.399902,
    low: 5328.700195,
    close: 5404.799805,
    adjClose: 5404.799805,
    volume: 750200,
    symbol: '^AXJO'
  },
  {
    date: 2020-05-14T04:00:00.000Z,
    open: 5421.700195,
    high: 5421.700195,
    low: 5328.700195,
    close: 5328.700195,
    adjClose: 5328.700195,
    volume: 829800,
    symbol: '^AXJO'
  }
]

Can you let us know how you are calling historical() and what the results / errors are?

@anth87
Copy link
Author

anth87 commented May 17, 2020

Thanks @gadicc - this is also working for me. I was calling historical() with the same from and to date - and I believe this was causing no output to return, just an empty array.

Interestingly, if I use the same from and to date for ^GSPC (the S&P500), I still get a response.

In any case, I have what I need now so thank you very much for your help!

@gadicc
Copy link
Collaborator

gadicc commented May 18, 2020

Hey @anth87, thanks for reporting back. That's interesting to know.

The library parses the from and to from a string to a moment() object and ultimately converts to a unix timestamp before sending to Yahoo. So I guess between the different datetime of when the data is available for in foreign markets, and your local timezone, this is what results in this behaviour.

from and to also accept a Date() object. So you could give it an appropriate datetime that will match the range. Note in the output above the datetime for the historical record was e.g. 2020-05-14T04:00:00.000Z (i.e. 4am UTC). Presumably Yahoo to > from and <= to.

You can leave this issue open, I'll give it some thought if perhaps we should assume a certain timezone when doing the conversion.

@gadicc
Copy link
Collaborator

gadicc commented May 18, 2020

If you can rename the title to: "International indices/stocks not working with same from/to; timezone issue" that would be great :)

@anth87 anth87 changed the title International indices/stocks not working International indices/stocks not working with same from/to; timezone issue May 18, 2020
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