Default quantity to 1 contract when submitting option orders

This commit is contained in:
moshferatu 2024-02-19 12:40:46 -08:00
parent 3c276c15c1
commit 5be5867c47

View File

@ -80,7 +80,7 @@ class Client:
self.ib.qualifyContracts(option_contract) self.ib.qualifyContracts(option_contract)
return option_contract return option_contract
def submit_combo_option_order(self, legs: List[OptionLeg], quantity: int, limit_price: float = None) -> Trade: def submit_combo_option_order(self, legs: List[OptionLeg], quantity: int = 1, limit_price: float = None) -> Trade:
combo_legs = [] combo_legs = []
for leg in legs: for leg in legs:
option_contract = self.get_option_contract(leg) option_contract = self.get_option_contract(leg)
@ -112,7 +112,7 @@ class Client:
return self.ib.placeOrder(combo_contract, combo_order) return self.ib.placeOrder(combo_contract, combo_order)
def submit_single_option_order(self, leg: OptionLeg, quantity: int, limit_price: float = None) -> Trade: def submit_single_option_order(self, leg: OptionLeg, quantity: int = 1, limit_price: float = None) -> Trade:
option_contract = self.get_option_contract(leg) option_contract = self.get_option_contract(leg)
contract = Contract() contract = Contract()
contract.conId = option_contract.conId contract.conId = option_contract.conId
@ -137,7 +137,7 @@ class Client:
leg_mid = (leg_data.ask + max(leg_data.bid, 0)) / 2.0 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_mid - 0.25) - (leg_mid % 0.05)
option_order = self.submit_single_option_order(leg_data, 1, limit_price = leg_limit) option_order = self.submit_single_option_order(leg_data, limit_price = leg_limit)
while not option_order.isDone(): while not option_order.isDone():
self.ib.waitOnUpdate() self.ib.waitOnUpdate()
@ -153,7 +153,7 @@ class Client:
spread_mid = short_leg_mid - long_leg_mid spread_mid = short_leg_mid - long_leg_mid
spread_limit = (spread_mid - 0.25) - (spread_mid % 0.05) spread_limit = (spread_mid - 0.25) - (spread_mid % 0.05)
spread_order = self.submit_combo_option_order([short_leg, long_leg], 1, limit_price = spread_limit) spread_order = self.submit_combo_option_order([short_leg, long_leg], limit_price = spread_limit)
while not spread_order.isDone(): while not spread_order.isDone():
self.ib.waitOnUpdate() self.ib.waitOnUpdate()