Log exit slippage incurred when stopping out of a trade
This commit is contained in:
parent
0f12e6932c
commit
5807aa076c
@ -58,12 +58,14 @@ def monitor_spread_price(short_leg: OptionLeg, long_leg: OptionLeg, stop_price:
|
|||||||
short_leg_exit = replace(short_leg, action = BUY if short_leg.action == SELL else SELL)
|
short_leg_exit = replace(short_leg, action = BUY if short_leg.action == SELL else SELL)
|
||||||
long_leg_exit = replace(long_leg, action = BUY if long_leg.action == SELL else SELL)
|
long_leg_exit = replace(long_leg, action = BUY if long_leg.action == SELL else SELL)
|
||||||
if long_contract.bid > 0:
|
if long_contract.bid > 0:
|
||||||
client.submit_spread_order(short_leg_exit, long_leg_exit)
|
exit_order = client.submit_spread_order(short_leg_exit, long_leg_exit)
|
||||||
logging.info('Whole spread exited.')
|
logging.info('Whole spread exited.')
|
||||||
else:
|
else:
|
||||||
client.submit_option_order(short_leg_exit)
|
exit_order = client.submit_option_order(short_leg_exit)
|
||||||
logging.info('Short leg only exited.')
|
logging.info('Short leg only exited.')
|
||||||
|
|
||||||
|
logging.info(f'Exit Slippage: {exit_order.fill_price - stop_price}')
|
||||||
|
|
||||||
# Unsubscribe from market data updates once the trade has exited.
|
# Unsubscribe from market data updates once the trade has exited.
|
||||||
for leg in [short_leg, long_leg]:
|
for leg in [short_leg, long_leg]:
|
||||||
market_data[leg].updateEvent -= on_market_data_update
|
market_data[leg].updateEvent -= on_market_data_update
|
||||||
|
Loading…
Reference in New Issue
Block a user