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,50 +312,54 @@ 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,
'type': 'ask',
}:
client.last_ask = (
tick_price,
tick.get('size', client.last_ask[1]),
)
if ttype in ('ask',): orders = client._buys.get(sym, {})
book_sequence = reversed(
sorted(orders.keys(), key=itemgetter(1)))
client.last_ask = ( def pred(our_price):
tick_price, return tick_price <= our_price
tick.get('size', client.last_ask[1]),
)
orders = client._buys.get(sym, {}) case {
'price': tick_price,
'type': 'bid',
}:
client.last_bid = (
tick_price,
tick.get('size', client.last_bid[1]),
)
orders = client._sells.get(sym, {})
book_sequence = sorted(
orders.keys(),
key=itemgetter(1)
)
book_sequence = reversed( def pred(our_price):
sorted(orders.keys(), key=itemgetter(1))) return tick_price >= our_price
def pred(our_price): case {
return tick_price < our_price 'price': tick_price,
'type': ('trade' | 'last'),
elif ttype in ('bid',): }:
# TODO: simulate actual book queues and our orders
client.last_bid = ( # place in it, might require full L2 data?
tick_price, continue
tick.get('size', client.last_bid[1]),
)
orders = client._sells.get(sym, {})
book_sequence = sorted(orders.keys(), key=itemgetter(1))
def pred(our_price):
return tick_price > our_price
elif ttype in ('trade', 'last'):
# TODO: simulate actual book queues and our orders
# place in it, might require full L2 data?
continue
# iterate book prices descending # iterate book prices descending
for oid, our_price in book_sequence: for oid, our_price in book_sequence: