WebSocket消息处理,批量订阅,错误处理

新手请教。

1,获取binance的现货期货交易对,480+/280+

2,设定了分批次订阅,和间隔延时

batch_size = 20 delay = 15
3,订阅代码如下

async def subscribe_to_pairs(url, pairs, is_futures, pool):
    """订阅多个交易对的实时数据"""
    retry_delay = 2  # 如果连接失败,等待2秒再次尝试
    # 构造WebSocket URL,以订阅多个交易对
    streams = "/".join([f"{pair.lower()}@trade" for pair in pairs])
    final_url = f"{url}stream?streams={streams}"
    while True:
        try:
            async with websockets.connect(final_url) as ws:
                # print(f"### WebSocket Opened for multiple pairs ###")
                async for message in ws:
                    message_json = json.loads(message)['data']
                    await process_and_insert_data(pool, message_json, is_futures)
        except asyncio.CancelledError:
            # 任务被取消,直接退出
            break
        except websockets.exceptions.WebSocketException as e:
            print(f"WebSocket error: {e}, URL: {final_url}. Retrying in {retry_delay} seconds...")
            await asyncio.sleep(retry_delay)
        except Exception as e:
            print(f"An unexpected error occurred: {e}. Retrying in {retry_delay} seconds...")
            await asyncio.sleep(retry_delay)

async def batch_subscribe(pairs, batch_size, delay, base_url, is_futures, pool):
    print(f"Total pairs to subscribe: {len(pairs)}")
    for i in range(0, len(pairs), batch_size):
        batch = pairs[i:i + batch_size]
        print(f"Subscribing batch {i//batch_size+1}: {batch}")
        # 使用新的订阅函数订阅当前批次的交易对
        asyncio.create_task(subscribe_to_pairs(base_url, batch, is_futures, pool))
        print(f"Batch {i//batch_size+1} subscription initiated.")
        await asyncio.sleep(delay)  # 在每个批次之间等待一段时间

4,问题出现,1011

各位大佬有知道怎么解决的麻烦帮帮,谢谢!