python-binance icon indicating copy to clipboard operation
python-binance copied to clipboard

Example does not work

Open KissCoderr opened this issue 1 year ago • 2 comments

Is this code works?

Describe the bug ConnectionClosedError (received 1003 (unsupported data) binary frames are not supported; then sent 1003 (unsupported data) binary frames are not supported) BinanceWebsocketClosed (Connection closed. Reconnecting...) Traceback (most recent call last): File "C:\Users\ersint\AppData\Local\Programs\Python\Python313\Lib\asyncio\tasks.py", line 507, in wait_for return await fut ^^^^^^^^^ asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\ersint\AppData\Local\Programs\Python\Python313\Lib\site-packages\binance\ws\websocket_api.py", line 107, in request response = await asyncio.wait_for(future, timeout=self.TIMEOUT) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ersint\AppData\Local\Programs\Python\Python313\Lib\asyncio\tasks.py", line 506, in wait_for async with timeouts.timeout(timeout): ~~~~~~~~~~~~~~~~^^^^^^^^^ File "C:\Users\ersint\AppData\Local\Programs\Python\Python313\Lib\asyncio\timeouts.py", line 116, in aexit raise TimeoutError from exc_val TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "F:\pythonProject3\silsonra.py", line 28, in main() ~~~~^^ File "F:\pythonProject3\silsonra.py", line 19, in main order = client.ws_create_order( symbol="LTCUSDT", ...<2 lines>... quantity=0.1, ) File "C:\Users\ersint\AppData\Local\Programs\Python\Python313\Lib\site-packages\binance\client.py", line 10788, in ws_create_order return self._ws_api_request_sync("order.place", True, params) ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ersint\AppData\Local\Programs\Python\Python313\Lib\site-packages\binance\base_client.py", line 413, in _ws_api_request_sync return self.loop.run_until_complete( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ self._ws_api_request(method, signed, params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "C:\Users\ersint\AppData\Local\Programs\Python\Python313\Lib\asyncio\base_events.py", line 720, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "C:\Users\ersint\AppData\Local\Programs\Python\Python313\Lib\site-packages\binance\base_client.py", line 408, in _ws_api_request return await self.ws_api.request(id, payload) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ersint\AppData\Local\Programs\Python\Python313\Lib\site-packages\binance\ws\websocket_api.py", line 116, in request raise BinanceWebsocketUnableToConnect("Request timed out") binance.exceptions.BinanceWebsocketUnableToConnect: Request timed out

To Reproduce import os import sys import asyncio

root = os.path.dirname(os.path.dirname(os.path.abspath(file))) sys.path.append(root)

from binance import AsyncClient

create order using websockets async

the API is very similar to the REST API

async def main(): api_key = "" # your api_key here secret = "" # your secret here client = AsyncClient(api_key, secret, testnet=True) order = await client.ws_create_order( symbol="LTCUSDT", side="BUY", type="MARKET", quantity=0.1, ) print(order["orderId"]) await client.close_connection()

asyncio.run(main())

Environment (please complete the following information):

  • Python version: 3.13
  • Virtual Env: virtualenv
  • python-binance version 1.0.27

KissCoderr avatar Jan 20 '25 19:01 KissCoderr

Hello @KissCoderr,

Yes locally it is working, are you sure this is not a network-related issue?

carlosmiei avatar Jan 21 '25 17:01 carlosmiei

same error,my mac use proxy,but i do not know how to config ThreadedWebsocketManager, Clinet works well,, klines = self.client.get_historical_klines( symbol=Config.SYMBOL, interval=interval, start_str=start_str ) success, work on it for 1day

SnoopPanda avatar Apr 27 '25 08:04 SnoopPanda