futures open interest error(wrong data output from binance)

Hey I am having an issue with getting futures open interest from binance api. I think the error is on binance side since every other endpoint works well(mark price, funding…).

code to recreate error:

from binance.client import Client

client = Client(api_key, api_secret)
oi = client.futures_open_interest(symbol="BTCUSDT")

error I get:

binance.exceptions.BinanceAPIException: APIError(code=0): Invalid JSON error message from Binance

  • some html

what should this code return:

data about open interest in json format

for example:

mark = client.futures_mark_price(symbol="BTCUSDT")

above code returns this:

{‘symbol’: ‘BTCUSDT’, ‘markPrice’: ‘9153.01075457’, ‘lastFundingRate’: ‘0.00010000’, ‘nextFundingTime’: 1593072000000, ‘time’: 1593069849000}

OS: Windows
Lang.: python 3.7.6
package needed for this to work -> python-binance


I also tried SDK provided from binance(output here works) but I still think there is some kind of an error on binance side since ouptut is different from the data provided on binance website.

from api I get OI around 6000(red circles on img) but on the website the OI is around 38000
link to futures oi on website: https://www.binance.com/en/futures/funding-history/0

Futures’ openinterst is returned from public data endpoint, which should be easy to debug.

curl -s "https://fapi.binance.com/fapi/v1/openInterest?symbol=BTCUSDT"

I’m afraid there is somewhere worth to debug in the client side. :slight_smile:

For the first example I figured it out that error is on my side.

But now I am using SDK provided by binance and I get the response from api but the data is wrong.
There is no other code for than line 27 in the img(I don’t really know what is to debug there) and I am also using official SDK so I don’t really know where to look for problems.

Mark price works as it should which confuses me even further(I would expect open interesti to work same as mark price)

the library seems works on testnet by default, please try to provide the url:

request_client = RequestClient(api_key=g_api_key, secret_key=g_secret_key, url="https://fapi.binance.com")

result = request_client.get_open_interest(symbol="BTCUSDT")
1 Like

Thank you and sorry for that trivial mistake(url was the problem) I am fairly new to this api thing.

1 Like