Add mid price to the option order in order to more accurately determine the incurred slippage

This commit is contained in:
moshferatu 2024-02-20 08:43:34 -08:00
parent 7c9837f3d2
commit 8f48ff6950
2 changed files with 5 additions and 4 deletions

View File

@ -143,7 +143,7 @@ class Client:
while not option_order.isDone():
self.ib.waitOnUpdate()
return OptionOrder(option_order)
return OptionOrder(option_order, leg_mid)
def submit_spread_order(self, near_leg: OptionLeg, far_leg: OptionLeg) -> OptionOrder:
near_leg_data = self.get_market_data(self.get_option_contract(near_leg))
@ -160,7 +160,7 @@ class Client:
while not spread_order.isDone():
self.ib.waitOnUpdate()
return OptionOrder(spread_order)
return OptionOrder(spread_order, spread_mid)
def submit_stop_loss_order(self, trade: Trade, stop_loss_price: float, limit_price: float = None) -> Trade:
stop_loss_order = Order()

View File

@ -2,6 +2,7 @@ from ib_insync import Trade
class OptionOrder:
def __init__(self, trade_result: Trade):
def __init__(self, trade_result: Trade, mid_price: float):
self.limit_price = abs(trade_result.order.lmtPrice)
self.fill_price = abs(trade_result.orderStatus.avgFillPrice)
self.fill_price = abs(trade_result.orderStatus.avgFillPrice)
self.mid_price = mid_price