From 0e9c7dfe85eb22bb5633791c719cb4d5e2a6636a Mon Sep 17 00:00:00 2001 From: yhydev Date: Sun, 15 Jun 2025 03:03:31 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comsumer/order.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/comsumer/order.py b/comsumer/order.py index 85c03c1..3e17dbd 100644 --- a/comsumer/order.py +++ b/comsumer/order.py @@ -16,13 +16,13 @@ async def start_bn_future_order_consumer(account_id, api_key, api_secret, testne client = await AsyncClient.create(api_key, api_secret, testnet=testnet) bm = BinanceSocketManager(client, max_queue_size=100000) ws = bm.futures_user_socket() - while True: - msg = await ws.recv() - msg['x-account-id'] = account_id - asyncio.create_task(send_msg(msg)) - + async with ws as stream: + while True: + msg = await ws.recv() + msg['x-account-id'] = account_id + asyncio.create_task(send_msg(msg)) async def send_msg(msg): logger.info(f"send to kafka: {msg}") await kafka_service.send_to_kafka("binance_future_order_update", json.dumps(msg),key="DEFAULT",send_now=True) - logger.info(f"send to kafka success: {msg}") \ No newline at end of file + logger.info(f"send to kafka success: {msg}")