Skip to main content
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

dex
string
required
gains or lighter.
chainId
string
required
Chain of the order.
orderIndex
string
required
Order index as a positive integer string (regex ^\d+$). Obtainable from /2/wallet/perp/orders.
marketId
string
Mobula market identifier. Required by Lighter.
orderType
string
Gains only. One of order, tp, sl. Omit for Lighter.

Endpoint-specific errors

Statusmessage
400cancel-order payload generation failed — order not found or DEX refusal

Example

Cancel Lighter unfilled order orderIndex=42 on BTC/USD:
const endpoint = 'api/2/perp/payloads/cancel-order';
const timestamp = Date.now();
const signature = await wallet.signMessage(`${endpoint}-${timestamp}`);

const res = await fetch(`https://api.mobula.io/${endpoint}`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    timestamp,
    signature,
    dex: 'lighter',
    chainId: 'lighter:301',
    marketId: 'lighter-btc-usd',
    orderIndex: '42',
  }),
}).then(r => r.json());