Add real-time pnl calc and display in status pane

fsp_feeds
Tyler Goodlet 2021-08-27 16:38:06 -04:00
parent fb4354d629
commit 8c7e4c0ce9
2 changed files with 23 additions and 6 deletions

View File

@ -41,6 +41,7 @@ from .._daemon import (
maybe_spawn_brokerd,
)
from ..brokers import get_brokermod
from ..calc import percent_change
from ._axes import (
DynamicDateAxis,
PriceAxis,
@ -67,6 +68,7 @@ from ..data import maybe_open_shm_array
from ..data.feed import open_feed, Feed, install_brokerd_search
from ..data._source import Symbol
from ..data._sharedmem import ShmArray
from ..data._normalize import iterticks
from .. import brokers
from ..log import get_logger
from ._exec import run_qtractor
@ -1848,6 +1850,15 @@ async def display_symbol_data(
pp = order_mode.pp
live = pp.live_pp
if live.size < 0:
types = ('ask', 'last')
elif live.size > 0:
types = ('bid', 'last')
else:
raise RuntimeError('No pp?!?!')
# real-time update pnl on the order mode
async with feed.stream.subscribe() as bstream:
last_tick = time.time()
@ -1858,13 +1869,19 @@ async def display_symbol_data(
for sym, quote in quotes.items():
ticks = quote.get('ticks', ())
if ticks:
for tick in iterticks(quote, types):
print(f'{1/period} Hz')
if live.size:
# compute and display pnl
pass
# compute and display pnl status
order_mode.pane.pnl_label.format(
pnl=round(
live.size * percent_change(
live.avg_price,
tick['price'],
),
ndigits=2,
)
)
last_tick = time.time()

View File

@ -547,7 +547,7 @@ def mk_fill_status_bar(
bar_labels_lhs = QVBoxLayout(fields)
left_label = fields.add_field_label(
dedent("""
{pnl}% PnL
{pnl}% pnl
"""),
font_size=bar_label_font_size,
font_color='gunmetal',