Skip to content

fix: keep order properties on rebuilt open orders - #267

Merged
Romazes merged 2 commits into
QuantConnect:masterfrom
Romazes:bug-rebuilt-open-orders-lose-ib-properties
Oct 1, 2026
Merged

Romazes merged 2 commits into
QuantConnect:masterfrom
Romazes:bug-rebuilt-open-orders-lose-ib-properties

Conversation

@Romazes

@Romazes Romazes commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Open orders that the brokerage rebuilds in GetOpenOrders now carry InteractiveBrokersOrderProperties. Before, a rebuilt order had plain OrderProperties.

// first deployment: the order rests at IB
DefaultOrderProperties = new InteractiveBrokersOrderProperties { OutsideRegularTradingHours = true };
LimitOrder("SPY", 1, 100m);

// next deployment: Lean rebuilds the order from IB
var order = Transactions.GetOpenOrders().First();
var properties = order.Properties as InteractiveBrokersOrderProperties;   // before: null
IB open order Lean order properties
OutsideRth OutsideRegularTradingHours, always
FaGroup is set FaGroup, FaMethod, and FaPercentage when the method is PctChange
no FaGroup, Account is not the account of the deployment Account
  • FaProfile can not be copied, IB has no such field: "openOrder callback will report Profile in place of Group if order was for profile" (IB docs). Such an order is rebuilt with the name in FaGroup.
  • The check for the method PctChange is one helper now, used by the order placement too. It does not look at the case of the name; before, the placement compared with == "PctChange".
  • If the conversion of the properties fails, the error is logged with the order values it reads, and the order is rebuilt with the default OrderProperties, like before this change.

Related PR(s)

Related Issue

N/A

Motivation and Context

  • The algorithm could not see how a rebuilt order is routed and if it can trade outside regular hours.
  • Financial Advisor accounts: CanEmitFill accepted every execution of a rebuilt order, the ones of the allocations too. Now a rebuilt account group order reports only the execution of the master account, and a single managed account order only the executions of that account.

The update of a rebuilt order is not a reason: master sends it with OutsideRth = false and the master account, but IB keeps the flag and the routing of the open order (second table below).

Requires Documentation Change

No

How Has This Been Tested?

Live on the IB paper Financial Advisor account (group filter TEST), 2026-09-29, regular trading hours.

InteractiveBrokersOpenOrderPropertiesTests.GetOpenOrdersAfterRestartKeepsOutsideRegularTradingHours places the order with the flag, stops the brokerage, starts a new one and reads GetOpenOrders:

Case master 25fa440 this branch 26635c1
(Limit, 100), SPY fails passes
(ComboLimit, 0.05), SPXW 7700/7750 call spread, 2026-10-02 fails passes

Both fail with Expected: instance of <QuantConnect.Orders.InteractiveBrokersOrderProperties> But was: <QuantConnect.Orders.OrderProperties>.

An update that carries other values than the open order has. IB takes the new price only, with no error and no warning:

Open order at IB Update sent IB after the update
SPY limit 100, OutsideRth = true, single managed account, no group by master for the rebuilt order: limit 101, OutsideRth = false, master account, FaGroup = "TEST" limit 101, OutsideRth = true, the same managed account, no group
SPY limit 100, OutsideRth = true limit 101, OutsideRth = false limit 101, OutsideRth = true
SPY limit 100, OutsideRth = false limit 101, OutsideRth = true limit 101, OutsideRth = false
  • The combo case uses SPXW: on a SPY option combo IB holds the order without the flag, 2109 - Order Event Warning:Attribute 'Outside Regular Trading Hours' is ignored based on the order type and destination. PlaceOrder is now being processed.
  • Offline: InteractiveBrokersOpenOrderTimeConversionTests and InteractiveBrokersFaGroupOrderConversionTests pass.
  • Not checked: the full test suite, a fill, an order with the method PctChange. The follow-up commit f407dca (try catch and log around the conversion) was built, not run live.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>

@Romazes Romazes self-assigned this Sep 29, 2026
@Romazes Romazes added the bug Something isn't working label Sep 29, 2026
- copy FaGroup, FaMethod, FaPercentage, Account and OutsideRth from the ib open order
- pass the properties to every rebuilt order type
- share the percent change method check with the order placement
- add a live test with a limit order and a combo limit order
@Romazes
Romazes force-pushed the bug-rebuilt-open-orders-lose-ib-properties branch from 1ac6006 to 26635c1 Compare September 29, 2026 18:03
- wrap ConvertOrderProperties in a try catch and log the error
- log the order values the conversion reads
- return null so the rebuilt order gets the default order properties
@Romazes
Romazes force-pushed the bug-rebuilt-open-orders-lose-ib-properties branch from cbbd626 to f407dca Compare October 1, 2026 15:24
@Romazes
Romazes merged commit 695d344 into QuantConnect:master Oct 1, 2026
@Romazes
Romazes deleted the bug-rebuilt-open-orders-lose-ib-properties branch October 1, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants