ccxt: Bug in fetchOpenInterestHistory, fetchFundingRateHistory for ByBit
Operating System
Windows 11
Programming Languages
python
CCXT Version
Latest
Description
fetchOpenInterestHistory returns 200 data in one api call. So, I tried to loop to create multiple api call to access historic OI data but it won’t display any more than 200 data starting from latest data to previous 200 data depending on the timeframe.
I thought exchange might not provide historic data/ may have been deleted. But it’s not the case as if I put 1d in the timeframe then it returns OI data for past 200 days but if I put 5m as timeframe then it only returns data for the last (5*200 minutes) although clearly those data exists.
Same issue with fetchFundingRateHistory as well.
Code
start_date_str = '2023/01/01'
timeframe = '4h'
while True:
data = exchange.fetchOpenInterestHistory(symbol, timeframe=timeframe, since=start_time, limit=200, params={})
open_interest.extend([d['openInterestValue'] for d in data])
timestamps.extend([d['timestamp'] for d in data])
start_timestamp = data[-1]['timestamp'] + 14400000
if start_timestamp > now:
break
df = pd.DataFrame({'Open Interest': open_interest, 'Timestamp': timestamps})
df['Timestamp'] = pd.to_datetime(df['Timestamp'], unit='ms')
Output
Open Interest
Timestamp
2023-04-06 12:00:00 53219.568
2023-04-06 16:00:00 53926.314
2023-04-06 20:00:00 54017.478
2023-04-07 00:00:00 53409.204
2023-04-07 04:00:00 54020.004
... ...
2023-05-09 00:00:00 53571.610
2023-05-09 04:00:00 54207.733
2023-05-09 08:00:00 54772.759
2023-05-09 12:00:00 54877.994
2023-05-09 16:00:00 55444.414
[200 rows x 1 columns]
It starts from April although start date is clearly from January and I can’t seem to find a way to start from January even after trying to do multiple api calls
If I put 1d as timeframe (to show that the older historic data exists)
Output:
Open Interest
Timestamp
2022-10-22 68092.454
2022-10-23 67547.822
2022-10-24 67271.853
2022-10-25 64434.425
2022-10-26 71259.918
... ...
2023-05-05 53308.578
2023-05-06 53550.725
2023-05-07 49812.835
2023-05-08 50175.792
2023-05-09 53571.610
[200 rows x 1 columns]
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 19 (9 by maintainers)
Hi @Osthumus
I’ve add nextPageCursor in the ccxt. Now you can fetch data in this way:
Hi @Osthumus
It seems they always retrieve data from the current time if the
endTimeis not set (fetchOpenInterestHistory). The return order is by timestamp desc.The
fetchFundingRateHistoryworks for me. Would you like to post verbose log for the request?