Drop internal nursery from option chain

kivy_mainline_and_py3.8
Tyler Goodlet 2019-02-21 23:07:44 -05:00
parent 462c419970
commit cbb973ae9d
1 changed files with 13 additions and 19 deletions

View File

@ -16,7 +16,6 @@ from kivy.core.window import Window
from kivy.uix.label import Label from kivy.uix.label import Label
from ..log import get_logger from ..log import get_logger
from ..brokers.core import contracts
from ..brokers.data import DataFeed from ..brokers.data import DataFeed
from .pager import PagerView from .pager import PagerView
@ -155,6 +154,8 @@ async def find_local_monitor():
if not portal: if not portal:
log.warn( log.warn(
"No monitor app could be found, no symbol link established..") "No monitor app could be found, no symbol link established..")
else:
log.info(f"Found {portal.channel.uid}")
yield portal yield portal
@ -172,6 +173,7 @@ class OptionChain(object):
): ):
self.symbol = None self.symbol = None
self.expiry = None self.expiry = None
self.rate = rate
self.widgets = widgets self.widgets = widgets
self.bidasks = bidasks self.bidasks = bidasks
self._strikes2rows = {} self._strikes2rows = {}
@ -212,9 +214,7 @@ class OptionChain(object):
"""Open an internal update task scope required to allow """Open an internal update task scope required to allow
for dynamic real-time operation. for dynamic real-time operation.
""" """
self._parent_nursery = nursery n = self._nursery = nursery
async with trio.open_nursery() as n:
self._nursery = n
# fill out and start updating strike table # fill out and start updating strike table
n.start_soon( n.start_soon(
partial(self._start_displaying, symbol, expiry=expiry) partial(self._start_displaying, symbol, expiry=expiry)
@ -222,7 +222,6 @@ class OptionChain(object):
# listen for undlerlying symbol changes from a local monitor app # listen for undlerlying symbol changes from a local monitor app
n.start_soon(self._rx_symbols) n.start_soon(self._rx_symbols)
yield self yield self
n.cancel_scope.cancel()
self._nursery = None self._nursery = None
# make sure we always tear down our existing data feed # make sure we always tear down our existing data feed
@ -346,9 +345,6 @@ class OptionChain(object):
self._update_cs.cancel() self._update_cs.cancel()
await trio.sleep(0) await trio.sleep(0)
if self._quote_gen:
await self._quote_gen.aclose()
# redraw any symbol specific UI components # redraw any symbol specific UI components
if self.symbol != symbol or expiry is None: if self.symbol != symbol or expiry is None:
# set window title # set window title
@ -359,7 +355,6 @@ class OptionChain(object):
# retreive all contracts to populate expiry row # retreive all contracts to populate expiry row
all_contracts = await self.feed.call_client( all_contracts = await self.feed.call_client(
'get_all_contracts', symbols=[symbol]) 'get_all_contracts', symbols=[symbol])
# all_contracts = await contracts(self.feed.brokermod, symbol)
if not all_contracts: if not all_contracts:
label = self.no_opts_label label = self.no_opts_label
@ -374,7 +369,7 @@ class OptionChain(object):
# msgpack... The expiry index is 2, see the ``ContractsKey`` named # msgpack... The expiry index is 2, see the ``ContractsKey`` named
# tuple in the questrade broker mod. It would normally look # tuple in the questrade broker mod. It would normally look
# something like: # something like:
# expiry = next(iter(all_contracts)).expiry if not expiry else expiry # exp = next(iter(all_contracts)).expiry if not exp else exp
ei = 2 ei = 2
# start streaming soonest contract by default if not provided # start streaming soonest contract by default if not provided
expiry = next(iter(all_contracts))[ei] if not expiry else expiry expiry = next(iter(all_contracts))[ei] if not expiry else expiry
@ -401,6 +396,7 @@ class OptionChain(object):
self._quote_gen, first_quotes = await self.feed.open_stream( self._quote_gen, first_quotes = await self.feed.open_stream(
[(symbol, expiry)], [(symbol, expiry)],
'option', 'option',
rate=self.rate,
) )
log.debug(f"Got first_quotes for {symbol}:{expiry}") log.debug(f"Got first_quotes for {symbol}:{expiry}")
records, displayables = self.feed.format_quotes(first_quotes) records, displayables = self.feed.format_quotes(first_quotes)
@ -443,7 +439,6 @@ async def new_chain_ui(
portal: tractor._portal.Portal, portal: tractor._portal.Portal,
symbol: str, symbol: str,
brokermod: types.ModuleType, brokermod: types.ModuleType,
nursery: trio._core._run.Nursery,
rate: int = 1, rate: int = 1,
) -> None: ) -> None:
"""Create and return a new option chain UI. """Create and return a new option chain UI.
@ -499,7 +494,6 @@ async def _async_main(
portal, portal,
symbol, symbol,
brokermod, brokermod,
nursery,
rate=rate, rate=rate,
) )
async with chain.open_rt_display(nursery, symbol): async with chain.open_rt_display(nursery, symbol):