how_to_show_ur_pp: fixes for end-2-end order/position display #60

Merged
goodboy merged 11 commits from how_to_show_ur_pp into main 2026-01-07 19:32:55 +00:00

Since apparently we can’t (yet) rely on our fqme (fully-qualified-market-endpoint)as consistent, e2e uniquely matchable keys for various brokerd -> emsd -> chartd event relaying, namely bc (at least from the .brokers.ib backend..) the venue-token-part can change depending on,

  • where the order was cleared, possibly on multiple (sub-)venues which are not the primary listing venue.
  • how cleared orders are recorded in the broker backend’s blotter/ledger normally by time but with a varying venue field.
  • depending on piker’s txn-ledger processing (again normally sorted by record time stamp) the last venue is likely not the primary; the fqme might not match that of the data feed’s MktPair.fqme.

This problems becomes most obvious with our chart-trading UX where position markers/annotations might not be displayed on the correct live time-series view due to such a mismatch of MktPair.fqme -> BrokerPosition.fmqe.

So instead (at least for now) just always relay through the broker’s own unique-mkt-ID schema (what we dub the bs_mktid: backend-sys market ID) on a new (5b91b089) BrokerdPosition.bs_mktid field to guarantee consistency at least on a per-broker reporting basis.

Obviously ensure we always set it for .ib emitted pp msgs (58654915) and ensure the .ui.order_mode prioritize the mkt-match on .bs_mktid (388a9a4d).


Related/surrounding broker txn ledger improvements

  • (b6d70d50, 7b68444c) track and ignore any txn entries with invalid time-stamps (again such as can be recorded by the .ib backend..) by refining the .accounting.calc.iter_by_dt() impl with a handy _invalid: list passed to the embedded dyn_parse_to_dt() closure which allows us to either,

    • crash-handle such cases when a new debug: bool param is set OR,
    • at the least log.error() such txns to console.
  • d67ace75 avoid overriding Account.pps: dict entries by again using a bs_mktid to uniquely key Position entries in .accounting._pos.open_account() as delivered by Account.pps.

  • 0e9b50de _ems: tolerate and warn on already popped execs,

    such that we never crash on a status_msg > = book._active.pop(oid) in the ‘closed’ status handler whenever a double removal happens.

  • c609858f ui._remote_ctl: shield remote rect removals

    Since under trio-cancellation the .remove() is a checkpoint

  • f5850fe5 draft a ems/txn-ledger test which needs to eventually have checks on an example ledger file ensuring a position cleared over multiple venues (and thus currently mapping over multiple .fqme keys in its txn set) renders to a single, unified and correct position measure/report.

Since apparently we can't (yet) rely on our fqme (fully-qualified-market-endpoint)as consistent, e2e uniquely matchable keys for various `brokerd` -> `emsd` -> `chartd` event relaying, namely bc (at least from the `.brokers.ib` backend..) the venue-token-part can change depending on, - where the order was cleared, possibly on multiple (sub-)venues which are **not the primary** listing venue. - how cleared orders are recorded in the broker backend's blotter/ledger normally by time but with a varying venue field. - depending on `piker`'s txn-ledger processing (again normally sorted by record time stamp) the last venue is likely not the *primary*; the fqme might not match that of the data feed's `MktPair.fqme`. This problems becomes most obvious with our chart-trading UX where position markers/annotations might not be displayed on the correct live time-series view due to such a mismatch of `MktPair.fqme` -> `BrokerPosition.fmqe`. So instead (at least for now) just always relay through the broker's own unique-mkt-ID schema (what we dub the `bs_mktid`: backend-sys market ID) on a new (5b91b089) `BrokerdPosition.bs_mktid` field to guarantee consistency at least on a per-broker reporting basis. Obviously ensure we always set it for `.ib` emitted pp msgs (58654915) and ensure the `.ui.order_mode` prioritize the mkt-match on `.bs_mktid` (388a9a4d). --- #### Related/surrounding broker txn ledger improvements - (b6d70d50, 7b68444c) track and ignore any txn entries with invalid time-stamps (again such as can be recorded by the `.ib` backend..) by refining the `.accounting.calc.iter_by_dt()` impl with a handy `_invalid: list` passed to the embedded `dyn_parse_to_dt()` closure which allows us to either, - crash-handle such cases when a new `debug: bool` param is set OR, - at the least `log.error()` such txns to console. - d67ace75 avoid overriding `Account.pps: dict` entries by again using a `bs_mktid` to uniquely key `Position` entries in `.accounting._pos.open_account()` as delivered by `Account.pps`. - 0e9b50de `_ems`: tolerate and warn on already popped execs, > such that we never crash on a `status_msg > = book._active.pop(oid)` > in the 'closed' status handler whenever a double removal happens. - c609858f `ui._remote_ctl`: shield remote rect removals > Since under `trio`-cancellation the `.remove()` is a checkpoint - f5850fe5 draft a ems/txn-ledger test which needs to eventually have checks on an example ledger file ensuring a position cleared over multiple venues (and thus currently mapping over multiple `.fqme` keys in its txn set) renders to a single, unified and correct position measure/report. * hopefully i won't forget about actually finishing this suite in follow-up with https://www.pikers.dev/pikers/piker/issues/61 !!
goodboy force-pushed how_to_show_ur_pp from 7c11bdb859 to 58654915ac 2026-01-07 18:41:28 +00:00 Compare
goodboy added 1 commit 2026-01-07 19:22:04 +00:00
7b68444c7a accounting.calc: `.error()` on bad txn-time fields..
Since i'm seeing IB records with a `None` value and i don't want to be
debugging every time order-mode boots up..

Also use `pdb=debug` in `.open_ledger_dfs()`

Note, this had conflicts on `piker/accounting/calc.py` when rebasing
onto the refactored `brokers_refinery` history which were resolved
manually!
goodboy merged commit 9e82a46c0b into main 2026-01-07 19:32:55 +00:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: pikers/piker#60
There is no content yet.