Work when only newly time stamped quotes are received
parent
b7b7abbc1f
commit
1bbf212ad0
|
@ -45,6 +45,7 @@ _kv = (f'''
|
||||||
text_size: self.size
|
text_size: self.size
|
||||||
size: self.texture_size
|
size: self.texture_size
|
||||||
font_size: '20'
|
font_size: '20'
|
||||||
|
color: {colorcode('gray')}
|
||||||
# size_hint_y: None
|
# size_hint_y: None
|
||||||
font_color: {colorcode('gray')}
|
font_color: {colorcode('gray')}
|
||||||
font_name: 'Roboto-Regular'
|
font_name: 'Roboto-Regular'
|
||||||
|
@ -62,9 +63,9 @@ _kv = (f'''
|
||||||
size: self.size
|
size: self.size
|
||||||
|
|
||||||
<HeaderCell>
|
<HeaderCell>
|
||||||
bold: True
|
# bold: True
|
||||||
font_size: '20'
|
font_size: '20'
|
||||||
background_color: 0,0,0,0
|
background_color: [0]*4
|
||||||
canvas.before:
|
canvas.before:
|
||||||
Color:
|
Color:
|
||||||
rgb: [0.13]*4
|
rgb: [0.13]*4
|
||||||
|
@ -288,7 +289,7 @@ async def update_quotes(
|
||||||
elif daychange > 0.:
|
elif daychange > 0.:
|
||||||
color = colorcode('forestgreen')
|
color = colorcode('forestgreen')
|
||||||
else:
|
else:
|
||||||
color = colorcode('darkgray')
|
color = colorcode('gray')
|
||||||
|
|
||||||
chngcell.color = hdrcell.color = color
|
chngcell.color = hdrcell.color = color
|
||||||
|
|
||||||
|
@ -296,23 +297,25 @@ async def update_quotes(
|
||||||
if hdrcell.background_color != [0]*4:
|
if hdrcell.background_color != [0]*4:
|
||||||
hdrcell.background_color != color
|
hdrcell.background_color != color
|
||||||
|
|
||||||
|
cache = {}
|
||||||
|
|
||||||
# initial coloring
|
# initial coloring
|
||||||
syms2rows = {}
|
|
||||||
for quote in first_quotes:
|
for quote in first_quotes:
|
||||||
sym = quote['symbol']
|
sym = quote['symbol']
|
||||||
row = grid.symbols2rows[sym]
|
row = grid.symbols2rows[sym]
|
||||||
syms2rows[sym] = row
|
data, _ = qtconvert(quote, symbol_data=symbol_data)
|
||||||
color_row(row, quote)
|
color_row(row, data)
|
||||||
|
cache[sym] = (data, row)
|
||||||
|
|
||||||
# the core cell update loop
|
# the core cell update loop
|
||||||
while True:
|
while True:
|
||||||
log.debug("Waiting on quotes")
|
log.debug("Waiting on quotes")
|
||||||
quotes = await queue.get()
|
quotes = await queue.get()
|
||||||
datas = []
|
|
||||||
for quote in quotes:
|
for quote in quotes:
|
||||||
data, displayable = qtconvert(quote, symbol_data=symbol_data)
|
data, displayable = qtconvert(quote, symbol_data=symbol_data)
|
||||||
row = grid.symbols2rows[data['symbol']]
|
row = grid.symbols2rows[data['symbol']]
|
||||||
datas.append((data, row))
|
# only updates newly timestamped quotes
|
||||||
|
cache[data['symbol']] = (data, row)
|
||||||
|
|
||||||
# color changed field values
|
# color changed field values
|
||||||
for key, val in data.items():
|
for key, val in data.items():
|
||||||
|
@ -334,8 +337,8 @@ async def update_quotes(
|
||||||
# sort rows by daily % change since open
|
# sort rows by daily % change since open
|
||||||
grid.clear_widgets()
|
grid.clear_widgets()
|
||||||
sort_key = grid.sort_key
|
sort_key = grid.sort_key
|
||||||
for i, (data, row) in enumerate(
|
for data, row in reversed(
|
||||||
reversed(sorted(datas, key=lambda item: item[0][sort_key]))
|
sorted(cache.values(), key=lambda item: item[0][sort_key])
|
||||||
):
|
):
|
||||||
grid.add_widget(row) # row append
|
grid.add_widget(row) # row append
|
||||||
|
|
||||||
|
@ -411,4 +414,4 @@ async def _async_main(name, watchlists, brokermod):
|
||||||
}
|
}
|
||||||
|
|
||||||
nursery.start_soon(run_kivy, widgets['root'], nursery)
|
nursery.start_soon(run_kivy, widgets['root'], nursery)
|
||||||
nursery.start_soon(update_quotes, widgets, queue, sd, first_quotes)
|
nursery.start_soon(update_quotes, widgets, queue, sd, pkts)
|
||||||
|
|
Loading…
Reference in New Issue