sammchardy / python-binance

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

Threadedwebsocket doesn't show any result #1030

Open frouzbeh opened 2 years ago

frouzbeh commented 2 years ago

Describe the bug I am trying to get realtime kline record using threadedwebsocketmanager, but when I run the code it absolutely shows nothing. Only one time when I just left the code running, when I came back I saw couple of records which was exactly what I want. But other time absolutely nothing.

To Reproduce `import time from binance.client import Client # Import the Binance Client from binance import ThreadedWebsocketManager # Import the Binance Socket Manager import os

PUBLIC = os.environ.get('binance_api') SECRET = os.environ.get('binance_secret')

twm = ThreadedWebsocketManager(api_key=PUBLIC, api_secret=SECRET, tld='us')

def handle_message(msg): print(msg)

conn_key = twm.start_kline_socket(callback=handle_message, symbol='ETHBTC') twm.start()

time.sleep(10)

twm.stop_socket(conn_key)`

Expected behavior Showing the realtime kline records. Environment (please complete the following information):

Logs or Additional context No output.

jasonish commented 2 years ago

Was running into this myself tonight so came to these and issues to check. Appears this was reported a couple days ago, see https://github.com/sammchardy/python-binance/issues/1023. The solution (for now) is to downgrade the websockets module to 9.1.

frouzbeh commented 2 years ago

@jasonish Thank you. I was able to make it work last night. I just needed to put a twm.join() after starting the socket. But still it's veryyyyy slow. I'll try with websocket 9.1 to see if it gets better.

Thanks,