Skip to content

Commit

Permalink
binance: wrap streamer async-gen in aclosing()
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed Mar 13, 2023
1 parent 889e920 commit 5a07542
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions piker/brokers/binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
)
import time

from async_generator import aclosing
import trio
from trio_typing import TaskStatus
import pendulum
Expand Down Expand Up @@ -529,14 +530,14 @@ async def subscribe(ws: wsproto.WSConnection):
# XXX: do we need to ack the unsub?
# await ws.recv_msg()

async with open_autorecon_ws(
'wss://stream.binance.com/ws',
fixture=subscribe,
) as ws:

async with (
open_autorecon_ws(
'wss://stream.binance.com/ws',
fixture=subscribe,
) as ws,
aclosing(stream_messages(ws)) as msg_gen,
):
# pull a first quote and deliver
msg_gen = stream_messages(ws)

typ, quote = await msg_gen.__anext__()

while typ != 'trade':
Expand Down

0 comments on commit 5a07542

Please sign in to comment.