Skip to content

Add contingent orders support: order groups and order sends order - #109

Merged
Martin-Molinero merged 4 commits into
masterfrom
feature-contingent-orders
Sep 25, 2026
Merged

Martin-Molinero merged 4 commits into
masterfrom
feature-contingent-orders

Conversation

@Martin-Molinero

@Martin-Molinero Martin-Molinero commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Description

Places contingent order sets through TradeStation's native order relationships:

  • OCO/BRK order groups through the order groups endpoint. BRK maps the one updates other contingency.
  • Orders triggered by another are sent as OSOs of their parent, grouped when they are related to each other.
  • Held children are reported as triggered once their parent fills.
  • The contingencies of open orders are rebuilt from their linked orders (OCO, BRK, OSO and OSP relationships) through OrderContingency.Trigger/Relate.
  • TradeStation confirms the orders sent by another (OSO) before it: the placed orders are matched in that order, ruling out a confirmation for another side or order type.
  • Orders TradeStation cancels itself (CAN), like the orders sent by a canceled order, are reported as canceled.
  • The sent but not yet acknowledged orders (OPN) are loaded as open orders, they were skipped.
  • TradeStation cancels the rest of a group when a member fills, not when one is canceled: canceling a member warns once that the rest keep working.

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.

How Has This Been Tested?

  • Unit tests of the contingent orders support: request building and open orders rebuilding.
  • Live on the TradeStation simulator, through the Lean BrokerageTests contingent orders suite (TradeStationBrokerageTests.ContingentOrders.cs):
Case Equity (AAPL) Option (AAPL) Index option (SPXW) Future (MES)
OCO resting: cancel one ✅ ✅ ✅ ✅
OUO (BRK, limit + stop) resting: cancel one ✅ ✅ ✅ ✅
OTO resting: cancel the parent cancels the held child ✅ ✅ ✅ ✅
Bracket resting: cancel the entry cancels the held exits ✅ ✅ ✅ ✅
OCO / OUO / OTO / bracket: every order updated, held ones included ✅ ✅ ✅ ✅
OTO / bracket with a market parent: parent fills, children released ✅ ✅ ✅ ✅
OCO / OUO / OTO / bracket: open orders rebuilt with the same contingencies, held ones held ✅ ✅ ✅ ✅
  • OCO with a market member: the fill cancels the other member and it's reported as canceled.
  • Existing order tests, equities: market, limit, stop market and stop limit orders long/short from zero and closing (16), limit order update, update of a canceled order. CancelOrders fails as on master: the second cancel of the closed order returns true (_cancelOrderSoftRejects).

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. Please add associated performance test and results)
  • 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>

🤖 Generated with Claude Code

Places OCO/BRK order groups through the order groups endpoint and the
orders triggered by another as OSOs, reports triggered orders once their
parent fills and rebuilds the contingencies of open orders from their
linked orders.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Martin-Molinero and others added 3 commits September 24, 2026 13:05
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…TradeStation

TradeStation confirms the orders sent by another (OSO) before it: the placed orders are matched in that order, ruling out
the confirmations which are for another side or order type. Orders canceled by TradeStation (CAN), like the orders sent by a
canceled order, are reported as canceled. Canceling a member of an order group warns once that the rest keep working.
The contingent orders tests cover equities, options, index options and futures.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…rders test

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Martin-Molinero
Martin-Molinero merged commit 06c2c94 into master Sep 25, 2026
1 check failed
@Martin-Molinero
Martin-Molinero deleted the feature-contingent-orders branch September 25, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant