sammchardy / python-binance

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

`start_kline_socket` callback does not permit writing to file #1192

Closed mikkokotila closed 2 years ago

mikkokotila commented 2 years ago

Describe the bug The exact same code which works with start_trade_socket does not work with start_kline_socket in the sense that writing to fill does not work inside the callback function. Even just writing a dummy string does not work i.e. f.write() does nothing when it's inside the callback function.

To Reproduce

f = open('test.csv', 'a')

stream = ThreadedWebsocketManager(api_key=api_key, api_secret=api_secret)

stream.start()

def handle_socket_message(msg):
        f.write('test.csv')

stream.start_kline_socket(callback=handle_socket_message, symbol=symbol)

stream.join()

Expected behavior One should be able to run any arbitrary code, including writing to a file, inside the callback function.

Environment (please complete the following information):

halfelf commented 2 years ago

Please flush the file stream.

mikkokotila commented 2 years ago

That did it. Thanks a lot!