sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
6.01k stars 2.2k forks source link

APIError(code=-2015): Invalid API-key, IP, or permissions for action. When getting account info #778

Open numerocat opened 3 years ago

numerocat commented 3 years ago

When i run the python script balance = client.get_asset_balance(asset="USDT") i get the error -2015

I have 2 api´s, i dont know if that has a role there, i already checked that those are the correct keys. The permissions enabled are: reading spot and margin trading withdrawals universal transfer vanilla options

Reproduce the error: from binance.client import Client client = Client("mykey", "mykey", tld='us') balance = client.get_asset_balance(asset="USDT")

Full error lines: Traceback (most recent call last): File "lol.py", line 19, in balance = client.get_asset_balance(asset="USDT") File "C:\Users\numerocat.conda\envs\bot\lib\site-packages\binance\client.py", line 1847, in get_asset_balance res = self.get_account(params) File "C:\Users\numerocat.conda\envs\bot\lib\site-packages\binance\client.py", line 1822, in get_account return self._get('account', True, data=params) File "C:\Users\numerocat.conda\envs\bot\lib\site-packages\binance\client.py", line 292, in _get return self._request_api('get', path, signed, version, kwargs) File "C:\Users\numerocat.conda\envs\bot\lib\site-packages\binance\client.py", line 242, in _request_api return self._request(method, uri, signed, **kwargs) File "C:\Users\numerocat.conda\envs\bot\lib\site-packages\binance\client.py", line 237, in _request return self._handle_response() File "C:\Users\numerocat.conda\envs\bot\lib\site-packages\binance\client.py", line 285, in _handle_response raise BinanceAPIException(self.response) binance.exceptions.BinanceAPIException: APIError(code=-2015): Invalid API-key, IP, or permissions for action.

egcodes commented 3 years ago

for test try this

client = Client(api_key, api_secret)
client.API_URL = "https://testnet.binance.vision/api"

but there must be a better way to convert all api to test image

numerocat commented 3 years ago

for test try this

client = Client(api_key, api_secret)
client.API_URL = "https://testnet.binance.vision/api"

but there must be a better way to convert all api to test image

Thanks, looks like removing the third argument in Client object fixed it. Awesome!

emrahkirdok commented 3 years ago

Hi, I have also the same error. All the api keys new and relevant permissions are granted. BTW, I am using https://www.trbinance.com

Do you know how can I fix it? Thank you for the help. e

numerocat commented 3 years ago

You should search for the "tld=" argument as i said in my last reply, check it and change it if necessary. I am sorry that i cant help you any further, good luck.

alexrmacleod commented 1 year ago

here is the answer, gotta create a testnet api key which is different to the regular api key via the binance testnet docs

https://stackoverflow.com/questions/67376632/how-to-create-binance-test-api-key

https://testnet.binance.vision/ (click generate api)