Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PpTables #361

Merged
merged 6 commits into from
Jul 21, 2022
Merged

PpTables #361

merged 6 commits into from
Jul 21, 2022

Conversation

goodboy
Copy link
Contributor

@goodboy goodboy commented Jul 21, 2022

Reworks the piker.pp apis to include a new open_pps() context manager which delivers a PpTable, a type that allows real-time incremental management of position updates from backend transaction records.

This more or less deprecates the previous update_pps_conf() routine.


In follow up,

both moved to #345.
- [ ] we should add support for immediate config file (ledger or pps.toml) writing likely via the trio async file IO apis which use a bg thread to avoid main thread latency.
- [ ] probably adjust the PpTable.dump_active() output to be the open and closed Position object dicts and have a seperate method which generates the toml-ready "entries" dict for the pps.toml?

@goodboy goodboy requested review from guilledk and iamzoltan July 21, 2022 16:09
guilledk
guilledk previously approved these changes Jul 21, 2022
Base automatically changed from fix_forex to master July 21, 2022 21:52
goodboy added 6 commits July 21, 2022 17:52
In an effort to begin allowing backends to have more granular control
over position updates, particular in the case where they need to be
reloaded from a trades ledger, this adds a new table API which can
be loaded using `open_pps()`.

- offer an `.update_trans()` method which takes in a `dict` of
  `Transactions` and updates the current table of `Positions` from it.
- add a `.dump_active()` which renders the active pp entries dict in
  a format ready for toml serialization and all closed positions since
  the last update (we might want to not drop these?)

All other module-function apis currently in use should remain working as
before for the moment.
In order to avoid double transaction adds/updates and too-early-discard
of zero sized pps (like when trades are loaded from a backend broker but
were already added to a ledger or `pps.toml` prior) we now **don't** pop
such `Position` entries from the `.pps` table in order to keep each
position's clears table always in place. This avoids the edge case where
an entry was removed too early (due to zero size) but then duplicate
trade entries that were in that entrie's clears show up from the backend
and are entered into a new entry resulting in an incorrect size in a new
entry..We still only push non-net-zero entries to the `pps.toml`.

More fixes:
- return the updated set of `Positions` from `.lifo_update()`.
- return the full table set from `update_pps()`.
- use `PpTable.update_from_trans()` more throughout.
- always write the `pps.toml` on `open_pps()` exit.
- only return table from `load_pps_from_toml()`.
Can't believe i missed this but any `return` inside a `finally` will
suppress the error from the `try:` part... XD

Thought i was losing my mind when the ledger was mutated and then
an error just after wasn't getting raised.. lul.

Never again...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants