Specify bid-ask "stacked" cells by argument

kivy_mainline_and_py3.8
Tyler Goodlet 2018-03-20 21:20:55 -04:00
parent 6c0f1fbdfc
commit f0149118e1
1 changed files with 17 additions and 11 deletions

View File

@ -21,6 +21,7 @@ from kivy.core.window import Window
from ..calc import humanize, percent_change from ..calc import humanize, percent_change
from ..log import get_logger from ..log import get_logger
from .pager import PagerView from .pager import PagerView
from ..brokers.core import poll_tickers
log = get_logger('watchlist') log = get_logger('watchlist')
@ -266,7 +267,7 @@ class Row(GridLayout):
turn adjust the text color of the values based on content changes. turn adjust the text color of the values based on content changes.
""" """
def __init__( def __init__(
self, record, headers=(), table=None, is_header_row=False, self, record, headers=(), bidasks=None, table=None, is_header_row=False,
**kwargs **kwargs
): ):
super(Row, self).__init__(cols=len(record), **kwargs) super(Row, self).__init__(cols=len(record), **kwargs)
@ -276,13 +277,9 @@ class Row(GridLayout):
self.is_header = is_header_row self.is_header = is_header_row
# create `BidAskCells` first # create `BidAskCells` first
bidasks = {
'last': ['bid', 'ask'],
'size': ['bsize', 'asize'],
'VWAP': ['low', 'high'],
}
ba_cells = {}
layouts = {} layouts = {}
bidasks = bidasks or {}
ba_cells = {}
for key, children in bidasks.items(): for key, children in bidasks.items():
layout = BidAskLayout( layout = BidAskLayout(
[record[key]] + [record[child] for child in children], [record[key]] + [record[child] for child in children],
@ -356,10 +353,10 @@ class TickerTable(GridLayout):
# for tracking last clicked column header cell # for tracking last clicked column header cell
self.last_clicked_col_cell = None self.last_clicked_col_cell = None
def append_row(self, record): def append_row(self, record, bidasks=None):
"""Append a `Row` of `Cell` objects to this table. """Append a `Row` of `Cell` objects to this table.
""" """
row = Row(record, headers=('symbol',), table=self) row = Row(record, headers=('symbol',), bidasks=bidasks, table=self)
# store ref to each row # store ref to each row
self.symbols2rows[row._last_record['symbol']] = row self.symbols2rows[row._last_record['symbol']] = row
self.add_widget(row) self.add_widget(row)
@ -467,7 +464,8 @@ async def _async_main(name, tickers, brokermod):
# get long term data including last days close price # get long term data including last days close price
sd = await client.symbols(tickers) sd = await client.symbols(tickers)
nursery.start_soon(brokermod.poll_tickers, client, tickers, queue) nursery.start_soon(
poll_tickers, client, brokermod.quoter, tickers, queue)
# get first quotes response # get first quotes response
pkts = await queue.get() pkts = await queue.get()
@ -485,11 +483,19 @@ async def _async_main(name, tickers, brokermod):
Builder.load_string(_kv) Builder.load_string(_kv)
box = BoxLayout(orientation='vertical', padding=5, spacing=5) box = BoxLayout(orientation='vertical', padding=5, spacing=5)
# define bid-ask "stacked" cells
bidasks = {
'last': ['bid', 'ask'],
'size': ['bsize', 'asize'],
'VWAP': ['low', 'high'],
}
# add header row # add header row
headers = first_quotes[0].keys() headers = first_quotes[0].keys()
header = Row( header = Row(
{key: key for key in headers}, {key: key for key in headers},
headers=headers, headers=headers,
bidasks=bidasks,
is_header_row=True, is_header_row=True,
size_hint=(1, None), size_hint=(1, None),
) )
@ -501,7 +507,7 @@ async def _async_main(name, tickers, brokermod):
size_hint=(1, None), size_hint=(1, None),
) )
for ticker_record in first_quotes: for ticker_record in first_quotes:
grid.append_row(ticker_record) grid.append_row(ticker_record, bidasks=bidasks)
# associate the col headers row with the ticker table even though # associate the col headers row with the ticker table even though
# they're technically wrapped separately in containing BoxLayout # they're technically wrapped separately in containing BoxLayout
header.table = grid header.table = grid