Compare commits
2 Commits
8299c65818
...
d1eec24ed5
| Author | SHA1 | Date |
|---|---|---|
|
|
d1eec24ed5 | |
|
|
d06bbec24f |
|
|
@ -38,7 +38,7 @@ from bidict import bidict
|
||||||
import trio
|
import trio
|
||||||
import tractor
|
import tractor
|
||||||
from tractor.devx.pformat import ppfmt
|
from tractor.devx.pformat import ppfmt
|
||||||
# from tractor._exceptions import reg_err_types
|
from tractor._exceptions import reg_err_types
|
||||||
|
|
||||||
from piker.accounting import (
|
from piker.accounting import (
|
||||||
Position,
|
Position,
|
||||||
|
|
@ -97,6 +97,13 @@ 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
|
# TODO: make this wrap the `api.Client` and `ws` instances
|
||||||
# and give it methods to submit cancel vs. add vs. edit
|
# and give it methods to submit cancel vs. add vs. edit
|
||||||
# requests?
|
# requests?
|
||||||
|
|
@ -159,6 +166,7 @@ async def handle_order_requests(
|
||||||
# triggered-submitted and then we have inavlid
|
# triggered-submitted and then we have inavlid
|
||||||
# value in `reqids2txids` sent over ws.send()??
|
# value in `reqids2txids` sent over ws.send()??
|
||||||
log.error('TOO FAST CANCEL/EDIT')
|
log.error('TOO FAST CANCEL/EDIT')
|
||||||
|
# reqids2txids[reqid] = TooFastEdit(reqid)
|
||||||
toofastedit.add(reqid)
|
toofastedit.add(reqid)
|
||||||
reqids2txids[reqid] = reqid
|
reqids2txids[reqid] = reqid
|
||||||
await ems_order_stream.send(
|
await ems_order_stream.send(
|
||||||
|
|
@ -198,6 +206,7 @@ async def handle_order_requests(
|
||||||
|
|
||||||
# XXX: not sure if this block ever gets hit now?
|
# XXX: not sure if this block ever gets hit now?
|
||||||
log.error('TOO FAST EDIT')
|
log.error('TOO FAST EDIT')
|
||||||
|
# reqids2txids[reqid] = TooFastEdit(reqid)
|
||||||
reqids2txids[reqid] = reqid
|
reqids2txids[reqid] = reqid
|
||||||
toofastedit.add(reqid)
|
toofastedit.add(reqid)
|
||||||
await tractor.pause()
|
await tractor.pause()
|
||||||
|
|
@ -329,19 +338,11 @@ async def subscribe(
|
||||||
'''
|
'''
|
||||||
# more specific logic for this in kraken's sync client:
|
# 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
|
# https://github.com/krakenfx/kraken-wsclient-py/blob/master/kraken_wsclient_py/kraken_wsclient_py.py#L188
|
||||||
latest_token: str = await client.get_ws_token()
|
assert (
|
||||||
if (
|
|
||||||
token
|
token
|
||||||
!=
|
and
|
||||||
latest_token
|
token == await client.get_ws_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()
|
subnames: set[str] = set()
|
||||||
|
|
||||||
for name, sub_opts in subs:
|
for name, sub_opts in subs:
|
||||||
|
|
@ -349,8 +350,7 @@ async def subscribe(
|
||||||
'event': 'subscribe',
|
'event': 'subscribe',
|
||||||
'subscription': {
|
'subscription': {
|
||||||
'name': name,
|
'name': name,
|
||||||
# 'token': await client.get_ws_token(),
|
'token': await client.get_ws_token(),
|
||||||
'token': latest_token,
|
|
||||||
**sub_opts,
|
**sub_opts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -698,7 +698,7 @@ async def open_trade_dialog(
|
||||||
handle_order_requests,
|
handle_order_requests,
|
||||||
ws=ws,
|
ws=ws,
|
||||||
client=client,
|
client=client,
|
||||||
ems_order_stream=ems_stream,
|
ems_stream=ems_stream,
|
||||||
apiflows=apiflows,
|
apiflows=apiflows,
|
||||||
ids=ids,
|
ids=ids,
|
||||||
reqids2txids=reqids2txids,
|
reqids2txids=reqids2txids,
|
||||||
|
|
@ -868,7 +868,7 @@ async def handle_order_updates(
|
||||||
for order_msg in order_msgs:
|
for order_msg in order_msgs:
|
||||||
log.info(
|
log.info(
|
||||||
f'`openOrders` msg update_{seq}:\n'
|
f'`openOrders` msg update_{seq}:\n'
|
||||||
f'{ppfmt(order_msg)}'
|
f'{pformat(order_msg)}'
|
||||||
)
|
)
|
||||||
txid, update_msg = list(order_msg.items())[0]
|
txid, update_msg = list(order_msg.items())[0]
|
||||||
|
|
||||||
|
|
@ -1040,6 +1040,10 @@ async def handle_order_updates(
|
||||||
status == 'open'
|
status == 'open'
|
||||||
and
|
and
|
||||||
reqid in toofastedit
|
reqid in toofastedit
|
||||||
|
# isinstance(
|
||||||
|
# reqids2txids.get(reqid),
|
||||||
|
# TooFastEdit
|
||||||
|
# )
|
||||||
):
|
):
|
||||||
# TODO: don't even allow this case
|
# TODO: don't even allow this case
|
||||||
# by not moving the client side line
|
# by not moving the client side line
|
||||||
|
|
@ -1203,6 +1207,7 @@ async def handle_order_updates(
|
||||||
# we throttle too-fast-requests on the ems side
|
# we throttle too-fast-requests on the ems side
|
||||||
and
|
and
|
||||||
reqid in toofastedit
|
reqid in toofastedit
|
||||||
|
# not isinstance(txid, TooFastEdit)
|
||||||
):
|
):
|
||||||
# client was editting too quickly
|
# client was editting too quickly
|
||||||
# so we instead cancel this order
|
# so we instead cancel this order
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue