'Why is depth book not showing bid and ask price?

When I try this code, I get best bid/ask price:

async def depth_book(client):
    symbol = "BTCUSDT"
    bm = BinanceSocketManager(client)
    ds = bm.depth_socket(symbol, depth=BinanceSocketManager.WEBSOCKET_DEPTH_5)

    async with ds as depth_socket:
        while True:
            res = await depth_socket.recv()
            print(res)

    await client.close_connection()

Output:

{
    "lastUpdateId": 19040448324,
    "bids": [
        ["32260.24000000", "0.65396000"],
        ["32260.20000000", "0.00385000"],
        ["32258.84000000", "0.01489000"],
        ["32256.09000000", "0.00062000"],
        ["32255.44000000", "0.14932000"],
    ],
    "asks": [
        ["32260.25000000", "2.87357000"],
        ["32260.29000000", "0.00139000"],
        ["32262.19000000", "0.48023000"],
        ["32262.20000000", "1.12084000"],
        ["32262.52000000", "0.80000000"],
    ],
}

But when I try this code I don't see the same response:

async def depth_book2(client):
    symbol = SYMBOL

    twm = ThreadedWebsocketManager(api_key=KEY, api_secret=SECRET_KEY)
    twm.start()

    def handle_socket_message(msg):
        print(msg)

    twm.start_depth_socket(callback=handle_socket_message, symbol=symbol)

    twm.join()

I get something like:

{
    "e": "depthUpdate",
    "E": 1652111145422,
    "s": "BTCUSDT",
    "U": 19040479632,
    "u": 19040479716,
    "b": [
        ["32296.03000000", "3.69493000"],
        ["32295.99000000", "0.00000000"],
        ["32295.11000000", "0.01616000"],
        ["32295.09000000", "0.00000000"],
        ["32294.04000000", "0.01318000"],
        ["32294.03000000", "0.00000000"],
        ["32290.50000000", "0.00000000"],
        ["32288.30000000", "2.30106000"],
        ["32288.29000000", "0.00000000"],
        ["32286.79000000", "0.01534000"],
        ["32284.97000000", "0.15479000"],
        ["32284.80000000"],
    ],
}

What am I missing? I also intend to use ThreadedWebsocketManager so that's why I need it to be like the first one.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source