Use brokerd's client to get all contracts

kivy_mainline_and_py3.8
Tyler Goodlet 2019-02-09 21:58:27 -05:00
parent 395f0c8e4a
commit 3ab9e28ddb
1 changed files with 13 additions and 5 deletions

View File

@ -1,6 +1,5 @@
""" """
options: a real-time option chain. options: a real-time option chain.
Launch with ``piker options <symbol>``. Launch with ``piker options <symbol>``.
""" """
import types import types
@ -358,7 +357,9 @@ class OptionChain(object):
) )
# retreive all contracts to populate expiry row # retreive all contracts to populate expiry row
all_contracts = await contracts(self.feed.brokermod, symbol) all_contracts = await self.feed.call_client(
'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
@ -369,12 +370,18 @@ class OptionChain(object):
self.symbol, self.expiry = symbol, expiry self.symbol, self.expiry = symbol, expiry
return return
# XXX: Unfortunately we can't serialize named tuples over
# msgpack... The expiry index is 2, see the ``ContractsKey`` named
# tuple in the questrade broker mod. It would normally look
# something like:
# expiry = next(iter(all_contracts)).expiry if not expiry else expiry
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)).expiry if not expiry else expiry expiry = next(iter(all_contracts))[ei] if not expiry else expiry
# TODO: figure out how to compact these buttons # TODO: figure out how to compact these buttons
expiries = { expiries = {
key.expiry: key.expiry[:key.expiry.find('T')] key[ei]: key[ei][:key[ei].find('T')]
for key in all_contracts for key in all_contracts
} }
expiry_row = self.widgets['expiry_row'] expiry_row = self.widgets['expiry_row']
@ -500,6 +507,7 @@ async def _async_main(
# trio-kivy entry point. # trio-kivy entry point.
await async_runTouchApp(chain.widgets['root']) # run kivy await async_runTouchApp(chain.widgets['root']) # run kivy
finally: finally:
if chain._quote_gen:
await chain._quote_gen.aclose() await chain._quote_gen.aclose()
# cancel GUI update task # cancel GUI update task
nursery.cancel_scope.cancel() nursery.cancel_scope.cancel()