Repository navigation
Add contingent orders support: bracket, oco and oto order classes - #83
Merged
Merged
Conversation
5 of 11 tasks
Places brackets, OCO exits and OTO sets as a single advanced order, propagates the brokerage side leg resizing, reports triggered legs once the entry fills and rebuilds the contingencies of nested open orders. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Martin-Molinero
force-pushed
the
feature-contingent-orders
branch
from
September 25, 2026 12:50
6918992 to
0660cef
Compare
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This was referenced Sep 25, 2026
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
Places contingent order sets as a single Alpaca advanced order:
bracket: entry with take profit and stop loss.oco: exits only.oto: entry and one exit.OrderContingency.Trigger/Relate. Open orders are read withnested=true, which only regroups the bracket/oco/oto legs: multi-leg option orders come with their legs either way (checked live).order parameters are not changed) leaving the order unchanged, or rejects the replacement when the order filled first, a fill the stream reports.Related Issue
Requires QuantConnect/Lean#9828, which adds contingent orders to Lean. This PR builds against it, so CI will pass once it's merged and released.
Motivation and Context
Support for Lean contingent orders (OCO, OTO, OUO, brackets) using the brokerage's native functionality, so the sets are placed atomically and managed on the brokerage side.
Requires Documentation Change
The supported contingent order shapes of this brokerage, see its brokerage model in Lean: equities only, crypto and options are rejected by the model (Alpaca supports advanced orders for equities).
How Has This Been Tested?
BrokerageTestscontingent orders suite (AlpacaBrokerageTests.ContingentOrders.cs):order parameters are not changed): checked live that the rejection is now a warning and the order stays submitted, and OCO, which Alpaca only takes as the exits of an existing position.The ❌ fail as on master: the test moves the stop to the last traded price to force a fill, and Alpaca rejects it when the price ticked the other way (
stop price must be less than current price), or it doesn't fill in time. Flaky, the long from short stop limit failed in the previous run.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>🤖 Generated with Claude Code