Skip to content

Modify Order

Modify existing orders by changing their price and/or quantity. This is essentially a cancel-and-replace operation that maintains the order's position in the queue while updating its parameters.

Endpoint

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

Request

Request Format

{
  "params": {
    "action": "modifyOrder",
    "subAccountId": "1867542890123456789",
    "orderId": "12345",
    "price": "45000.50",
    "quantity": "2.50"
  },
  "nonce": 1703123456789,
  "signature": {
    "v": 27,
    "r": "0x5a3c2b1d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789",
    "s": "0x1a2b3c4d5e6f7890abcdef0123456789abcdef0123456789abcdef0123456789"
  },
  "expiresAfter": 1703123456789
}

Request Parameters

ParameterTypeRequiredDescription
paramsobjectYesAction object containing modification details
params.actionstringYesMust be "modifyOrder"
params.subAccountIdstringYesSubAccount ID that owns the order
params.orderIdstringYesOrder ID to modify (string for JS BigInt compatibility)
params.pricestringNo*New price as decimal string
params.quantitystringNo*New quantity as decimal string
params.triggerPricestringNo*New trigger price for conditional orders (triggerSl, triggerTp)
noncenumberYesTimestamp in milliseconds for signature uniqueness
signatureobjectYesEIP-712 signature components
expiresAfternumberNoOptional expiration timestamp in milliseconds
*At least one of price, quantity, or triggerPrice must be provided for the modification to be valid.

Response

Success Response

{
  "status": "ok",
  "response": {
    "orderId": "12345",
    "status": "modified",
    "price": "45000.50",
    "quantity": "2.50"
  },
  "request_id": "req-123456789",
  "timestamp": "2025-01-01T00:00:00Z"
}

Error Response

{
  "status": "error",
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Order not found or does not belong to this subaccount",
    "details": null
  },
  "request_id": "req-123456789",
  "timestamp": "2025-01-01T00:00:00Z"
}

Response Fields

FieldTypeDescription
statusstringAlways "ok" for successful requests or "error" for failures
responseobjectContains operation results (omitted when status is "error")
response.orderIdstringThe modified order ID
response.statusstringAlways "modified" for successful operations
response.pricestringNew price (only if modified)
response.quantitystringNew quantity (only if modified)
errorobjectError details (only present when status is "error")
requestIdstringRequest tracking identifier
timestampintegerUnix milliseconds timestamp

Code Examples

Modify Order Price Only

{
  "params": {
    "action": "modifyOrder",
    "orderId": "12345",
    "price": "49000.00"
  },
  "nonce": 1703123456789,
  "signature": {
    "v": 27,
    "r": "0x5a3c2b1d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789",
    "s": "0x1a2b3c4d5e6f7890abcdef0123456789abcdef0123456789abcdef0123456789"
  },
  "subAccountId": "1",
}

Modify Order Quantity Only

{
  "params": {
    "action": "modifyOrder",
    "orderId": "12346",
    "quantity": "0.50"
  },
  "nonce": 1703123466789,
  "signature": {
    "v": 27,
    "r": "0x5a3c2b1d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789",
    "s": "0x1a2b3c4d5e6f7890abcdef0123456789abcdef0123456789abcdef0123456789"
  },
  "subAccountId": 1
}

Modify Both Price and Quantity

{
  "params": {
    "action": "modifyOrder",
    "orderId": "12347",
    "price": "95.50",
    "quantity": "5.00"
  },
  "nonce": 1703123476789,
  "signature": {
    "v": 27,
    "r": "0x5a3c2b1d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789",
    "s": "0x1a2b3c4d5e6f7890abcdef0123456789abcdef0123456789abcdef0123456789"
  },
  "subAccountId": "1",
  "expiresAfter": 1703123506789
}

Important Behavior

  • Queue Position: The operation preserves the order's position in the queue when possible
  • Atomic Operation: The modify operation is atomic - either the entire modification succeeds or fails
  • Partial Modification: If only one field (price or quantity) is provided, the other field retains its current value
  • Precision: All monetary values use string representation to avoid floating-point precision issues

Validation Rules

Request Validation

  1. Action Type: Must be exactly "modifyOrder"
  2. Order ID: Must be a valid positive integer string
  3. Modification Fields: At least one of price, quantity, or triggerPrice must be provided
  4. Price Format: If provided, must be a valid decimal string
  5. Quantity Format: If provided, must be a valid decimal string
  6. Trigger Price Format: If provided, must be a valid decimal string
  7. Order Existence: The order must exist and belong to the specified subaccount
  8. Signature Verification: EIP-712 signature must be valid for the request parameters

Business Logic Validation

  • Order must be in an open/active state
  • Cannot modify orders that are already filled or cancelled
  • Price/quantity changes must comply with market rules
  • Account must have sufficient margin for the modification

Authentication & Authorization

  • Request must include valid EIP-712 signature using the ModifyOrder typed data structure
  • nonce must be a timestamp in milliseconds and must be increasing per address
  • Each nonce can only be used once (replay protection)
  • expiresAfter timestamp must be in the future (if provided)
EIP-712 Domain Separator:
{
  "name": "Synthetix",
  "version": "1",
  "chainId": 1,
  "verifyingContract": "0x0000000000000000000000000000000000000000"
}

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
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
Error CodeDescription
VALIDATION_ERRORRequest validation failed (invalid format, missing fields, etc.)
INVALID_FORMATRequest body is not valid JSON
INTERNAL_ERRORServer-side processing error
UNAUTHORIZEDAuthentication failed
FORBIDDENWallet does not own the specified subaccount
Invalid signatureEIP-712 signature verification failed
Signature address mismatchSignature address does not match wallet address
Nonce already usedNonce has been used in a previous request (replay protection)
Request expiredexpiresAfter timestamp has passed
Order not foundOrder ID does not exist or not owned by user
Order not modifiableOrder is filled, cancelled, or not a limit order
Invalid order parametersNew order parameters are invalid