BitMEX / api-connectors

Libraries for connecting to the BitMEX API.
https://www.bitmex.com/app/restAPI
910 stars 795 forks source link

Websocket's tradeBin data latency #242

Open muratyz opened 6 years ago

muratyz commented 6 years ago

I need OHLC data with low latency. I've tried BitMEX-Delta-Server with 'tradeBin1m' subscription but there is latency of ~15 seconds compared to real-time data on web browser. Namely, i get latest 1m OHLC data 15 seconds after the candle closes. Actually, it is the same latency that REST API have. What is the reason of this latency in websocket feed and how i could get OHLC data with lower latency?

vanishjournalist commented 6 years ago

Same here, 1m candles arrive at about :15.

Most straight-forward way would be listen to the 'trade' endpoint and construct the candle data yourself comparatively to your system time (that you should synchronize for example with NTP).

Ie, on the span of one minute, candle.low=Minimum of all the trades that occured during the minute candle.high=Maximum of all the trades that occured during the minute candle.open=First trade that occured during the minute candle.close=Last trade that occured during the minute

After construction of the candle, do whatever you want, empty the list of trades and repeat.

R2FREE commented 5 years ago

Same here, 1m candles arrive at about :15.

Most straight-forward way would be listen to the 'trade' endpoint and construct the candle data yourself comparatively to your system time (that you should synchronize for example with NTP).

Ie, on the span of one minute, candle.low=Minimum of all the trades that occured during the minute candle.high=Maximum of all the trades that occured during the minute candle.open=First trade that occured during the minute candle.close=Last trade that occured during the minute

After construction of the candle, do whatever you want, empty the list of trades and repeat.

But there is one more problem Dude. Cause the Internet latency and the time compute needed to run, the candle.close price and candle.open price will always be higher or lower 0.5 XBT than the real one.

And I tried timestamp minus the latency/2, wanna to get the real timestamp the BitMEX send trade data, but the result is not really ideal.

Krach64 commented 4 years ago

Hi, The latency is because by default in the resquest rest api link, partial=false. If you change this argument to true, you will have the ohlc of the current timestamp. Here an example :

https://www.bitmex.com/api/v1/trade/bucketed?binSize=1m&partial=true&symbol=XBTUSD

You can see the ohlc of current timestamp. Make this issue close

erocitna commented 4 years ago

Hi, The latency is because by default in the resquest rest api link, partial=false. If you change this argument to true, you will have the ohlc of the current timestamp. Here an example :

https://www.bitmex.com/api/v1/trade/bucketed?binSize=1m&partial=true&symbol=XBTUSD

You can see the ohlc of current timestamp. Make this issue close

How about websocket api is there a solution for that? Thanks

Krach64 commented 4 years ago

Hi, The latency is because by default in the resquest rest api link, partial=false. If you change this argument to true, you will have the ohlc of the current timestamp. Here an example : https://www.bitmex.com/api/v1/trade/bucketed?binSize=1m&partial=true&symbol=XBTUSD You can see the ohlc of current timestamp. Make this issue close

How about websocket api is there a solution for that? Thanks

in websocket api, i just take live trades and make my ohlc with that. Unlike bitfinex, bitmex don't give the currend ohlc but the past. Just use live trade to make them.