Use `Client` in watchlist app
parent
17feb17535
commit
4123139750
|
@ -319,7 +319,7 @@ async def update_quotes(
|
||||||
nursery: 'Nursery',
|
nursery: 'Nursery',
|
||||||
brokermod: ModuleType,
|
brokermod: ModuleType,
|
||||||
widgets: dict,
|
widgets: dict,
|
||||||
queue: 'StreamQueue',
|
client: 'Client',
|
||||||
symbol_data: dict,
|
symbol_data: dict,
|
||||||
first_quotes: dict
|
first_quotes: dict
|
||||||
):
|
):
|
||||||
|
@ -359,7 +359,7 @@ async def update_quotes(
|
||||||
grid.render_rows(cache)
|
grid.render_rows(cache)
|
||||||
|
|
||||||
# core cell update loop
|
# core cell update loop
|
||||||
async for quotes in queue: # new quotes data only
|
async for quotes in client.aiter_recv(): # new quotes data only
|
||||||
for symbol, quote in quotes.items():
|
for symbol, quote in quotes.items():
|
||||||
record, displayable = brokermod.format_quote(
|
record, displayable = brokermod.format_quote(
|
||||||
quote, symbol_data=symbol_data)
|
quote, symbol_data=symbol_data)
|
||||||
|
@ -374,6 +374,7 @@ async def update_quotes(
|
||||||
log.warn("Server connection dropped")
|
log.warn("Server connection dropped")
|
||||||
nursery.cancel_scope.cancel()
|
nursery.cancel_scope.cancel()
|
||||||
|
|
||||||
|
|
||||||
async def run_kivy(root, nursery):
|
async def run_kivy(root, nursery):
|
||||||
'''Trio-kivy entry point.
|
'''Trio-kivy entry point.
|
||||||
'''
|
'''
|
||||||
|
@ -387,18 +388,22 @@ async def _async_main(name, tickers, brokermod, rate):
|
||||||
This is started with cli command `piker watch`.
|
This is started with cli command `piker watch`.
|
||||||
'''
|
'''
|
||||||
# setup ticker stream
|
# setup ticker stream
|
||||||
from ..brokers.core import StreamQueue
|
from ..brokers.core import Client
|
||||||
queue = StreamQueue(await trio.open_tcp_stream('127.0.0.1', 1616))
|
|
||||||
await queue.put((brokermod.name, tickers)) # initial request for symbols price streams
|
async def subscribe(client):
|
||||||
|
# initial request for symbols price streams
|
||||||
|
await client.send((brokermod.name, tickers))
|
||||||
|
|
||||||
|
async with Client(('127.0.0.1', 1616), subscribe) as client:
|
||||||
|
|
||||||
# get initial symbol data
|
# get initial symbol data
|
||||||
async with brokermod.get_client() as client:
|
async with brokermod.get_client() as bclient:
|
||||||
# get long term data including last days close price
|
# get long term data including last days close price
|
||||||
sd = await client.symbol_data(tickers)
|
sd = await bclient.symbol_data(tickers)
|
||||||
|
|
||||||
async with trio.open_nursery() as nursery:
|
async with trio.open_nursery() as nursery:
|
||||||
# get first quotes response
|
# get first quotes response
|
||||||
quotes = await queue.get()
|
quotes = await client.recv()
|
||||||
first_quotes = [
|
first_quotes = [
|
||||||
brokermod.format_quote(quote, symbol_data=sd)[0]
|
brokermod.format_quote(quote, symbol_data=sd)[0]
|
||||||
for quote in quotes.values()]
|
for quote in quotes.values()]
|
||||||
|
@ -459,4 +464,4 @@ async def _async_main(name, tickers, brokermod, rate):
|
||||||
}
|
}
|
||||||
nursery.start_soon(run_kivy, widgets['root'], nursery)
|
nursery.start_soon(run_kivy, widgets['root'], nursery)
|
||||||
nursery.start_soon(
|
nursery.start_soon(
|
||||||
update_quotes, nursery, brokermod, widgets, queue, sd, quotes)
|
update_quotes, nursery, brokermod, widgets, client, sd, quotes)
|
||||||
|
|
Loading…
Reference in New Issue