= f'wss://stream.binance.com:9443/stream?streams={pair}@miniTicker'
async with websockets.connect(binance_ws) as client:
while True:
data = json.loads(await client.recv())['data']
event_time = time.localtime(data['E'] // 1000)
yield {'pair': pair, 'event_time': event_time, 'price': data['c']}
@router.get('/courses')
async def get_currency_courses(pairs: str, exchanger: str = 'binance'):
try:
tasks = [get_currency_rate_binance(pair) for pair in pairs]
result = await asyncio.gather(*tasks)
return result
except Exception as e:
print(e)
Попробуй писать await перед вызовом get_currency_rate_binance
я вроде как фиксанул, теперь код выглядит вот так: async def get_currency_rate_binance(pair: str = 'btcusdt'): binance_ws = "wss://stream.binance.com:9443/stream?streams=ltcbtc@aggTrade/ethbtc@aggTrade" async with websockets.connect(binance_ws) as client: data = json.loads(await client.recv())['data'] print(data) return {'pair': data['s'], 'price': data['c']}
Обсуждают сегодня