Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example does not work #1548

Open
KissCoderr opened this issue Jan 20, 2025 · 1 comment
Open

Example does not work #1548

KissCoderr opened this issue Jan 20, 2025 · 1 comment
Assignees

Comments

@KissCoderr
Copy link

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
@carlosmiei
Copy link
Collaborator

Hello @KissCoderr,

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants