sammchardy / python-binance

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

Fixed threaded stream and futures user socket #1233

Closed casper-hansen closed 1 year ago

casper-hansen commented 2 years ago

Fix #1200 and #1174 with Python 3.8.13

The stream does not work anymore with the standard code presented. We have to change the threading approach to run it successfully. Additionally, we should also be able to use the testnet for the futures stream in combination with the threaded approach, so that has also been fixed. @sammchardy

Minimal testing example:

import time
from binance.streams import ThreadedWebsocketManager

def handler(order_data):
    print(order_data)

manager = ThreadedWebsocketManager(
    API_KEY, 
    API_SECRET, 
    testnet=True
)

manager.daemon = True # ctrl-c works
manager.start()
manager.start_futures_user_socket(handler)

while True:
    # run your other code here
    time.sleep(0.1)
sammchardy commented 1 year ago

Thanks @casperbh96