Consolidate the inputs required when updating the trades table into an options order
This commit is contained in:
parent
19987f1114
commit
a9023f8594
@ -14,7 +14,7 @@ from ibkr.order_action import BUY, SELL
|
||||
from iron_condor_trade import IronCondorTrade
|
||||
from options_chain import OptionsChain
|
||||
from option_type import OptionType
|
||||
from trades_table import insert_trade, update_on_stop_loss
|
||||
from trades_table import insert_trade, update_trade
|
||||
|
||||
load_dotenv()
|
||||
|
||||
@ -64,7 +64,7 @@ def monitor_spread_price(trade: IronCondorTrade, short_leg: OptionLeg, long_leg:
|
||||
exit_slippage = round(exit_order.fill_price - stop_price, 3)
|
||||
logging.info(f'Exit Slippage: {exit_slippage}')
|
||||
|
||||
update_on_stop_loss(trade, short_leg.option_type, exit_order.fill_price, exit_slippage)
|
||||
update_trade(trade, exit_order)
|
||||
|
||||
# Unsubscribe from market data updates once the trade has exited.
|
||||
for leg in [short_leg, long_leg]:
|
||||
|
@ -50,7 +50,7 @@ def insert_trade(iron_condor: IronCondorTrade, call_spread_order: OptionOrder, p
|
||||
}])
|
||||
)
|
||||
|
||||
def update_on_stop_loss(iron_condor: IronCondorTrade, option_type: str, close_price: float, exit_slippage: float):
|
||||
def update_trade(iron_condor: IronCondorTrade, stop_order: OptionOrder):
|
||||
date = iron_condor.entry_time.date()
|
||||
|
||||
trade_record = trade(
|
||||
@ -61,10 +61,13 @@ def update_on_stop_loss(iron_condor: IronCondorTrade, option_type: str, close_pr
|
||||
)
|
||||
spreads = trade_record['Spreads'].iloc[0]
|
||||
|
||||
spread_index = 0 if option_type == 'C' else 1 # 'C' for call spread, 'P' for put spread.
|
||||
option_type = translate_option_type(stop_order.legs[0].option_type)
|
||||
spread_index = 0 if (option_type == OptionType.CALL) else 1
|
||||
|
||||
spreads[spread_index]['Close'] = close_price
|
||||
spreads[spread_index]['Exit Slippage'] = exit_slippage
|
||||
spreads[spread_index]['Close'] = stop_order.fill_price
|
||||
|
||||
stop_price = spreads[spread_index]['Open'] * iron_condor.stop_multiple
|
||||
spreads[spread_index]['Exit Slippage'] = round(stop_order.fill_price - stop_price, 3)
|
||||
|
||||
upsert(
|
||||
DataFrame([{
|
||||
|
Loading…
Reference in New Issue
Block a user