sammchardy / python-binance

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

API: "futures_coin_recent_trades" doesn't work? #1211

Closed yiluzhou closed 2 years ago

yiluzhou commented 2 years ago

It looks USDT-M Futures API works, while COIN-M Futures API doesn't work.

For example, the following for USDT-M Futures works! recent_trades = client.futures_recent_trades(symbol='BTCUSDT')

While the following for COIN-M Futures doesn't work. recent_trades = client.futures_coin_recent_trades(symbol='BTCUSD') https://github.com/sammchardy/python-binance/blob/59e3c8045fa13ca0ba038d4a2e0481212b3b665f/binance/client.py#L6205

Error message as below: APIError(code=-1121): Invalid symbol. Is this a bug? Thank you!

---------------------------------------------------------------------------
BinanceAPIException                       Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_13620/2129933085.py in <module>
     11 """
     12 
---> 13 recent_trades = client.futures_coin_recent_trades(symbol='BTCUSD')

D:\ProgramData\Anaconda3\lib\site-packages\binance\client.py in futures_coin_recent_trades(self, **params)
   6209 
   6210         """
-> 6211         return self._request_futures_coin_api("get", "trades", data=params)
   6212 
   6213     def futures_coin_historical_trades(self, **params):

D:\ProgramData\Anaconda3\lib\site-packages\binance\client.py in _request_futures_coin_api(self, method, path, signed, version, **kwargs)
    347         uri = self._create_futures_coin_api_url(path, version=version)
    348 
--> 349         return self._request(method, uri, signed, True, **kwargs)
    350 
    351     def _request_futures_coin_data_api(self, method, path, signed=False, version=1, **kwargs) -> Dict:

D:\ProgramData\Anaconda3\lib\site-packages\binance\client.py in _request(self, method, uri, signed, force_params, **kwargs)
    313 
    314         self.response = getattr(self.session, method)(uri, **kwargs)
--> 315         return self._handle_response(self.response)
    316 
    317     @staticmethod

D:\ProgramData\Anaconda3\lib\site-packages\binance\client.py in _handle_response(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=-1121): Invalid symbol.
halfelf commented 2 years ago

I believe the exception has explained why the API request failed well.

yiluzhou commented 2 years ago

I believe the exception has explained why the API request failed well.

But the symbol should be correct. I've tried several symbols for COIN-M Futures.

halfelf commented 2 years ago

Clearly it's not correct. Try to find the correct one in exchange_info()

yiluzhou commented 2 years ago

Clearly it's not correct. Try to find the correct one in exchange_info()

Thank you so much! I just checked futures_coin_exchange_info, and realized the symbol should be "BTCUSD_PERP"...