Hello everyone,
starting from this example taken from the official binance-connector documentation
from binance.websocket.spot.websocket_client import SpotWebsocketClient as WebsocketClient
def message_handler(message):
print(message)
ws_client = WebsocketClient()
ws_client.start()
ws_client.mini_ticker(
symbol=‘bnbusdt’,
id=1,
callback=message_handler,
)
ws_client.instant_subscribe(
stream=[‘bnbusdt@bookTicker’, ‘ethusdt@bookTicker’],
callback=message_handler,
)
ws_client.stop()
I implemented this
from binance.websocket.spot.websocket_client import SpotWebsocketClient as WebsocketClient
def message_handler(message):
print(message)
ws_client = WebsocketClient()
ws_client.start()
ws_client.instant_subscribe(
stream=‘!miniTicker@arr’,
callback=message_handler,
)
ws_client.stop()
but I’m encountering this error
ModuleNotFoundError: No module named 'binance.websocket.spot.websocket_client'
I corrected it in this way
from binance.client import Client
from binance.streams import BinanceSocketManager
def message_handler(message):
print(message)
client = Client(API_KEY, API_SECRET)
ws_client = BinanceSocketManager(client)
#ws_client.start()
ws_client.instant_subscribe(
stream=‘!miniTicker@arr’,
callback=message_handler,
)
ws_client.stop()
but I still get an error
AttributeError: 'BinanceSocketManager' object has no attribute 'instant_subscribe'
.
How is it possible that the official documentation is not up to date? How can I resolve this?
Thank you.