Don't spin paper clear loop on non-clearing ticks
Not sure what exactly happened but it seemed clears weren't working in some cases without this, also there's no point in spinning the simulated clearing loop if we're handling a non-clearing tick type.multi_client_order_mgt
parent
48ff4859e6
commit
30bce42c0b
|
@ -61,13 +61,13 @@ log = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class PaperBoi(Struct):
|
class PaperBoi(Struct):
|
||||||
"""
|
'''
|
||||||
Emulates a broker order client providing the same API and
|
Emulates a broker order client providing approximately the same API
|
||||||
delivering an order-event response stream but with methods for
|
and delivering an order-event response stream but with methods for
|
||||||
triggering desired events based on forward testing engine
|
triggering desired events based on forward testing engine
|
||||||
requirements.
|
requirements (eg open, closed, fill msgs).
|
||||||
|
|
||||||
"""
|
'''
|
||||||
broker: str
|
broker: str
|
||||||
|
|
||||||
ems_trades_stream: tractor.MsgStream
|
ems_trades_stream: tractor.MsgStream
|
||||||
|
@ -336,9 +336,10 @@ async def simulate_fills(
|
||||||
return tick_price >= our_price
|
return tick_price >= our_price
|
||||||
|
|
||||||
match tick:
|
match tick:
|
||||||
|
|
||||||
|
# on an ask queue tick, only clear buy entries
|
||||||
case {
|
case {
|
||||||
'price': tick_price,
|
'price': tick_price,
|
||||||
# 'type': ('ask' | 'trade' | 'last'),
|
|
||||||
'type': 'ask',
|
'type': 'ask',
|
||||||
}:
|
}:
|
||||||
client.last_ask = (
|
client.last_ask = (
|
||||||
|
@ -351,9 +352,9 @@ async def simulate_fills(
|
||||||
itertools.repeat(buy_on_ask)
|
itertools.repeat(buy_on_ask)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# on a bid queue tick, only clear sell entries
|
||||||
case {
|
case {
|
||||||
'price': tick_price,
|
'price': tick_price,
|
||||||
# 'type': ('bid' | 'trade' | 'last'),
|
|
||||||
'type': 'bid',
|
'type': 'bid',
|
||||||
}:
|
}:
|
||||||
client.last_bid = (
|
client.last_bid = (
|
||||||
|
@ -366,6 +367,10 @@ async def simulate_fills(
|
||||||
itertools.repeat(sell_on_bid)
|
itertools.repeat(sell_on_bid)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# TODO: fix this block, though it definitely
|
||||||
|
# costs a lot more CPU-wise
|
||||||
|
# - doesn't seem like clears are happening still on
|
||||||
|
# "resting" limit orders?
|
||||||
case {
|
case {
|
||||||
'price': tick_price,
|
'price': tick_price,
|
||||||
'type': ('trade' | 'last'),
|
'type': ('trade' | 'last'),
|
||||||
|
@ -390,6 +395,13 @@ async def simulate_fills(
|
||||||
|
|
||||||
iter_entries = interleave()
|
iter_entries = interleave()
|
||||||
|
|
||||||
|
# NOTE: all other (non-clearable) tick event types
|
||||||
|
# - we don't want to sping the simulated clear loop
|
||||||
|
# below unecessarily and further don't want to pop
|
||||||
|
# simulated live orders prematurely.
|
||||||
|
case _:
|
||||||
|
continue
|
||||||
|
|
||||||
# iterate all potentially clearable book prices
|
# iterate all potentially clearable book prices
|
||||||
# in FIFO order per side.
|
# in FIFO order per side.
|
||||||
for order_info, pred in iter_entries:
|
for order_info, pred in iter_entries:
|
||||||
|
@ -532,7 +544,10 @@ async def trades_dialogue(
|
||||||
|
|
||||||
# TODO: load paper positions per broker from .toml config file
|
# TODO: load paper positions per broker from .toml config file
|
||||||
# and pass as symbol to position data mapping: ``dict[str, dict]``
|
# and pass as symbol to position data mapping: ``dict[str, dict]``
|
||||||
await ctx.started((pp_msgs, ['paper']))
|
await ctx.started((
|
||||||
|
pp_msgs,
|
||||||
|
['paper'],
|
||||||
|
))
|
||||||
|
|
||||||
async with (
|
async with (
|
||||||
ctx.open_stream() as ems_stream,
|
ctx.open_stream() as ems_stream,
|
||||||
|
|
Loading…
Reference in New Issue