From a10783c737361c06f7a43676174079a9a07cc35c Mon Sep 17 00:00:00 2001 From: moshferatu Date: Thu, 22 Feb 2024 11:34:05 -0800 Subject: [PATCH] Add the list of option legs to the order --- ibkr/client.py | 4 ++-- ibkr/option_order.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ibkr/client.py b/ibkr/client.py index 3f07d7a..261197a 100644 --- a/ibkr/client.py +++ b/ibkr/client.py @@ -145,7 +145,7 @@ class Client: while not option_order.isDone(): self.ib.waitOnUpdate() - return OptionOrder(option_order, leg_mid) + return OptionOrder([leg], leg_mid, option_order) 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)) @@ -164,7 +164,7 @@ class Client: while not spread_order.isDone(): self.ib.waitOnUpdate() - return OptionOrder(spread_order, spread_mid) + return OptionOrder([near_leg, far_leg], spread_mid, spread_order) def submit_stop_loss_order(self, trade: Trade, stop_loss_price: float, limit_price: float = None) -> Trade: stop_loss_order = Order() diff --git a/ibkr/option_order.py b/ibkr/option_order.py index ae7283f..f40b127 100644 --- a/ibkr/option_order.py +++ b/ibkr/option_order.py @@ -1,8 +1,12 @@ from ib_insync import Trade +from typing import List + +from .option_leg import OptionLeg class OptionOrder: - 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.mid_price = mid_price \ No newline at end of file + def __init__(self, legs: List[OptionLeg], mid_price: float, order_result: Trade): + self.legs = legs + self.mid_price = mid_price + self.limit_price = abs(order_result.order.lmtPrice) + self.fill_price = abs(order_result.orderStatus.avgFillPrice) \ No newline at end of file