Clean up `TooFastEdit` remnants and ws-token flow
Drop all commented-out `TooFastEdit` class,
`reg_err_types`, and `isinstance()` references.
Replace the hard ws-token `assert` in
`subscribe()` with a soft mismatch log that
updates the local `token` ref; cache the result
as `latest_token` for use in sub msgs.
Also,
- Comment out the `reg_err_types` import.
- Switch `pformat` -> `ppfmt` in `openOrders` update log.
(this commit msg was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
(cherry picked from commit 8299c65818)
wkt/land_kraken_parity_replay
parent
fadaad4241
commit
878a813b82
|
|
@ -38,7 +38,7 @@ from bidict import bidict
|
|||
import trio
|
||||
import tractor
|
||||
from tractor.devx.pformat import ppfmt
|
||||
from tractor._exceptions import reg_err_types
|
||||
# from tractor._exceptions import reg_err_types
|
||||
|
||||
from piker.accounting import (
|
||||
Position,
|
||||
|
|
@ -99,13 +99,6 @@ MsgUnion = Union[
|
|||
]
|
||||
|
||||
|
||||
# class TooFastEdit(Exception):
|
||||
# 'Edit requests faster then api submissions'
|
||||
|
||||
|
||||
# reg_err_types([TooFastEdit])
|
||||
|
||||
|
||||
# TODO: make this wrap the `api.Client` and `ws` instances
|
||||
# and give it methods to submit cancel vs. add vs. edit
|
||||
# requests?
|
||||
|
|
@ -168,7 +161,6 @@ async def handle_order_requests(
|
|||
# triggered-submitted and then we have inavlid
|
||||
# value in `reqids2txids` sent over ws.send()??
|
||||
log.error('TOO FAST CANCEL/EDIT')
|
||||
# reqids2txids[reqid] = TooFastEdit(reqid)
|
||||
toofastedit.add(reqid)
|
||||
reqids2txids[reqid] = reqid
|
||||
await ems_order_stream.send(
|
||||
|
|
@ -208,7 +200,6 @@ async def handle_order_requests(
|
|||
|
||||
# XXX: not sure if this block ever gets hit now?
|
||||
log.error('TOO FAST EDIT')
|
||||
# reqids2txids[reqid] = TooFastEdit(reqid)
|
||||
reqids2txids[reqid] = reqid
|
||||
toofastedit.add(reqid)
|
||||
await tractor.pause()
|
||||
|
|
@ -340,11 +331,19 @@ async def subscribe(
|
|||
'''
|
||||
# more specific logic for this in kraken's sync client:
|
||||
# https://github.com/krakenfx/kraken-wsclient-py/blob/master/kraken_wsclient_py/kraken_wsclient_py.py#L188
|
||||
assert (
|
||||
latest_token: str = await client.get_ws_token()
|
||||
if (
|
||||
token
|
||||
and
|
||||
token == await client.get_ws_token()
|
||||
!=
|
||||
latest_token
|
||||
):
|
||||
log.info(
|
||||
f'RE-subscribing to WS connection..\n'
|
||||
f'orig-token: {token!r}\n'
|
||||
f'latest-token: {latest_token!r}\n'
|
||||
)
|
||||
token = latest_token
|
||||
|
||||
subnames: set[str] = set()
|
||||
|
||||
for name, sub_opts in subs:
|
||||
|
|
@ -352,7 +351,8 @@ async def subscribe(
|
|||
'event': 'subscribe',
|
||||
'subscription': {
|
||||
'name': name,
|
||||
'token': await client.get_ws_token(),
|
||||
# 'token': await client.get_ws_token(),
|
||||
'token': latest_token,
|
||||
**sub_opts,
|
||||
}
|
||||
}
|
||||
|
|
@ -870,7 +870,7 @@ async def handle_order_updates(
|
|||
for order_msg in order_msgs:
|
||||
log.info(
|
||||
f'`openOrders` msg update_{seq}:\n'
|
||||
f'{pformat(order_msg)}'
|
||||
f'{ppfmt(order_msg)}'
|
||||
)
|
||||
txid, update_msg = list(order_msg.items())[0]
|
||||
|
||||
|
|
@ -1042,10 +1042,6 @@ async def handle_order_updates(
|
|||
status == 'open'
|
||||
and
|
||||
reqid in toofastedit
|
||||
# isinstance(
|
||||
# reqids2txids.get(reqid),
|
||||
# TooFastEdit
|
||||
# )
|
||||
):
|
||||
# TODO: don't even allow this case
|
||||
# by not moving the client side line
|
||||
|
|
@ -1209,7 +1205,6 @@ async def handle_order_updates(
|
|||
# we throttle too-fast-requests on the ems side
|
||||
and
|
||||
reqid in toofastedit
|
||||
# not isinstance(txid, TooFastEdit)
|
||||
):
|
||||
# client was editting too quickly
|
||||
# so we instead cancel this order
|
||||
|
|
|
|||
Loading…
Reference in New Issue