'Fetching the order depth with python-binance, but the code does not complete

I am running a python script to fetch all the current order books for all symbols that ends with USDT.

Whenever I try to run it, it fetches the orderbook for the first three symbols (in this case BTCUSDT, ETHUSDT and BNBUSDT). Any takers on what I am messing up here?

I am using this logic to get a list of the symbols and the order book;

import asyncio
import config as c #from config.py
import infinity as inf #userdefined function for infinity (probably not needed)

from binance import AsyncClient, DepthCacheManager, Client


client = Client(c.API_KEY, c.API_SECRET, tld = 'com')

info = client.get_exchange_info()
symbols = info['symbols']

ls = []

for s in symbols:
    if 'USDT' in s['symbol']:
            #if 'BUSD' not in s['symbol']:
            ls.append(s['symbol'])

async def main():
    
    # initialise the client
    client = await AsyncClient.create()

    for i in ls:
        async with DepthCacheManager(client, symbol= i, limit = 10000) as dcm_socket:
                depth_cache = await dcm_socket.recv()
                symbol = i
                asks = depth_cache.get_asks()[:5]
                bids = depth_cache.get_bids()[:5]
                full = [symbol, asks, bids]
                print(full)
            
    
if __name__ == "__main__":

    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())


Solution 1:[1]

It wouldn't complete, because it's not supposed to. DepthCacheManager is designed to establish a connection (WebSockets), get a snapshot of the order information, and then subscribes to a stream of updates to the current outstanding orders that it applies locally in it's "DepthCache". Each time that gets updated, it deliver the updated set of current asks/bids as you can see.
The trading and orders never stop, so why would it stop?

Solution 2:[2]

Maybe you wana try: https://github.com/LUCIT-Systems-and-Development/unicorn-binance-local-depth-cache

import unicorn_binance_local_depth_cache

ubldc = unicorn_binance_local_depth_cache.BinanceLocalDepthCacheManager(exchange="binance.com")
ubldc.create_depth_cache("LUNABTC")

asks = ubldc.get_asks("LUNABTC")
bids = ubldc.get_bids("LUNABTC")

Thats it :)

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Andrew Downing
Solution 2 Oliver