Use `force_mkt` override in paper pps updates
When processing paper trades ledgers we normally won't have specific `MktPair` info for the backend market we're simulating, as such we need to look up this info when updating pps.toml files such that we get precision info correct (particularly in the case of cryptos!) and can also run paper ledger processing without running the simulated clearing loop. In order to make it happen we lookup any `get_mkt_info()` ep on the backend and pass the output to the `force_mkt` input of the `PpTable.update_from_trans()` method.rekt_pps
parent
83514b0e90
commit
55b4866d5e
|
@ -504,7 +504,7 @@ class PpTable(Struct):
|
|||
trans: dict[str, Transaction],
|
||||
cost_scalar: float = 2,
|
||||
|
||||
mkt: MktPair | None = None,
|
||||
force_mkt: MktPair | None = None,
|
||||
|
||||
) -> dict[str, Position]:
|
||||
|
||||
|
@ -523,7 +523,7 @@ class PpTable(Struct):
|
|||
|
||||
# template the mkt-info presuming a legacy market ticks
|
||||
# if no info exists in the transactions..
|
||||
mkt: MktPair | Symbol | None = mkt or t.sys
|
||||
mkt: MktPair | Symbol | None = force_mkt or t.sys
|
||||
if not mkt:
|
||||
mkt = MktPair.from_fqme(
|
||||
fqme,
|
||||
|
|
|
@ -34,9 +34,13 @@ import pendulum
|
|||
import trio
|
||||
import tractor
|
||||
|
||||
from ..brokers import get_brokermod
|
||||
from .. import data
|
||||
from ..data.types import Struct
|
||||
from ..accounting._mktinfo import Symbol
|
||||
from ..accounting._mktinfo import (
|
||||
Symbol,
|
||||
MktPair,
|
||||
)
|
||||
from ..accounting import (
|
||||
Position,
|
||||
PpTable,
|
||||
|
@ -545,8 +549,31 @@ async def trades_dialogue(
|
|||
'paper',
|
||||
) as ledger
|
||||
):
|
||||
# attempt to get market info from the backend instead of presuming
|
||||
# the ledger entries have everything correct.
|
||||
# TODO: how to process ledger info from backends?
|
||||
# - should we be rolling our own actor-cached version of these
|
||||
# client API refs or using portal IPC to send requests to the
|
||||
# existing brokerd daemon?
|
||||
# - alternatively we can possibly expect and use
|
||||
# a `.broker.norm_trade_records()` ep?
|
||||
mkt: MktPair | None = None
|
||||
brokermod = get_brokermod(broker)
|
||||
gmi = getattr(brokermod, 'get_mkt_info', None)
|
||||
if gmi:
|
||||
mkt, pair = await brokermod.get_mkt_info(
|
||||
fqme.rstrip(f'.{broker}'),
|
||||
)
|
||||
|
||||
# update pos table from ledger history
|
||||
ppt.update_from_trans(ledger.to_trans())
|
||||
ppt.update_from_trans(
|
||||
ledger.to_trans(),
|
||||
|
||||
# NOTE: here we pass in any `MktPair` provided by the
|
||||
# backend broker instead of assuming the pps.toml contains
|
||||
# the correct contents!
|
||||
force_mkt=mkt
|
||||
)
|
||||
|
||||
pp_msgs: list[BrokerdPosition] = []
|
||||
pos: Position
|
||||
|
|
Loading…
Reference in New Issue