bybit-exchange / pybit

Official Python3 API connector for Bybit's HTTP and WebSockets APIs.
Other
418 stars 135 forks source link

get_kline returning today's candle that has not closed #175

Closed einarjohnson closed 12 months ago

einarjohnson commented 1 year ago

Hello, I am using your pybit library to interact with the Bybit API. I have noticed that when I fetch KLine data using get_kline for the 1D interval I get "today's" candle which has not yet closed. Is this expected behaviour? Example from today (21st November, 2023) image

When I fetch information about the 4h interval, for instance, this behaviour doesn't seem to happen and I only receive past candles which have already closed.

einarjohnson commented 1 year ago

I'm actually realising the same behaviour appears when I fetch the 4h kline's. It would be great to get some kinda flag from the API indicating the candle has not yet closed, much like we do get with the websocket data.

dextertd commented 12 months ago

You can work it out by taking the interval and startTime to know when the candle will close.

I called https://api.bybit.com/v5/market/kline?category=linear&symbol=BTCUSDT&interval=240 and the first item in the list was a candle which had opened 2 hours ago.

Do you have a response which exhibits the problem?

You can also refer to confirm from the websocket for a single field indicating if the candle closed or not. https://bybit-exchange.github.io/docs/v5/websocket/public/kline

einarjohnson commented 12 months ago

hi @dextertd , yes, I had noticed the confirm flag in the websocket response data. would be nice to get a similar flag in the get_kline response. but like you say, I can of course deduct this information from the current date.