hootnot / oanda-api-v20

OANDA REST-V20 API wrapper. Easy access to OANDA's REST v20 API with oandapyV20 package. Checkout the Jupyter notebooks!
MIT License
398 stars 107 forks source link

daily candles seem to be shifted one day #192

Closed andreaskoeszegi closed 2 years ago

andreaskoeszegi commented 2 years ago

Hello!

I´m not sure what I´m doing wrong. When I try to request daily candle data and compare it with the webchart, the API seems to shift OHLC data by one day

Here an example:

params={
    "count": 2,
    "to":dt.datetime(2022,5,13).timestamp(),
    "granularity": "D"}

r = instruments.InstrumentsCandles(instrument="EUR_USD",params=params)

response=client.request(r)

response

Output´d be:

{'candles': [{'complete': True,
   'mid': {'c': '1.03810', 'h': '1.05294', 'l': '1.03538', 'o': '1.05166'},
   'time': '2022-05-11T21:00:00.000000000Z',
   'volume': 191082},
  {'complete': True,
   'mid': {'c': '1.04072', 'h': '1.04198', 'l': '1.03492', 'o': '1.03781'},
   'time': '2022-05-12T21:00:00.000000000Z',
   'volume': 157178}],
 'granularity': 'D',
 'instrument': 'EUR_USD'}
EURUSD_D_May_12

As you can see, the API-data from may 11th seems to fit to chart-data of may 12th

Other granularities work fine. I´m working on a practice-account. It´s probably an Issue from the Rest-API from Oanda. I already emailed them.

Or did I interpreted the output the wrong way?

Thank you in advance for your replies!

best regards Andrew

hootnot commented 2 years ago

Hi Andrew, Although you don't mention an issue with the oandapyV20 library, I will try to explain:

The market is open from Sunday 21:00 UTC to Friday 21:00 UTC. daily candles therefore from:

Sunday 21:00 -> monday 21:00 monday 21:00 -> Tue 21:00 Tue 21:00 -> wed 21:00 wed 21:00 -> thur 21:00 thursday 21:00 -> Friday 21:00

So, the datetime of the first candle is sunday. This is what it is. The API data is OK