Skip to content

Cancel Orders

Cancel one or more existing orders by their unique order IDs

Endpoint

POST https://papi.synthetix.io/v1/trade

Request

Request Format

{
  "params": {
    "action": "cancelOrders",
    "orderIds": ["1948058938469519360"]
  },
  "nonce": 1704067200000,
  "signature": {
    "v": 28,
    "r": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
    "s": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
  },
  "expiresAfter": 1704067300000
}

Request Parameters

ParameterTypeRequiredDescription
paramsobjectYesParameters object containing method details
params.actionstringYesMust be "cancelOrders"
params.orderIdsarrayYesArray of orderId to cancel
ParameterTypeRequiredDescription
nonceuint64YesUnix milliseconds timestamp (must be monotonically increasing)
signatureobjectYesEIP-712 signature object
expiresAfteruint64NoUnix milliseconds expiration timestamp (5x rate limit on stale cancels)

Response

Success Response

{
  "status": "ok",
  "response": {
    "statuses": [
      {
        "canceled": {
          "id": "1948058938469519360"
        }
      }
    ]
  },
  "request_id": "5ccf215d37e3ae6d",
  "timestamp": "2025-01-01T00:00:00Z"
}

Success Response - Multiple Orders

{
  "status": "ok",
  "response": {
    "statuses": [
      {
        "canceled": {
          "id": "1948058938469519360"
        }
      },
      {
        "canceled": {
          "id": "1948058938469519361"
        }
      }
    ]
  },
  "request_id": "5ccf215d37e3ae6d",
  "timestamp": "2025-01-01T00:00:00Z"
}

Error Response

{
  "status": "error",
  "error": {
    "message": "Order not found",
    "code": "VALIDATION_ERROR"
  },
  "request_id": "5ccf215d37e3ae6d",
  "timestamp": "2025-01-01T00:00:00Z"
}

Code Examples

Cancel Single Order

{
  "action": {
    "action": "cancelOrders",
    "orderIds": ["1948058938469519360"]
  },
  "nonce": 1704067200000,
  "signature": {
    "v": 28,
    "r": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
    "s": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
  }
}

Cancel Multiple Orders

{
  "action": {
    "action": "cancelOrders",
    "orderIds": ["1948058938469519360", "1948058938469519361"]
  },
  "nonce": 1704067200000,
  "signature": {
    "v": 28,
    "r": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
    "s": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
  }
}

Cancel Behavior

  • Only OPEN/PARTIALLY_FILLED orders can be cancelled
  • Filled portions of partially filled orders remain executed
  • Cancellation is immediate upon validation
  • Freed margin becomes available instantly

Order States

StateCan Cancel
OPEN✅ Yes
PARTIALLY_FILLED✅ Yes (remaining quantity)
FILLED❌ No
CANCELLED❌ No
EXPIRED❌ No

Validation Rules

  • nonce must be a timestamp in milliseconds and must be increasing
  • orderIds array must contain at least one order ID
  • Each order ID must be a valid integer
  • Orders must belong to the requesting account
  • Must be signed by order owner or authorized delegate

Signing

All trading methods are signed using EIP-712. Each successful trading request will contain:

  • A piece of structured data that includes the sender address
  • A signature of the hash of that structured data, signed by the sender

For detailed information on EIP-712 signing, see EIP-712 Signing.

Nonce Management

The nonce system prevents replay attacks and ensures order uniqueness:

  • Use current timestamp in milliseconds as nonce
  • Each nonce must be greater than the previous one
  • Recommended: Use Date.now() or equivalent
  • If nonce conflicts occur, increment by 1 and retry

Error Handling

Common error scenarios:

ErrorDescription
Order not foundOrder ID does not exist or not owned by user
Order already cancelledOrder was previously cancelled
Order already filledOrder was completely filled
Empty orderIds arrayMust specify at least one order to cancel
ErrorDescription
Invalid signatureEIP-712 signature validation failed
Invalid market symbolMarket symbol not recognized
Nonce already usedNonce must be greater than previous value
Rate limit exceededToo many requests in time window
Request expiredexpiresAfter timestamp has passed