Use 2 min-ticks offset for dark orders

basic_orders
Tyler Goodlet 2021-01-22 23:00:01 -05:00
parent f072e2551b
commit 4b2161a37b
1 changed files with 27 additions and 5 deletions

View File

@ -236,7 +236,13 @@ async def exec_loop(
# update to keep new cmds informed # update to keep new cmds informed
book.lasts[(broker, symbol)] = price book.lasts[(broker, symbol)] = price
for oid, (pred, tf, cmd, percent_away) in ( for oid, (
pred,
tf,
cmd,
percent_away,
abs_diff_away
) in (
tuple(execs.items()) tuple(execs.items())
): ):
@ -244,8 +250,10 @@ async def exec_loop(
# majority of iterations will be non-matches # majority of iterations will be non-matches
continue continue
submit_price = price + price*percent_away # submit_price = price + price*percent_away
print( submit_price = price + abs_diff_away
log.info(
f'Dark order triggered for price {price}\n' f'Dark order triggered for price {price}\n'
f'Submitting order @ price {submit_price}') f'Submitting order @ price {submit_price}')
@ -274,7 +282,7 @@ async def exec_loop(
# remove exec-condition from set # remove exec-condition from set
log.info(f'removing pred for {oid}') log.info(f'removing pred for {oid}')
pred, tf, cmd, percent_away = execs.pop(oid) execs.pop(oid)
await ctx.send_yield(resp) await ctx.send_yield(resp)
@ -359,6 +367,9 @@ async def process_broker_trades(
# XXX should we make one when it's blank? # XXX should we make one when it's blank?
log.error(pformat(message)) log.error(pformat(message))
# TODO: getting this bs, prolly need to handle status messages
# 'Market data farm connection is OK:usfarm.nj'
# another stupid ib error to handle # another stupid ib error to handle
# if 10147 in message: cancel # if 10147 in message: cancel
@ -523,20 +534,31 @@ async def _ems_main(
# the user choose the predicate operator. # the user choose the predicate operator.
pred = mk_check(trigger_price, last) pred = mk_check(trigger_price, last)
mt = feed.symbols[sym].min_tick
if action == 'buy': if action == 'buy':
tickfilter = ('ask', 'last', 'trade') tickfilter = ('ask', 'last', 'trade')
percent_away = 0.005 percent_away = 0.005
abs_diff_away = 2 * mt
elif action == 'sell': elif action == 'sell':
tickfilter = ('bid', 'last', 'trade') tickfilter = ('bid', 'last', 'trade')
percent_away = -0.005 percent_away = -0.005
abs_diff_away = -2 * mt
else: # alert else: # alert
tickfilter = ('trade', 'utrade', 'last') tickfilter = ('trade', 'utrade', 'last')
percent_away = 0 percent_away = 0
abs_diff_away = 0
# submit execution/order to EMS scanner loop # submit execution/order to EMS scanner loop
book.orders.setdefault( book.orders.setdefault(
sym, {} sym, {}
)[oid] = (pred, tickfilter, cmd, percent_away) )[oid] = (
pred,
tickfilter,
cmd,
percent_away,
abs_diff_away
)
# ack-response that order is live here # ack-response that order is live here
await ctx.send_yield({ await ctx.send_yield({