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
402 stars 107 forks source link

Closed candles delay #155

Closed iassinskii closed 4 years ago

iassinskii commented 4 years ago

Hello,

I am reading candles from "https://api-fxpractice.oanda.com/v3/instruments/GBP_USD/candles?count=10&price=M&granularity=M1" with the rate 1 per second. I am interested in the last closed/complete candle.

I have noticed that the last closed/complete candle is received with the delay anything between 1 sec up to the ~45 secs (what I have seen). Most of the time the delay is just a few seconds, but sometimes it is much longer. For example if the current time is 1:10:00, the closed/complete candle can arrive at 1:10:25.

Is this the expected behaviour? If so, is there any way to make it more consistent with let's say just 1-2 secs delay?

Thank you,

Viktor

hootnot commented 4 years ago

Hi,

"Expected behaviour": that depends on how things are defined.

At certain times of the day ticks are very low frequent and gaps of multiple minutes might occur between consecutive ticks.

The way you describe it, it looks like the first tick in a new timeframe (M1 in your case), closes the prior candle. So, until that tick occurs, that prior candle keeps state 'completed=False'.

Another option would be to close the candle every time exactly 1 minute has passed. The way you describe it, OANDA seems to have choosen the first scenario.

In case you want the latter one I think you should process a tickstream and generate the candles every time exactly N-seconds have passed.

Pls. take a look at https://github.com/hootnot/oanda-trading-environment.

You also might try to modify your current solution by including some time calculation and modify the state to True when you know the time for the prior candle got passed. This is probably the most easy since it is only a small extension to the code you already have.

Feite

iassinskii commented 4 years ago

Thank you for the quick reply. I understand that I can build my own candles from the tick but this is expected from the platform. If it takes platform so long to close the candle, I am not sure that ticks are received timely. The problem is that these delays are very costly - missing trades or late closing.

hootnot commented 4 years ago

To get an impression on the tick frequency you can easily setup some test and log ticks for several days. If the market is that thin that time between ticks can be > a minute, you probably have bad spreads also. "Do you want to trade under those conditions ?" is a question that pops up.

I'm afraid I can't help you here. For detailed answers you should ask OANDA.

iassinskii commented 4 years ago

Ok, thank you.

Cheers,

Viktor

On Wed, Jan 1, 2020 at 6:01 AM Feite Brekeveld notifications@github.com wrote:

To get an impression on the tick frequency you can easily setup some test and log ticks for several days. If the market is that thin that time between ticks can be > a minute, you probably have bad spreads also. "Do you want to trade under those conditions ?" is a question that pops up.

I'm afraid I can't help you here. For detailed answers you should ask OANDA.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hootnot/oanda-api-v20/issues/155?email_source=notifications&email_token=AC3FJZE57WHLDF4KMXGE4SDQ3RZZTA5CNFSM4J7MYT2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEH5CZ3Q#issuecomment-570043630, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC3FJZEY2D44TOMOWNN5F63Q3RZZTANCNFSM4J7MYT2A .

hootnot commented 4 years ago

... market just opened. Query on S5 records NZD/USD since opening gives:

20200101T22:00:00,True,0.67203,0.67403,0.67203,0.67403,0.67203,0.67403,0.67203,0.67403,1
20200101T22:01:40,True,0.67168,0.67302,0.67168,0.67302,0.67168,0.67302,0.67168,0.67302,1
20200101T22:02:00,True,0.67167,0.67295,0.67169,0.67301,0.67167,0.67295,0.67169,0.67301,2
20200101T22:04:00,True,0.67172,0.67288,0.67172,0.67288,0.67167,0.67283,0.67167,0.67283,2
20200101T22:04:40,True,0.67165,0.67272,0.67165,0.67272,0.67150,0.67262,0.67150,0.67262,3
20200101T22:04:50,True,0.67166,0.67265,0.67171,0.67270,0.67166,0.67265,0.67171,0.67270,2
20200101T22:06:35,True,0.67181,0.67268,0.67181,0.67268,0.67181,0.67268,0.67181,0.67268,1

Plenty S5 gaps and even M1 gaps, spread still 8 pips.

iassinskii commented 4 years ago

Not surprising to me. I really don't want to go into monitoring ticks and building my candles because I don't think it can be done reliably on the application side because of the performance reasons. These kind of things should be done on the Oanda server.

I don't have very challenging performance requirements but if I could get M5 candle within 1 sec of closing, that would be good enough for me. Because right now I either miss the trade, or have to offset the close price to anticipate market move by 1-2 pips. And thats a lot of pips in the year that I am loosing.

On Wed, Jan 1, 2020 at 5:13 PM Feite Brekeveld notifications@github.com wrote:

... market just opened. Query on S5 records NZD/USD since opening gives:

20200101T22:00:00,True,0.67203,0.67403,0.67203,0.67403,0.67203,0.67403,0.67203,0.67403,1 20200101T22:01:40,True,0.67168,0.67302,0.67168,0.67302,0.67168,0.67302,0.67168,0.67302,1 20200101T22:02:00,True,0.67167,0.67295,0.67169,0.67301,0.67167,0.67295,0.67169,0.67301,2 20200101T22:04:00,False,0.67172,0.67288,0.67172,0.67288,0.67167,0.67283,0.67167,0.67283,2 20200101T22:04:40,True,0.67165,0.67272,0.67165,0.67272,0.67150,0.67262,0.67150,0.67262,3 20200101T22:04:50,True,0.67166,0.67265,0.67171,0.67270,0.67166,0.67265,0.67171,0.67270,2 20200101T22:06:35,True,0.67181,0.67268,0.67181,0.67268,0.67181,0.67268,0.67181,0.67268,1

Plenty S5 gaps and even M1 gaps, spread still 8 pips.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hootnot/oanda-api-v20/issues/155?email_source=notifications&email_token=AC3FJZHHNHBFVDDKOEVTDHTQ3UIQRA5CNFSM4J7MYT2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEH5NSPY#issuecomment-570087743, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC3FJZHULLP5XSUD24ZTB3DQ3UIQRANCNFSM4J7MYT2A .