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

Rekt pps? problem? => piker.accounting #489

Merged
merged 294 commits into from
May 28, 2023
Merged

Rekt pps? problem? => piker.accounting #489

merged 294 commits into from
May 28, 2023

Conversation

goodboy
Copy link
Contributor

@goodboy goodboy commented Mar 10, 2023

Even moar fixes after #470, #475, #484 which mega broke the old
pps.toml management for live backend 💥 😶‍🌫️ 🤕

Turns out this might be the reason to start assaulting the revamp of
our accounting tooling as per our now long list of desirables:
accounting prolly positioning: the accounting of "what/when (is) owned"

Testing enhancements (some tasks deferred)

  • rework test set to use pytest.mark.parametrize so we can more
    easily use common harness logic for darks and alert testing.

  • reorg the ahab API docker supervisor endpoints to be decoupled
    from open_pikerd() and able to accept arbitrary config overrides for
    both testing and distributed setups.

  • dark order and alert clearing

  • add a basic accounting of position only test set?

tasks and bugs getting deferred..

dependency changes needed for this to land


Unrelated to .accounting changes

  • complete rework of .data._web_bs implementation to avoid the use
    of backend code using async generators within async context managers.
    • see 59743b7 and follow up commits
      • yeah probably should have broken this out into a separate PR but
        too many devs are too busy to review it rn so there's not a lot of
        point 😂

NEW SUBSYSTEM: the piker.accounting (subpkg) 🏄

  • move all .data._source and piker.pp mod contents into a much
    better organized subsystem API -> piker.accounting 🏄

    • ._mktinfo contains MktPair and Asset primitive as well as new
      .fqme acronym (fully qualified market endpoint) processing.
    • ._pos contains Position and PpTable loading and processing
    • ._ledger adds TransactionLedger and Transaction loading and
      sync.
    • .cli adds a ledger <broker>.<accountname> syncing prototype cli
      which can be used to dump position summaries to console.
  • try to see how many bullets we can nail from Positioning system refinements: paper engine, file writing, toml style and perf  #345

  • Prototype ledger cli using typer with follow up to come with Ledger (syncing) CLI and offline toolset #512

    • add typer and rich as deps!
  • Move our data feed layer to new MktPair market info struct as
    well as support a new "backend validation system" using
    the new .data.validate.FeedInit

    • we now expect stream_quotes() to deliver a pedantic list[FeedInit] on
      startup instead of a random dict of some schema 🏄

    • all backends should provide a get_mkt_info() endpoint now which
      does the work of constructing a MktPair from an input search
      pattern (str) and is also expected to construct the MktPair.src
      / .dst fields which in the ideal case are
      .accounting._mktinfo.Asset refs.

    • move all internal usage of the old Symbol type over to this as
      well as rename as much as we can of fqsn to the new fqme (fully
      qualified market endpoint)

      • data layer including Flume.symbol -> .mkt: MktPair
      • clearing engine
      • fsp engine
      • change Position.symbol -> .mkt
      • UI layers: _chart, _display _fsp.. etc.
      • Drop ui._chart.LinkedSplits.symbol outright and finally!
    • port all backends as much as is possible to this new interface

      • drop "good job" msg from .data.validate since it should be
        default now B)
      • kraken, ib for true full live support
      • binance, kucoin for read-onlys
        implementation, but i don't have a live feed..
      • make an issue for questrade? -> questrade: use ws api for live rt quotes #509
    • bring in backend checks from Brokercheck an all backends #393 and add to a test set for
      superficial audit of all broker/data providers.

      • ended up just tossing in warning log msgs to data.validate
        stuff and not sure we really need explicit test set?

Outstanding/Related issues/bugs that should be resolved here:


discovered BUGs tofix, issues likely to re-issued and defer, new feature ideas:


extra follow ToDos (birds with stones):

@goodboy
Copy link
Contributor Author

