Build cancel-order payload
Perps Execution
Build Cancel-Order Payload
Build a signed canonical payload to cancel an unfilled limit order (or TP/SL attached to a position) on Gains Network or Lighter.
POST
Build cancel-order payload
Builds the payload to cancel an unfilled order. For Gains,
orderType distinguishes pending limit orders (order) from TP/SL legs (tp, sl) attached to an open trade.
Request Body
gains or lighter.Chain of the order.
Order index as a positive integer string (regex
^\d+$). Obtainable from /2/wallet/perp/orders.Mobula market identifier. Required by Lighter.
Gains only. One of
order, tp, sl. Omit for Lighter.Authentication
Every/2/perp/payloads/<action> endpoint verifies the caller by requiring two extra fields in the request body alongside the action parameters:
Unix timestamp in milliseconds. Must be within 30 seconds of server time. Older timestamps are rejected to prevent replay.
Hex signature (EIP-191
personal_sign) of the message `${endpoint}-${timestamp}`, where endpoint is the path of this endpoint without the leading slash (e.g., for this page: api/2/perp/payloads/<this-action>). The recovered signer address becomes the user for the request. Single-use — replay returns 403 signature already used.Authentication errors
| Status | message |
|---|---|
| 403 | timestamp expired — timestamp older than 30s |
| 403 | signature already used — replay attempt |
| 400 | zod validation failed — timestamp/signature shape invalid |
Response envelope
Every/2/perp/payloads/<action> endpoint returns the same envelope shape. You pass these fields verbatim into POST /2/perp/execute-v2 to execute the action.
Top-level shape. Successful (2xx) responses return
{ data: { ... } }. A success: true flag is only present inside the body of execute-v2’s response, not on the payload-build endpoints. Parse defensively: read body.data, then check for the action-specific fields you need (e.g. data.payloadStr).Endpoint-specific errors
| Status | message |
|---|---|
| 400 | cancel-order payload generation failed — order not found or DEX refusal |
Full flow — cancel an order end-to-end
Single example covering both DEXes (Lighter offchain-api, Gains evm-tx). The flow branches ondata.transport.
Body
application/json
Available options:
gains, lighter Positive integer string (regex ^\d+$).
Required by Lighter.
Gains only. Omit for Lighter.
Available options:
order, tp, sl