How to get Futers Open Interest Historical Data for BTCUSDT pair

import requests
import pandas as pd
from binance.client import Client
from datetime import datetime
import datetime as dt

apikey=**my api
secret=**my api
startDT=dt.datetime(2022,9,1,00,00,00)
endDT=dt.datetime(2022,9,20,00,00,00)


#historical price data from binance api
symbol="BTCUSDT"
period="5m"
limit="500"
startTime=int(datetime.timestamp(startDT))
endTime=int(datetime.timestamp(endDT))

oi_data=requests.get(f'https://www.binance.com/futures/data/openInterestHist?symbol={symbol}&period={period}&limit={limit}&startTime=1663692242&endTime=1663695902')
oi_json=oi_data.json()

print(oi_json)

every time how much I tried using different startTime and endTime formats it returns the error

{'msg': "parameter 'startTime' is invalid.", 'code': -1130}
<Response [400]>

But if I remove the startTime and endTime parameters it returns the latest open interest values for the given limit

Hey, so look at Binance API Documentation to find that:

  • you’re not using the correct base url for Futures API.
  • all timestamps are in ms

This works:
GET https://fapi.binance.com/futures/data/openInterestHist?symbol=BTCUSDT&period=5m&limit=30&startTime=1663695902000&endTime=1663866791000

1 Like

Thank You,

the error was in the url.