Websocket connexion

Does anyone know what is the latest Binance API function version of start_multiplex_socket,
start_user_socket, start_symbol_ticker_socket or similar from
BinanceSocketManager or another module to start socket connexion.

Would be very much appreciated !

Hello,
it seems you’re using python-binance, which is not the official library and therefore we don’t support. Although if you’re keen to explore to the official one, you can check at Binance Public API Connector Python — binance-connector documentation or GitHub - binance/binance-connector-python: a simple connector to Binance Public API.

1 Like

Oh, so I could try with this library then,
Thanks a lot.

However, binance_connector is not recognized on Anaconda. It says the package in unavailable

Hi, it’s binance-connector actually. Try that instead.

pip install binance-connector is the recommended PyPi installation command.

Processing: Capture d’écran 2023-05-29 225927.png…

Still doesn’t work

In addition to python-binance and the binance-connector, there is also the UNICORN Binance Suite. Although it costs money, it works very reliably and is continuously developed and optimized: GitHub - LUCIT-Systems-and-Development/unicorn-binance-websocket-api: A Python SDK by LUCIT to use the Binance Websocket API`s (com+testnet, com-margin+testnet, com-isolated_margin+testnet, com-futures+testnet, com-coin_futures, us, tr, dex/chain+testnet) in a simple, fast, flexible, robust and fully-featured way.

For transparency, I am the programmer of the UNICORN Binance Suite and would like to present my solutions! :slight_smile:

Here is a full script for a multiplex stream:

from unicorn_binance_websocket_api import BinanceWebSocketApiManager
import asyncio

async def main():
    async def process_asyncio_queue(stream_id=None):
        print(f"Start processing the data from stream '{ubwa.get_stream_label(stream_id)}':")
        while ubwa.is_stop_request(stream_id) is False:
            data = await ubwa.get_stream_data_from_asyncio_queue(stream_id)
            print(data)
            ubwa.asyncio_queue_task_done(stream_id)

    ubwa.create_stream(channels=['trade', 'kline_1m'],
                       markets=['ethbtc', 'btcusdt'],
                       stream_label="MULTIPLEX",
                       process_asyncio_queue=process_asyncio_queue)
    while not ubwa.is_manager_stopping():
            await asyncio.sleep(1)

with BinanceWebSocketApiManager(exchange='binance.com') as ubwa:
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print("\r\nGracefully stopping ...")
    except Exception as e:
        print(f"\r\nERROR: {e}\r\nGracefully stopping ...")

once I launch my strategy bot my terminal displays this : APIError(code=-1121): Invalid symbol :
Traceback (most recent call last):
File “/Users/brandonmbambi/Documents/BOT/bot280524/BOT.py”, line 134, in
main()
File “/Users/brandonmbambi/Documents/BOT/bot280524/BOT.py”, line 91, in main
set_leverage(symbol, leverage)
File “/Users/brandonmbambi/Documents/BOT/bot280524/BOT.py”, line 42, in set_leverage
client.futures_change_leverage(symbol=symbol, leverage=leverage)
File “/Users/brandonmbambi/trading_bot_env/lib/python3.12/site-packages/binance/client.py”, line 6590, in futures_change_leverage
return self._request_futures_api(‘post’, ‘leverage’, True, data=params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/brandonmbambi/trading_bot_env/lib/python3.12/site-packages/binance/client.py”, line 383, in _request_futures_api
return self._request(method, uri, signed, True, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/brandonmbambi/trading_bot_env/lib/python3.12/site-packages/binance/client.py”, line 359, in _request
return self._handle_response(self.response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/brandonmbambi/trading_bot_env/lib/python3.12/site-packages/binance/client.py”, line 368, in _handle_response
raise BinanceAPIException(response, response.status_code, response.text)
binance.exceptions.BinanceAPIException: APIError(code=-1121): Invalid symbol.
(trading_bot_env) brandonmbambi@MacBook-Pro-3 ~ %