sammchardy / python-binance

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

Issue when using socket with a different symbol #762

Open deaton1337 opened 3 years ago

deaton1337 commented 3 years ago

Hello,

I have no issues buying and selling via the API, but when I use the socket as detailed in the demo script, everything works fine until I change the symbol. Then sometimes it works, sometimes it continues with the old symbol.

To Reproduce

        conn_key = bsm.start_symbol_ticker_socket('adabct', coin_trade_history)
        bsm.start()

        bsm.close()
        bsm.start_symbol_ticker_socket('ethbtc', coin_trade_history)

Expected behavior I'd expect the above to start return details about Eth, but sometimes it keeps the old coin.

Environment (please complete the following information):

Logs or Additional context I'm not sure bsm.close() is actually doing anything.

ongunarisev commented 3 years ago

I think this does not properly close the socket. Maybe implement the socket closure as detailed in https://algotrading101.com/learn/binance-python-api-guide/ which will yield a MWE as follows:

init and start the WebSocket

bsm = BinanceSocketManager(client) conn_key = bsm.start_symbol_ticker_socket('BTCUSDT', btc_trade_history) bsm.start()

Stop Websocket

bsm.stop_socket(conn_key)

Terminate WebSocket

reactor.stop()