feature: add one-cancels-the-other (OCO) order group - #9635
Draft
Romazes wants to merge 3 commits into
Draft
Conversation
Romazes
marked this pull request as draft
July 24, 2026 15:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a one-cancels-the-other (OCO) order group.
QCAlgorithm.OneCancelsTheOtherOrderplaces 2 or 3Limit/StopMarketorders together: when one leg fully fills, the other legs are canceled in the same order-event batch. A partial fill does not cancel the siblings.C#:
Python:
Main changes:
ComboTypeenum onGroupOrderManager(Combo,OneCancelsTheOther). Previously serialized groups keep loading asCombo.IBrokerageModel.SupportsGroupExecution(ComboType)with a default body that only acceptsCombo, so existing brokerage models (including Python ones) keep today's behavior.AlpacaBrokerageModelopts into OCO. In live trading the transaction handler rejects a group the brokerage model does not support; backtesting and paper trading simulate the group in the engine.BacktestingBrokerageevaluates the legs of a group in a fixed order (stop legs first, then limit legs, then by id) and cancels the open siblings as soon as one leg fully fills.LiquidateandCancelOpenOrdersissue one cancel per group instead of one per leg, since canceling one leg cancels the whole group.0001-bracket-order-type.mdand0002-one-cancels-the-other-order-group.md.Related PR(s)
N/A
Related Issue
#8253
Motivation and Context
First step of the bracket order plan: OCO now, conditional (OTO) next, bracket on top of both. Users can protect a position with a take-profit and stop-loss pair without managing the cancellation themselves.
Requires Documentation Change
Yes — the new
OneCancelsTheOtherOrderAPI needs documentation.How Has This Been Tested?
OneCancelsTheOtherOrderRegressionAlgorithm(winner leg fills and the sibling cancels in the same event batch),OneCancelsTheOtherOrderCancelRegressionAlgorithm(canceling one leg cancels the whole group), plusOneCancelsTheOtherOrderDemoAlgorithm.BacktestingBrokerageTests(group fill, cancel and invalid paths),AlgorithmTradingTests(submit validation),BrokerageTransactionHandlerTests(live support gate, projected holdings),SecurityPortfolioManagerTestsandCashBuyingPowerModelTests(buying power),OrderJsonConverterTestsandOrderTests(serialization round trip),PythonWrapperTests,AlpacaBrokerageModelTests,DefaultBrokerageModelTests.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>