DEV Community

Lukas Eber
Lukas Eber

Posted on

Very very basic python-binance ThreadedWebSocketManager example does not work... why?

I have an application that uses the binance api to trade and do some other stuff. The app worked fine for like 2 years, but one day it stopped working. So i decided to create a basic script to validate the core functionality of the api. I did everything exactly like its described in several offical docs and tutorials but its still not working as expected. Here is my code:

from binance import Client, ThreadedWebsocketManager

api_key = 'my_key'
api_secret = 'my_secret'

client = Client(api_key, api_secret)

def process_message(msg):
    print("message type: {}".format(msg['e']))
    print(msg)

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

ret = twm.start_kline_socket(callback=process_message, symbol='BTCEUR', interval='1m')
print(ret)

twm.join()
Enter fullscreen mode Exit fullscreen mode

So, what happens at all? The twm is created and my print statement returns: btceur@kline_1m
thats all. I expected the script to call the process_message func every 1 minute, but it does not get called after a 1 min session has completed. I have seen some similar troubles with older versions, have tried all possible solutions but I wasn´t able to fix it. I am using the latest python-binance version, v1.0.19 - 2023-08-11 and python 3.12.3

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay