Matchify paper clearing loop

the_ems_flattening
Tyler Goodlet 2022-08-04 16:26:12 -04:00
parent e28c1748fc
commit 109b35f6eb
1 changed files with 36 additions and 32 deletions

View File

@ -312,47 +312,51 @@ async def simulate_fills(
# this stream may eventually contain multiple symbols # this stream may eventually contain multiple symbols
async for quotes in quote_stream: async for quotes in quote_stream:
for sym, quote in quotes.items(): for sym, quote in quotes.items():
for tick in iterticks( for tick in iterticks(
quote, quote,
# dark order price filter(s) # dark order price filter(s)
types=('ask', 'bid', 'trade', 'last') types=('ask', 'bid', 'trade', 'last')
): ):
# print(tick) # print(tick)
tick_price = tick.get('price') match tick:
ttype = tick['type'] case {
'price': tick_price,
if ttype in ('ask',): 'type': 'ask',
}:
client.last_ask = ( client.last_ask = (
tick_price, tick_price,
tick.get('size', client.last_ask[1]), tick.get('size', client.last_ask[1]),
) )
orders = client._buys.get(sym, {}) orders = client._buys.get(sym, {})
book_sequence = reversed( book_sequence = reversed(
sorted(orders.keys(), key=itemgetter(1))) sorted(orders.keys(), key=itemgetter(1)))
def pred(our_price): def pred(our_price):
return tick_price < our_price return tick_price <= our_price
elif ttype in ('bid',):
case {
'price': tick_price,
'type': 'bid',
}:
client.last_bid = ( client.last_bid = (
tick_price, tick_price,
tick.get('size', client.last_bid[1]), tick.get('size', client.last_bid[1]),
) )
orders = client._sells.get(sym, {}) orders = client._sells.get(sym, {})
book_sequence = sorted(orders.keys(), key=itemgetter(1)) book_sequence = sorted(
orders.keys(),
key=itemgetter(1)
)
def pred(our_price): def pred(our_price):
return tick_price > our_price return tick_price >= our_price
elif ttype in ('trade', 'last'): case {
'price': tick_price,
'type': ('trade' | 'last'),
}:
# TODO: simulate actual book queues and our orders # TODO: simulate actual book queues and our orders
# place in it, might require full L2 data? # place in it, might require full L2 data?
continue continue