From 5807aa076c502b4867c999447db225ba7e28cae4 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Wed, 21 Feb 2024 08:35:27 -0800 Subject: [PATCH] Log exit slippage incurred when stopping out of a trade --- iron_condor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iron_condor.py b/iron_condor.py index eb6f139..97b9eef 100644 --- a/iron_condor.py +++ b/iron_condor.py @@ -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) long_leg_exit = replace(long_leg, action = BUY if long_leg.action == SELL else SELL) 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.') 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(f'Exit Slippage: {exit_order.fill_price - stop_price}') + # Unsubscribe from market data updates once the trade has exited. for leg in [short_leg, long_leg]: market_data[leg].updateEvent -= on_market_data_update