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

python-binance Websocket imcompatability with Python 3.10. Also not working with Python version greater than Python 3.7. #1335

Open
bairavand opened this issue Jun 23, 2023 · 5 comments

Comments

@bairavand
Copy link

bairavand commented Jun 23, 2023

Describe the bug
I was using python-binance with Python 3.7 and it was working fine. I upgraded Python version to 3.10 and I unable to get websocket response. I also tried with Python 3.8 that is also not working. Is there any way to handle it?

To Reproduce
Code snippet to reproduce the behavior:

client = await AsyncClient.create(api_key='', api_secret='', testnet=True)
bm = BinanceSocketManager(client, user_timeout=3600)
# start any sockets here, i.e a trade socket
ts = bm.futures_user_socket()
# then start receiving messages
async with ts as tscm:
    while True:
        res = await tscm.recv()

Expected behavior
Inside the while loop the trade response should come whenever a trade happens on Binance. but after upgraded to Python 3.10 the response is not triggered and I didn't receive any error.
Environment:

  • Python version: 3.10
  • Virtual Env: virtualenv
  • OS: Mac and Ubuntu
  • python-binance version 1.0.17

Logs or Additional context
I didn't receive the websocket response. Other than that, there is no specific error

@bairavand bairavand changed the title Websocket imcompatability with Python 3.10 (also greater than Python 3.7) python-binance Websocket imcompatability with Python 3.10. Also not working with Python version greater than Python 3.7. Jun 23, 2023
@thiemo-seys
Copy link

Did you manage to find a solution yet? Im running into the same issue

@bairavand
Copy link
Author

I didn't find any solution yet. I planned to switch to an another library called binance-connector which is currently supporting Python 3.10 and also it's an official Binance library.

@OpenCoderX
Copy link
Contributor

Another user opened issue #1354 that seems related.

@OpenCoderX
Copy link
Contributor

@bairavand Do you also have an instance of ThreadedDepthCacheManager in your application?

@vzhilov
Copy link

vzhilov commented Oct 30, 2023

With the simple script like below I get the same error, but not the ThreadedDepthCacheManager one. Also no scripts from the examples work for me giving the same error.

import time
from binance import ThreadedWebsocketManager

def on_message(message):
    event_time = message['data']['E']
    close_time = message['data']['k']['T']
    close_price = message['data']['k']['c']
    print(f"Event Time: {event_time}, Close Time: {close_time}, Close Price: {close_price}")

symbol = 'BNBBTC'
interval = '1m'

twm = ThreadedWebsocketManager(api_key=api_key, api_secret=api_secret)
twm.start()

twm.start_kline_socket(callback=on_message, symbol=symbol)
twm.join()

while True:
    time.sleep(1)

Exception in thread Thread-5:
Traceback (most recent call last):
File "C:\ProgramData\miniconda3\envs\streams\lib\threading.py", line 1016, in _bootstrap_inner
self.run()
File "C:\ProgramData\miniconda3\envs\streams\lib\site-packages\binance\threaded_stream.py", line 56, in run
self._loop.run_until_complete(self.socket_listener())
File "C:\ProgramData\miniconda3\envs\streams\lib\asyncio\base_events.py", line 625, in run_until_complete
self._check_running()
File "C:\ProgramData\miniconda3\envs\streams\lib\asyncio\base_events.py", line 584, in _check_running
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
C:\ProgramData\miniconda3\envs\streams\lib\threading.py:1018: RuntimeWarning: coroutine 'ThreadedApiManager.socket_listener' was never awaited
self._invoke_excepthook(self)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

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

5 participants