Add support for stop limit orders

This commit is contained in:
moshferatu 2024-02-17 09:27:21 -08:00
parent e722eacd7a
commit d95269cf4f

View File

@ -125,10 +125,16 @@ class Client:
return self.ib.placeOrder(combo_contract, combo_order)
def submit_stop_loss_order(self, trade: Trade, stop_loss_price):
def submit_stop_loss_order(self, trade: Trade, stop_loss_price: float, limit_price: float = None) -> Trade:
stop_loss_order = Order()
stop_loss_order.action = SELL if trade.order.action == BUY else BUY
stop_loss_order.orderType = 'STP'
if limit_price is None:
stop_loss_order.orderType = 'STP'
else:
stop_loss_order.orderType = 'STP LMT'
stop_loss_order.lmtPrice = limit_price
stop_loss_order.auxPrice = stop_loss_price
stop_loss_order.totalQuantity = trade.order.totalQuantity
stop_loss_order.transmit = True