Files
quant-data-collect/comsumer/order.py
yhydev@outlook.com 75a80698fb 优化代码
2025-06-15 02:01:20 +00:00

25 lines
852 B
Python

from binance import AsyncClient,BinanceSocketManager
import kafka_service
import asyncio
import json
from loguru import logger
async def start():
pass
async def start_bn_future_order_consumer(account_id, api_key, api_secret, testnet=False):
client = await AsyncClient.create(api_key, api_secret, testnet=testnet)
bm = BinanceSocketManager(client, max_queue_size=100000)
ws = bm.futures_user_socket()
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}")