Reputation: 13571
I want to use Binance_Futures_python API to get the balance of my account.
Here's my code:
import binance_f
fclient = binance_f.RequestClient(api_key='<my_api_key>', secret_key='<my_secret_key>', url='https://fapi.binance.com')
result = fclient.get_balance()
And the error message of the above code is
Traceback (most recent call last):
File "/Users/brian.lee/my_gitlab/binance_api_test/test_error.py", line 4, in <module>
result = fclient.get_balance()
File "/usr/local/lib/python3.9/site-packages/binance_futures-1.1.0-py3.9.egg/binance_f/requestclient.py", line 328, in get_balance
File "/usr/local/lib/python3.9/site-packages/binance_futures-1.1.0-py3.9.egg/binance_f/impl/restapiinvoker.py", line 37, in call_sync
File "/usr/local/lib/python3.9/site-packages/binance_futures-1.1.0-py3.9.egg/binance_f/impl/restapiinvoker.py", line 21, in check_response
binance_f.exception.binanceapiexception.BinanceApiException: ('ExecuteError', '[Executing] -2015: Invalid API-key, IP, or permissions for action, request ip: 111.93.84.192')
Here's the API management page of my Binance account.
I really don't understand why my code fails.
I've opened as many permissions as possible for the API key.
I use a non-US version of Binance (https://www.binance.com/).
I've read this post, but the answers in that post don't work.
Does anyone know the reason of the error?
Upvotes: 1
Views: 5354
Reputation: 21
you can use the python sdk (remove the tld option if you're not on binance.us)
client = Client(api_key=os.getenv("BINANCE_API_KEY"), api_secret=os.getenv("BINANCE_API_SECRET"), tld="us")
@app.get("/test_create_order")
async def test_create_order():
return client.create_test_order(
symbol='ETHUSDT',
side='BUY',
type='LIMIT',
timeInForce='GTC',
quantity=100,
price=2000)
Upvotes: 0
Reputation: 392
For anyone reading this, all you have to do (no this is not a joke) is delete and recreate the api key and secret until one works. This is tried and tested on 3 different Binance accounts. I have no idea what the issue with Binance is but feel that is has something to do with the verification they do via email and phone and google authenticate that sometimes it doesn’t update the key in their db as valid although it tells you it’s been validated and added . Anyways keep recreating those keys till one sticks! I’m answering because I couldn’t find help anywhere on this topic.
Upvotes: 6