Skip to content

Cancel an order or close a position

Three different ways out, three different endpoints. Cancelling kills a resting order, flattening closes what is already open, and reversing closes it and opens the opposite leg.

  1. Cancel keys off the venue order id, so read it off the order rows first. It is null before dispatch and on an order that never dispatched.

    Terminal window
    curl -s "https://api.troncharts.xyz/api/v1/accounts/$ACCOUNT_ID/orders?symbol=BTC.HL" \
    -H "authorization: Bearer $TOKEN" \
    -H "x-tenant-slug: $TC_TENANT_SLUG"
    # → { orders: [ { orderId, venueOrderId, symbol, type, state, … } ] }
  2. POST /oms/cancel composes a cancel intent against the resolved parent and returns 201 { intentId } — the id of the cancel, not of the order you killed.

    Terminal window
    curl -s https://api.troncharts.xyz/api/v1/oms/cancel \
    -H "authorization: Bearer $TOKEN" \
    -H "x-tenant-slug: $TC_TENANT_SLUG" \
    -H 'content-type: application/json' \
    -H "idempotency-key: $(uuidgen)" \
    -d '{"venueOrderId":"'"$VENUE_ORDER_ID"'"}'
  3. Both fields are optional and independent: symbol narrows to one market, accountId targets an owned account other than the token’s own. An empty body acts on the whole scope. Flatten cancels the symbol’s working orders first, then closes — so a resting order can’t fire against a now-flat account.

    Terminal window
    curl -s https://api.troncharts.xyz/api/v1/oms/flatten \
    -H "authorization: Bearer $TOKEN" \
    -H "x-tenant-slug: $TC_TENANT_SLUG" \
    -H 'content-type: application/json' \
    -d '{"symbol":"BTC.HL"}'
    # → { ok, cancelIntentIds, closeIntentId, alreadyFlat }
  4. Same body, opposite intent: /oms/reverse closes the position and opens the other side. openIntentId comes back null with reverseOpenDeferred: true — the open leg is composed at the realized close size once the close terminalizes, so it can never oversize the flip. It surfaces on the /ws/risk Position-Update frame.

    Terminal window
    curl -s https://api.troncharts.xyz/api/v1/oms/reverse \
    -H "authorization: Bearer $TOKEN" \
    -H "x-tenant-slug: $TC_TENANT_SLUG" \
    -H 'content-type: application/json' \
    -d '{"symbol":"BTC.HL"}'

    Cancel and flatten only reduce exposure, so a liquidation credential can make them. Reverse re-establishes it and needs fullTrading. See Scopes & tiers.

Next: Place your first order · Stream account and position updates · Accounts & positions