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

View File

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