Skip to content

Commit

Permalink
First draft, working WS based order management
Browse files Browse the repository at this point in the history
Move to using the websocket API for all order control ops and dropping
the sync rest api approach which resulted in a bunch of buggy races.
Further this gets us must faster (batch) order cancellation for free
and a simpler ems request handler loop. We now heavily leverage the new
py3.10 `match:` syntax for all kraken-side API msg parsing and
processing and handle both the `openOrders` and `ownTrades` subscription
streams.

We also block "order editing" (by immediate cancellation) for now since
the EMS isn't entirely yet equipped to handle brokerd side `.reqid`
changes (which is how kraken implements so called order "updates" or
"edits") for a given order-request dialog and we may want to even
consider just implementing "updates" ourselves via independent cancel
and submit requests? Definitely something to ponder. Alternatively we
can "masquerade" such updates behind the count-style `.oid` remapping we
had to implement anyway (kraken's limitation) and maybe everything will
just work?

Further details in this patch:
- create 2 tables for tracking the EMS's `.oid` (uui4) value to `int`s
  that kraken expects (for `reqid`s): `ids` and `reqmsgs` which enable
  local lookup of ems uids to piker-backend-client-side request ids and
  received order messages.
- add `openOrders` sub support which more or less directly relays to
  equivalent `BrokerdStatus` updates and calc the `.filled` and
  `.remaining` values based on cleared vlm updates.
- add handler blocks for `[add/edit/cancel]OrderStatus` events including
  error msg cases.
- don't do any order request response processing in
  `handle_order_requests()` since responses are always received via one
  (or both?) of the new ws subs: `ownTrades` and `openOrders` and thus
  such msgs are now handled in the response relay loop.

Relates to #290
Resolves #310, #296
  • Loading branch information
goodboy committed Jul 21, 2022
1 parent c6edb9a commit 31f35a2
Show file tree
Hide file tree
Showing 2 changed files with 319 additions and 139 deletions.
1 change: 1 addition & 0 deletions piker/brokers/kraken/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ async def submit_limit(
"volume": str(size),
}
return await self.endpoint('AddOrder', data)

else:
# Edit order data for kraken api
data["txid"] = reqid
Expand Down
Loading

0 comments on commit 31f35a2

Please sign in to comment.