Skip to content

Commit b841318

Browse files
committed
Fix order modification
Rather than modifying an existing order object in-place, we create a new object and copy the fields.
1 parent e890591 commit b841318

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

thetagang/portfolio_manager.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,19 +2369,22 @@ def adjust_prices(self) -> None:
23692369
order.lmtPrice
23702370
) == np.sign(updated_price):
23712371
console.print(
2372-
f"[green]Resubmitting order for {contract.symbol}"
2372+
f"[green]Resubmitting {order.action} {contract.secType} order for {contract.symbol}"
23732373
f" with old lmtPrice={dfmt(order.lmtPrice)} updated lmtPrice={dfmt(updated_price)}"
23742374
)
23752375
order.lmtPrice = float(updated_price)
23762376

2377-
if contract.secType == "BAG":
2378-
# for some reason, these fields need to be cleared
2379-
# when modifying an existing BAG (combo) order
2380-
# in-place (janky)
2381-
order.algoStrategy = ""
2382-
order.algoParams = []
2383-
order.tif = ""
2384-
order.account = ""
2377+
# For some reason, we need to create a new order object
2378+
# and populate the fields rather than modifying the
2379+
# existing order in-place (janky).
2380+
order = LimitOrder(
2381+
order.action,
2382+
order.totalQuantity,
2383+
updated_price,
2384+
orderId=order.orderId,
2385+
algoStrategy=order.algoStrategy,
2386+
algoParams=order.algoParams,
2387+
)
23852388

23862389
# put the trade back from whence it came
23872390
self.trades[idx] = self.ib.placeOrder(contract, order)

0 commit comments

Comments
 (0)