Trading

Place complex order

post
https://api.snaptrade.com/api/v1/accounts/{accountId}/trading/complex

Places a complex conditional order (OCO, OTO, or OTOCO). Disabled by default — contact support to enable. Only supported on certain brokerages.

  • OCO (One Cancels the Other): Two peer orders; when one fills the other is cancelled.
  • OTO (One Triggers the Other): A trigger order that, when filled, activates a conditional order.
  • OTOCO (One Triggers a One Cancels the Other): A trigger order that, when filled, activates an OCO pair of two peer orders.

Execute an API Request

Path
accountIdstring (format: uuid)required

The ID of the account to execute the trade on.

Query
userIdstringrequired

SnapTrade User ID. This is chosen by the API partner and can be any string that is a) unique to the user, and b) immutable for the user. It is recommended to NOT use email addresses for this property because they are usually not immutable.

userSecretstringrequired

SnapTrade User Secret. This is a randomly generated string and should be stored securely. If compromised, please rotate it via the rotate user secret endpoint.

Request Body
typestringrequired

The complex order type.

  • OCO: One Cancels the Other — two peer orders.
  • OTO: One Triggers the Other — a trigger order and a conditional order.
  • OTOCO: One Triggers a One Cancels the Other — a trigger order and two peer orders.
ordersarray of objectsrequired

The orders that make up the complex order. Required counts and roles per type:

  • OCO: exactly 2 orders, both PEER
  • OTO: exactly 2 orders, one TRIGGER and one CONDITIONAL
  • OTOCO: exactly 3 orders, one TRIGGER and two PEER
client_order_idstring or null

An optional client-provided identifier for this complex order. Passed through to the brokerage and returned in the response.

Authorization
Request
Installation
$
npm install snaptrade-typescript-sdk
1
import { Snaptrade } from "snaptrade-typescript-sdk";
2
3
const snaptrade = new Snaptrade({
4
clientId: "PARTNER_CLIENT_ID",
5
consumerKey: "CONSUMER_KEY",
6
});
7
8
const response =
9
await snaptrade.trading.placeComplexOrder({
10
accountId:
11
"917c8734-8470-4a3e-a18f-57c3f2ee6631",
12
userId: "snaptrade-user-123",
13
userSecret:
14
"adf2aa34-8219-40f7-a6b3-60156985cc61",
15
type: "OTO",
16
orders: [
17
{
18
order_role: "TRIGGER",
19
action: "ACTION",
20
instrument: {
21
symbol: "AAPL",
22
type: "TYPE",
23
},
24
order_type: "Market",
25
units: 10.5,
26
time_in_force: "Day",
27
price: 31.33,
28
stop: 29.5,
29
},
30
],
31
client_order_id: "my-order-123",
32
});
33
console.log(response.data);

Response fields

object

Response returned after successfully placing a complex order. AccountOrderRecord rows for the legs are not created synchronously — they're hydrated by the next brokerage sync, and can be queried later using the returned brokerage_group_order_id.

typestring

The complex order type that was placed.

brokerage_group_order_idstring or null

The brokerage-assigned identifier that links all legs of this complex order together. Each leg will eventually appear as a separate AccountOrderRecord sharing this value. May be null if the brokerage does not return a group identifier.

1
{
2
"type": "OTO",
3
"brokerage_group_order_id": "1234567890"
4
}