Positions
Flatten account: close positions and cancel orders
The full “panic button”: closes all open positions AND cancels all pending orders for the specified account(s).
Modes:
- Single account:
{ "account_ids": ["uuid"] } - Multiple accounts:
{ "account_ids": ["uuid1", "uuid2"] } - All accounts:
{}(empty body flattens everything) - Symbol-filtered: add
"symbols": ["ESH6"]to only flatten specific contracts
If flattening causes the profit target to be met on any account, those accounts are marked as passed.
Returns a command acceptance. Requires x-idempotency-key header.
POST
/
trade
/
flatten
// Flatten everything for a specific account
const response = await fetch('/trade/flatten', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
account_ids: ['550e8400-e29b-41d4-a716-446655440000']
})
});
const { data } = await response.json();
console.log(`Flattened: ${data.positions_closed} positions, ${data.orders_cancelled} orders`);
{
"code": null,
"data": {
"accepted": true,
"command_id": "0d9f3c1e-7c2a-4b53-9d21-8f6a2e4b7c90",
"command_type": "Flatten",
"status": "queued"
},
"error": null,
"success": true
}{
"code": "ERROR_CODE",
"data": null,
"error": "Error message describing what went wrong",
"success": false
}{
"code": "LOCKOUT_ACTIVE",
"data": null,
"error": "Account is locked out until 2026-03-12T16:00:00Z (mode: timed, 45 minutes remaining)",
"success": false
}{
"code": "ERROR_CODE",
"data": null,
"error": "Error message describing what went wrong",
"success": false
}{
"code": "RATE_LIMITED",
"data": null,
"error": "Rate limit exceeded for order submissions. Max 10 requests per second per account. Retry after 100 ms.",
"rate_limit": {
"limit": 10,
"remaining": 0,
"reset": 1711800125,
"retry_after": 0.1
},
"success": false
}Authorizations
Body
application/json
Request to flatten account(s)
⌘I
// Flatten everything for a specific account
const response = await fetch('/trade/flatten', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
account_ids: ['550e8400-e29b-41d4-a716-446655440000']
})
});
const { data } = await response.json();
console.log(`Flattened: ${data.positions_closed} positions, ${data.orders_cancelled} orders`);
{
"code": null,
"data": {
"accepted": true,
"command_id": "0d9f3c1e-7c2a-4b53-9d21-8f6a2e4b7c90",
"command_type": "Flatten",
"status": "queued"
},
"error": null,
"success": true
}{
"code": "ERROR_CODE",
"data": null,
"error": "Error message describing what went wrong",
"success": false
}{
"code": "LOCKOUT_ACTIVE",
"data": null,
"error": "Account is locked out until 2026-03-12T16:00:00Z (mode: timed, 45 minutes remaining)",
"success": false
}{
"code": "ERROR_CODE",
"data": null,
"error": "Error message describing what went wrong",
"success": false
}{
"code": "RATE_LIMITED",
"data": null,
"error": "Rate limit exceeded for order submissions. Max 10 requests per second per account. Retry after 100 ms.",
"rate_limit": {
"limit": 10,
"remaining": 0,
"reset": 1711800125,
"retry_after": 0.1
},
"success": false
}