优化代码
This commit is contained in:
@@ -3,21 +3,24 @@ import kafka_service
|
||||
import asyncio
|
||||
import json
|
||||
from loguru import logger
|
||||
from config import settings
|
||||
async def start():
|
||||
pass
|
||||
awaits = []
|
||||
for api in settings.binance_future_api:
|
||||
acc = start_bn_future_order_consumer(api['account_id'], api['api_key'], api['api_secret'], testnet=api['testnet'])
|
||||
awaits.append(acc)
|
||||
await asyncio.gather(*awaits)
|
||||
|
||||
|
||||
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))
|
||||
|
||||
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}")
|
||||
|
||||
Reference in New Issue
Block a user