Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

POST /cancel-order

This endpoint builds a cancellation transaction for an existing limit order. The returned payload must be signed and submitted to the blockchain by the caller to complete the cancellation.

TypeScript Types: Generate types for this API with a single command. See Type Generation.

API Reference: For detailed schema definitions and interactive testing, see the API Reference.

Request

Endpoint

POST /cancel-order

Headers

Content-Type: application/json
x-api-key: YOUR_API_KEY

Body Parameters

FieldTypeRequiredDescription
orderIdstringYesThe ID of the limit order to cancel
chainChainYesThe chain where the order was placed

Example Request

import type { components } from './m0-swap'; // From type generation
 
type CancelOrderResponse = components['schemas']['CancelOrderResponse'];
 
const response = await fetch('https://gateway.m0.xyz/v1/orchestration/cancel-order', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': YOUR_API_KEY,
  },
  body: JSON.stringify({
    orderId: '0xabc123...', // The limit order ID
    chain: 'Ethereum',
  }),
});
 
if (!response.ok) {
  const error = await response.text();
  throw new Error(`Cancel order failed: ${error}`);
}
 
const result: CancelOrderResponse = await response.json();

Response

Success Response (200)

Returns a CancelOrderResponse object containing the transaction payload to submit on-chain to complete the cancellation.

import type { components } from './m0-swap';
 
type CancelOrderResponse = components['schemas']['CancelOrderResponse'];

Response Fields

FieldTypeDescription
orderIdstringThe ID of the order being cancelled
chainChainThe chain where the cancellation transaction must be sent
payloadTransactionPayloadThe signed transaction data to submit to cancel the order

The payload field follows the same TransactionPayload structure as quote payloads — either an EvmPayload or SvmPayload depending on the chain. See the Quote docs for payload execution examples.

Error Responses

StatusDescription
404Order not found — the orderId does not exist on the specified chain
409Order cannot be cancelled — it may already be filled, expired, or cancelled
500Internal server error

Example Response

{
  "orderId": "0xabc123...",
  "chain": "Ethereum",
  "payload": {
    "type": "evm",
    "chain": "Ethereum",
    "chainId": 1,
    "to": "0x1234567890abcdef...",
    "data": "0xabcdef...",
    "value": "0"
  }
}

Executing the Cancellation

Once you have the response, submit the payload to the blockchain to complete the cancellation:

import { createWalletClient, http } from 'viem';
import { mainnet } from 'viem/chains';
import type { components } from './m0-swap';
 
type EvmPayload = components['schemas']['EvmPayload'];
 
async function executeCancelOrder(payload: EvmPayload, account: `0x${string}`) {
  const client = createWalletClient({
    chain: mainnet,
    transport: http(),
    account,
  });
 
  const hash = await client.sendTransaction({
    to: payload.to as `0x${string}`,
    data: payload.data as `0x${string}`,
    value: BigInt(payload.value),
  });
 
  return hash;
}

Notes

  • Only the original order creator can cancel a limit order
  • A 409 response means the order is in a terminal state (filled, expired, or already cancelled) and no action is needed
  • The cancellation is not final until the returned transaction payload is submitted and confirmed on-chain