bybit-exchange / pybit

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

Finding the earliest kline candle #186

Closed einarjohnson closed 5 months ago

einarjohnson commented 5 months ago

Hello Pybit folks, I am working on a project where I store all the Kline data from Bybit in a persistance layer. We use the https://bybit-exchange.github.io/docs/v5/market/kline API to fetch this data. If there a way for me to figure out what the earliest candle is for a particular ticker so I can start fetching from that date up until the datetime.now() ? Since the list returned is sorted in reverse by startTime i'm finding it a bit tricky to build a pipeline that fetches the whole history.

PS: I am fetching the data asynchronously so knowing the earliest candle date upfront would be ideal so I can know which period chunks I should query for.

Kamsby commented 5 months ago

There is no endpoint provides the earliest candle. I can suggest you to try with interval as 'M' (month), then pick the last record for your earliest candle reference.

https://api.bybit.com/v5/market/kline?cateory=linear&symbol=BTCUSDT&interval=M&limit=1000

einarjohnson commented 5 months ago

that's a good idea @Kamsby , thank you kindly for the input.