Fill in label with pairs from `status` value of backend init msg

ib_dedicated_data_client
Tyler Goodlet 2022-06-05 22:01:37 -04:00
parent 488506d8b8
commit 88eccc1e15
2 changed files with 31 additions and 23 deletions

View File

@ -46,6 +46,7 @@ import numpy as np
from ..brokers import get_brokermod from ..brokers import get_brokermod
from .._cacheables import maybe_open_context from .._cacheables import maybe_open_context
from ..calc import humanize
from ..log import get_logger, get_console_log from ..log import get_logger, get_console_log
from .._daemon import ( from .._daemon import (
maybe_spawn_brokerd, maybe_spawn_brokerd,
@ -1183,10 +1184,10 @@ class Feed:
shm: ShmArray shm: ShmArray
mod: ModuleType mod: ModuleType
first_quotes: dict # symbol names to first quote dicts first_quotes: dict # symbol names to first quote dicts
_portal: tractor.Portal _portal: tractor.Portal
stream: trio.abc.ReceiveChannel[dict[str, Any]] stream: trio.abc.ReceiveChannel[dict[str, Any]]
status: dict[str, Any]
throttle_rate: Optional[int] = None throttle_rate: Optional[int] = None
_trade_stream: Optional[AsyncIterator[dict[str, Any]]] = None _trade_stream: Optional[AsyncIterator[dict[str, Any]]] = None
@ -1327,9 +1328,24 @@ async def open_feed(
first_quotes=first_quotes, first_quotes=first_quotes,
stream=stream, stream=stream,
_portal=portal, _portal=portal,
status={},
throttle_rate=tick_throttle, throttle_rate=tick_throttle,
) )
# fill out "status info" that the UI can show
host, port = feed.portal.channel.raddr
if host == '127.0.0.1':
host = 'localhost'
feed.status.update({
'actor_name': feed.portal.channel.uid[0],
'host': host,
'port': port,
'shm': f'{humanize(feed.shm._shm.size)}',
'throttle_rate': feed.throttle_rate,
})
feed.status.update(init_msg.pop('status', {}))
for sym, data in init_msg.items(): for sym, data in init_msg.items():
si = data['symbol_info'] si = data['symbol_info']
fqsn = data['fqsn'] + f'.{brokername}' fqsn = data['fqsn'] + f'.{brokername}'

View File

@ -26,7 +26,7 @@ from typing import TYPE_CHECKING
# from PyQt5.QtCore import Qt # from PyQt5.QtCore import Qt
from ._style import _font, _font_small from ._style import _font, _font_small
from ..calc import humanize # from ..calc import humanize
from ._label import FormatLabel from ._label import FormatLabel
if TYPE_CHECKING: if TYPE_CHECKING:
@ -49,15 +49,21 @@ def mk_feed_label(
a feed control protocol. a feed control protocol.
''' '''
msg = """ status = feed.status
assert status
msg = dedent("""
actor: **{actor_name}**\n actor: **{actor_name}**\n
|_ @**{host}:{port}**\n |_ @**{host}:{port}**\n
|_ throttle_hz: **{throttle_rate}**\n """)
|_ shm: **{shm}**\n
""" for key, val in status.items():
if key in ('host', 'port', 'actor_name'):
continue
msg += f'\n|_ {key}: **{{{key}}}**\n'
feed_label = FormatLabel( feed_label = FormatLabel(
fmt_str=dedent(msg), fmt_str=msg,
# |_ streams: **{symbols}**\n # |_ streams: **{symbols}**\n
font=_font.font, font=_font.font,
font_size=_font_small.px_size, font_size=_font_small.px_size,
@ -72,20 +78,6 @@ def mk_feed_label(
# feed_label.height() # feed_label.height()
) )
# fill in brokerd feed info feed_label.format(**feed.status)
host, port = feed.portal.channel.raddr
if host == '127.0.0.1':
host = 'localhost'
mpshm = feed.shm._shm
shmstr = f'{humanize(mpshm.size)}'
feed_label.format(
actor_name=feed.portal.channel.uid[0],
host=host,
port=port,
# symbols=len(feed.symbols),
shm=shmstr,
throttle_rate=feed.throttle_rate,
)
return feed_label return feed_label