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

Kraken ws orders #349

Merged
merged 50 commits into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
00378c3
First draft, working WS based order management
goodboy Jul 5, 2022
f79d986
Use `match:` syntax in data feed subs processing
goodboy Jul 5, 2022
ab08dc5
Make ems relay loop report on brokerd `.reqid` changes
goodboy Jul 5, 2022
df4cec9
Get order "editing" working fully
goodboy Jul 5, 2022
84cab13
Drop uneeded count-sequencec verification
goodboy Jul 5, 2022
d9b4c4a
Factor msg loop into new func: `handle_order_updates()`
goodboy Jul 5, 2022
9fa9c27
Factor status handling into a new `process_status()` helper
goodboy Jul 5, 2022
bbcc55b
Update ledger *after* pps updates from new trades
goodboy Jul 5, 2022
8ab8268
Don't require an ems msg symbol on error statuses
goodboy Jul 5, 2022
bb2f8e4
Try out a backend readme
goodboy Jul 5, 2022
89bcaed
Add ledger and `pps.toml` snippets
goodboy Jul 5, 2022
804e9af
Pass our manually mapped `reqid: int` to EMS
goodboy Jul 8, 2022
ba93f96
Lol, gotta `float()` that vlm before `*` XD
goodboy Jul 7, 2022
a20a8d9
Use `aclosing()` around ws async gen
goodboy Jul 8, 2022
caecbaa
Cancel any live orders found on connect
goodboy Jul 9, 2022
b0d3d9b
TOSQUASH: lingering `.dict()`s
goodboy Jul 9, 2022
5dc9a61
Use cancel level logging for cancelled orders
goodboy Jul 10, 2022
57f2478
Fixes for state updates and clears
goodboy Jul 10, 2022
22f9b25
Provide symbol norming via a classmethod + global table
goodboy Jul 10, 2022
abb6854
Make all `.bsuid`s the normed symbol "altname"s
goodboy Jul 11, 2022
5b135fa
Handle pre-existing open orders specifically by checking for null `oid`
goodboy Jul 13, 2022
2386270
Handle too-fast-edits, add `ChainMap` msg tracing
goodboy Jul 13, 2022
0fca1b3
Also map the ws symbol set to the alt set
goodboy Jul 14, 2022
b96b7a8
Use `aclosing()` on all msg async-gens
goodboy Jul 15, 2022
54008a1
Add balance and assets retreival methods, cache assets on startup
goodboy Jul 18, 2022
3b79743
Finally get real-time pp updates workin for `kraken`
goodboy Jul 19, 2022
64f920d
Accept direct fqsn matches on position msg updates
goodboy Jul 19, 2022
319e68c
TOSQUASH: revert to 22Hz display throttle
goodboy Jul 19, 2022
aa7f24b
Drop old reversed order idea for rt-pp msg testing
goodboy Jul 19, 2022
b1419c8
Update ledger from api immediately, cruft cleaning
goodboy Jul 19, 2022
d502274
Add a `Client.get_xfers()` to retreive withdrawal transactions
goodboy Jul 22, 2022
8b609f5
Add transfers knowledge to positions validation
goodboy Jul 22, 2022
0fb3158
Go back to using `Position.size` property in pp loading audits
goodboy Jul 25, 2022
168c986
Look for transfers after ledger + api trans load
goodboy Jul 26, 2022
d43ba47
Renames to `ppu`
goodboy Jul 27, 2022
e6a3e8b
Add warning msg for `openOrders.userref` always being 0
goodboy Jul 29, 2022
db564d7
Add casting method to our struct variant
goodboy Jul 30, 2022
b3058b8
Drop remaining `pydantic` usage, convert `OHLC` to our struct variant
goodboy Jul 30, 2022
44e21b1
Drop field import
goodboy Jul 30, 2022
808dbb1
Drop forgotten `pydantic` dataclass in binance backend..
goodboy Jul 31, 2022
dc8072c
WIP: use `userref` field over `reqid`...
goodboy Jul 29, 2022
227a804
Use both `reqid` and `userref` in order requests
goodboy Jul 30, 2022
1cbf45b
Use the ``newuserref`` field on order edits
goodboy Jul 31, 2022
7f3f7f0
Merge pull request #370 from pikers/kill_pydantic_from_kraken
goodboy Jul 31, 2022
69e5017
Drop status event processing at large
goodboy Aug 1, 2022
1a29193
Drop subs ack handling from streamer
goodboy Aug 1, 2022
30bcfdc
Emit fills from `openOrders` block
goodboy Aug 1, 2022
ef5829a
Merge pull request #368 from pikers/kraken_userref_hackzin
goodboy Aug 3, 2022
d280a59
Repair normalize method logic to only error on lookup failure
goodboy Aug 5, 2022
3a0987e
Fix to-fast-edit guard case
goodboy Aug 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions piker/brokers/binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from fuzzywuzzy import process as fuzzy
import numpy as np
import tractor
from pydantic.dataclasses import dataclass
import wsproto

from .._cacheables import open_cached_client
Expand Down Expand Up @@ -106,14 +105,14 @@ class Pair(Struct, frozen=True):
permissions: list[str]


@dataclass
class OHLC:
"""Description of the flattened OHLC quote format.
class OHLC(Struct):
'''
Description of the flattened OHLC quote format.

For schema details see:
https://binance-docs.github.io/apidocs/spot/en/#kline-candlestick-streams

"""
'''
time: int

open: float
Expand Down Expand Up @@ -262,6 +261,7 @@ async def bars(
for i, bar in enumerate(bars):

bar = OHLC(*bar)
bar.typecast()

row = []
for j, (name, ftype) in enumerate(_ohlc_dtype[1:]):
Expand Down
64 changes: 64 additions & 0 deletions piker/brokers/kraken/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
``kraken`` backend
------------------
though they don't have the most liquidity of all the cexes they sure are
accommodating to those of us who appreciate a little ``xmr``.

status
******
current support is *production grade* and both real-time data and order
management should be correct and fast. this backend is used by core devs
for live trading.


config
******
In order to get order mode support your ``brokers.toml``
needs to have something like the following:

.. code:: toml

[kraken]
accounts.spot = 'spot'
key_descr = "spot"
api_key = "69696969696969696696969696969696969696969696969696969696"
secret = "BOOBSBOOBSBOOBSBOOBSBOOBSSMBZ69696969696969669969696969696"


If everything works correctly you should see any current positions
loaded in the pps pane on chart load and you should also be able to
check your trade records in the file::

<pikerk_conf_dir>/ledgers/trades_kraken_spot.toml


An example ledger file will have entries written verbatim from the
trade events schema:

.. code:: toml

[TFJBKK-SMBZS-VJ4UWS]
ordertxid = "SMBZSA-7CNQU-3HWLNJ"
postxid = "SMBZSE-M7IF5-CFI7LT"
pair = "XXMRZEUR"
time = 1655691993.4133966
type = "buy"
ordertype = "limit"
price = "103.97000000"
cost = "499.99999977"
fee = "0.80000000"
vol = "4.80907954"
margin = "0.00000000"
misc = ""


your ``pps.toml`` file will have position entries like,

.. code:: toml

[kraken.spot."xmreur.kraken"]
size = 4.80907954
ppu = 103.97000000
bsuid = "XXMRZEUR"
clears = [
{ tid = "TFJBKK-SMBZS-VJ4UWS", cost = 0.8, price = 103.97, size = 4.80907954, dt = "2022-05-20T02:26:33.413397+00:00" },
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 schema actually changed in #365 so we might want to document the new column order and the ppu (aka breakeven price) stuff here as well.

]
Loading