sammchardy / python-binance

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

binance.exceptions.BinanceAPIException: APIError(code=-1121): Invalid symbol #1146

Open tobeyond opened 2 years ago

tobeyond commented 2 years ago

Describe the bug When I try to trade futures, I always get this error: binance.exceptions.BinanceAPIException: APIError(code=-1121): Invalid symbol

The thing is I'm using valid pairs (eg: BTCUSDT). I can get the pair's information, but when I try futures_coin_change_leverage() or futures_coin_create_order() it returns this error. I don't know if it's because I'm in a different timezone or if this wrapper is broken.

To Reproduce client.futures_coin_change_leverage(symbol='BTCUSDT', leverage=5)

Logs or Additional context

File "C:\Users...\futures_bot.py", line 464, in start client.futures_coin_change_leverage(symbol='BTCUSDT', leverage=5) File "C:\Users...\AppData\Roaming\Python\Python38\site-packages\binance\client.py", line 6326, in futures_coin_change_leverage return self._request_futures_coin_api( File "C:\Users...\AppData\Roaming\Python\Python38\site-packages\binance\client.py", line 349, in _request_futures_coin_api return self._request(method, uri, signed, True, **kwargs) File "C:\Users...\AppData\Roaming\Python\Python38\site-packages\binance\client.py", line 315, in _request return self._handle_response(self.response) File "C:\Users...\AppData\Roaming\Python\Python38\site-packages\binance\client.py", line 324, in _handle_response raise BinanceAPIException(response, response.status_code, response.text) binance.exceptions.BinanceAPIException: APIError(code=-1121): Invalid symbol.

halfelf commented 2 years ago

Method starts with futures_coin is for coin-m futures, not usd-m futures.

Check exchange_info api for the right symbol name.

tobeyond commented 2 years ago

Thank you. It is mainly working now with the right functions, except the futures_cancel_orders() method. It returns:

CANCEL = client.futures_cancel_order(symbol=pair, origClientOrderIdList=cancel_list)

File ~...\virtual_binance\lib\site-packages\binance\client.py:5898, in Client.futures_cancel_order(self, params) 5892 def futures_cancel_order(self, params): 5893 """Cancel an active futures order. 5894 5895 https://binance-docs.github.io/apidocs/futures/en/#cancel-order-trade 5896 5897 """ -> 5898 return self._request_futures_api('delete', 'order', True, data=params)

File ~...\lib\site-packages\binance\client.py:339, in Client._request_futures_api(self, method, path, signed, kwargs) 336 def _request_futures_api(self, method, path, signed=False, kwargs) -> Dict: 337 uri = self._create_futures_api_uri(path) --> 339 return self._request(method, uri, signed, True, **kwargs)

File ~...\lib\site-packages\binance\client.py:315, in Client._request(self, method, uri, signed, force_params, kwargs) 312 kwargs = self._get_request_kwargs(method, signed, force_params, kwargs) 314 self.response = getattr(self.session, method)(uri, **kwargs) --> 315 return self._handle_response(self.response)

File ~...\lib\site-packages\binance\client.py:324, in Client._handle_response(response) 319 """Internal helper for handling API responses from the Binance server. 320 Raises the appropriate exceptions when necessary; otherwise, returns the 321 response. 322 """ 323 if not (200 <= response.status_code < 300): --> 324 raise BinanceAPIException(response, response.status_code, response.text) 325 try: 326 return response.json()

BinanceAPIException: APIError(code=-1022): Signature for this request is not valid.

I'm able to buy, so the issue is not the signature.

tobeyond commented 2 years ago

Nevermind, I found out I needed to parse the list and it worked.

picasso999 commented 2 years ago

I need help on this, it is working for me with BTCUSDT,ETHUSDT,XRPUSDT,LTCUSDT but when I am trying to run with same config , it is not working for other coin sets! like: SOLUSDT, MATICUSDT, LUNAUSDT and all! Can anyone help me with this issue. thank you.

Traceback (most recent call last): File "C:\Users\Administrator\Desktop\Part2_Materials\Part2_Materials\LUNA30mFutures.py", line 196, in trader6.start_trading(historical_days = 12) File "C:\Users\Administrator\Desktop\Part2_Materials\Part2_Materials\LUNA30mFutures.py", line 43, in start_trading self.get_most_recent(symbol = self.symbol, interval = self.bar_length, File "C:\Users\Administrator\Desktop\Part2_Materials\Part2_Materials\LUNA30mFutures.py", line 53, in get_most_recent bars = client.get_historical_klines(symbol = symbol, interval = interval, File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 932, in get_historical_klines return self._historical_klines(symbol, interval, start_str, end_str=end_str, limit=limit, klines_type=klines_type) File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 967, in _historical_klines first_valid_ts = self._get_earliest_valid_timestamp(symbol, interval, klines_type) File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 902, in _get_earliest_valid_timestamp kline = self._klines( File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 883, in _klines return self.get_klines(params) File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 868, in get_klines return self._get('klines', data=params, version=self.PRIVATE_API_VERSION) File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 371, in _get return self._request_api('get', path, signed, version, kwargs) File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 334, in _request_api return self._request(method, uri, signed, **kwargs) File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 315, in _request return self._handle_response(self.response) File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 324, in _handle_response raise BinanceAPIException(response, response.status_code, response.text) binance.exceptions.BinanceAPIException: APIError(code=-1121): Invalid symbol.

mirono commented 2 years ago

I have a similar issue, it is working for ETHUSDT but not for ETHBUSD

khalikovSalavat commented 1 year ago

I need help on this, it is working for me with BTCUSDT,ETHUSDT,XRPUSDT,LTCUSDT but when I am trying to run with same config , it is not working for other coin sets! like: SOLUSDT, MATICUSDT, LUNAUSDT and all! Can anyone help me with this issue. thank you.

Traceback (most recent call last): File "C:\Users\Administrator\Desktop\Part2_Materials\Part2_Materials\LUNA30mFutures.py", line 196, in trader6.start_trading(historical_days = 12) File "C:\Users\Administrator\Desktop\Part2_Materials\Part2_Materials\LUNA30mFutures.py", line 43, in start_trading self.get_most_recent(symbol = self.symbol, interval = self.bar_length, File "C:\Users\Administrator\Desktop\Part2_Materials\Part2_Materials\LUNA30mFutures.py", line 53, in get_most_recent bars = client.get_historical_klines(symbol = symbol, interval = interval, File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 932, in get_historical_klines return self._historical_klines(symbol, interval, start_str, end_str=end_str, limit=limit, klines_type=klines_type) File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 967, in _historical_klines first_valid_ts = self._get_earliest_valid_timestamp(symbol, interval, klines_type) File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 902, in _get_earliest_valid_timestamp kline = self._klines( File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 883, in _klines return self.get_klines(params) File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 868, in get_klines return self._get('klines', data=params, version=self.PRIVATE_API_VERSION) File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 371, in _get return self._request_api('get', path, signed, version, kwargs) File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 334, in _request_api return self._request(method, uri, signed, **kwargs) File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 315, in _request return self._handle_response(self.response) File "C:\ProgramData\Anaconda3\envs\trader\lib\site-packages\binance\client.py", line 324, in _handle_response raise BinanceAPIException(response, response.status_code, response.text) binance.exceptions.BinanceAPIException: APIError(code=-1121): Invalid symbol.

Have you solved this issue?

lacondeguy commented 1 year ago

Have you solved this issue?

1) client.API_URL = https://testnet.binance.vision/api in that case change it to https://api.binance.com/api

2) Client(api_key, secret_key, testnet=True) in that case change testnet=False or delete it

abdrakhmanovi commented 1 year ago

Nevermind, I found out I needed to parse the list and it worked.

how did you parse it? i have the same issue