goodboy commented Apr 16, 2023

Lul, gotta drop that pytest_trio import..

goodboy added 14 commits May 9, 2023 14:49
To be compat with the `Symbol` (for now) and generally allow for reading
the (derivative) contract specific part of the fqme. Adjust
`contract_info: list[str]` and make `src: str = ''` by default.
Initial attempt at getting the sampling and shm layer to use the new mkt
info meta-data type. Draft out a potential `BackendInitMsg:
msgspec.Struct` for validating the init msg returned from the
`stream_quotes()` start value; obvs don't actually use it yet.
To make nested `msgspec.Struct`s work we need to tell the codec that the
`.symbol` is some struct def, since we don't really need to enforce that
(yet) we're just going to enc/dec as `str` until we further formalize
and/or need something more complex.
# TODO: instead see if we can hack tomli and tomli-w to do the same:
# - https://github.com/hukkin/tomli
# - https://github.com/hukkin/tomli-w
class PpsEncoder(toml.TomlEncoder):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entirely replaced by tomlkit

conf_path: Path
conf, conf_path = config.load_account(brokername, acctid)

if brokername in conf:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was originally for converting legacy account files: pps.toml but we can probably remove it in next patch set for this subsys.

@@ -439,6 +519,35 @@ async def get_ohlc(
yield get_ohlc, {'erlangs': 3, 'rate': 3}


@async_lifo_cache()
async def get_mkt_info(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the new required endpoint for all backends which delivers the MktPair (ideally with embedded .src/.dst attrs which are Assets) translation for any searched market/symbol/ticker pattern.

@@ -713,6 +771,98 @@ def normalize(
return data


@async_lifo_cache()
async def get_mkt_info(
Copy link
Contributor Author

@goodboy goodboy May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm the least happy with this implementation (in terms of existing backends) just because as a legacy market broker ib tends to assume a source asset for every exchange..

Ideally we can work toward getting this more refined going forward particularly if we're going to be re-doing our tsdb subsys backend choice(s) and don't have to rely on the table keys in the existing replicated data sets..

longer run i would like to see mnq/usd.cme.ib over no usd in the fqme.

# but likely we want all backends to eventually handle
# ``dst/src.venue.`` style !?
src: str | Asset = ''
if atype == 'forex':
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bleh, yeah we need some backend specific tests i think to be able to get this to the new proper fqme nomenclature i'm thinking...

@goodboy goodboy force-pushed the rekt_pps branch 3 times, most recently from c72b998 to 7011187 Compare May 26, 2023 20:21
@goodboy
Copy link
Contributor Author

goodboy commented May 28, 2023

Ok so as per discussion in dev chat I'm going to cowboy land this massive change set without extensive review bc,

  • there aren't enough core devs around to give it the attention rn
  • the bug fix creep got too big and would require a lot of commit factoring and sub-PRs to be made (which i don't really have the time or patience to go through rn 😂 ) along the scale of what happened in Multichartz #420 ..
  • there's enough critical backend stuff that was fixed and the new .accounting pkg is important enough to get on the main branch asap.
  • there is a test set which has caught pretty much all regressions and all such issues have been resolved.
  • everything else that wasn't finalized has been documented in follow up issues.
  • i've been using this code in production for weeks and am aware of any oustanding critical live trading problems.

Hopefully this won't happen again 😹

@goodboy goodboy merged commit e51ba40 into master May 28, 2023
2 checks passed
@goodboy goodboy deleted the rekt_pps branch May 28, 2023 19:41
@goodboy goodboy mentioned this pull request Jun 21, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accounting prolly positioning: the accounting of "what/when (is) owned" clearing auction and mm tech: EMS, OMS, algo-trading config data-layer real-time and historical data processing and storage ledger trade, accounts and other user focal event history tracking, management and storage nomenclature cross broker/venue/asset symbology, syntax and acronyms (sub-)systems general sw design and eng
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant