diff --git a/ibkr/client.py b/ibkr/client.py index a60d667..6ca6f5a 100644 --- a/ibkr/client.py +++ b/ibkr/client.py @@ -135,7 +135,9 @@ class Client: def submit_option_order(self, leg: OptionLeg) -> OptionOrder: leg_data = self.get_market_data(self.get_option_contract(leg)) leg_mid = (leg_data.ask + max(leg_data.bid, 0)) / 2.0 + leg_limit = (leg_mid - 0.25) - (leg_mid % 0.05) + leg_limit = leg_limit if leg.action == BUY else -leg_limit option_order = self.submit_single_option_order(leg_data, limit_price = leg_limit) while not option_order.isDone(): @@ -143,17 +145,18 @@ class Client: return OptionOrder(option_order) - def submit_spread_order(self, short_leg: OptionLeg, long_leg: OptionLeg) -> OptionOrder: - short_leg_data = self.get_market_data(self.get_option_contract(short_leg)) - long_leg_data = self.get_market_data(self.get_option_contract(long_leg)) + 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)) + far_leg_data = self.get_market_data(self.get_option_contract(far_leg)) - short_leg_mid = (short_leg_data.ask + max(short_leg_data.bid, 0)) / 2.0 - long_leg_mid = (long_leg_data.ask + max(long_leg_data.bid, 0)) / 2.0 + near_leg_mid = (near_leg_data.ask + max(near_leg_data.bid, 0)) / 2.0 + far_leg_mid = (far_leg_data.ask + max(far_leg_data.bid, 0)) / 2.0 + spread_mid = near_leg_mid - far_leg_mid - spread_mid = short_leg_mid - long_leg_mid spread_limit = (spread_mid - 0.25) - (spread_mid % 0.05) + spread_limit = spread_limit if near_leg.action == BUY else -spread_limit - spread_order = self.submit_combo_option_order([short_leg, long_leg], limit_price = spread_limit) + spread_order = self.submit_combo_option_order([near_leg, far_leg], limit_price = spread_limit) while not spread_order.isDone(): self.ib.waitOnUpdate()