> ## Documentation Index
> Fetch the complete documentation index at: https://docs.polymarket.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 取消订单

> 取消单个、多个或所有未完成订单

所有取消端点都需要 [L2 身份验证](/trading/overview#authentication)。响应始终包含 `canceled`(已取消订单 ID 列表)和 `not_canceled`(订单 ID 到失败原因的映射)。

***

## 取消单个订单

<CodeGroup>
  ```typescript TypeScript theme={null}
  const resp = await client.cancelOrder("0xb816482a...");
  console.log(resp);
  // { canceled: ["0xb816482a..."], not_canceled: {} }
  ```

  ```python Python theme={null}
  resp = client.cancel(order_id="0xb816482a...")
  print(resp)
  # {"canceled": ["0xb816482a..."], "not_canceled": {}}
  ```

  ```bash REST theme={null}
  curl -X DELETE "https://clob.polymarket.com/order" \
    -H "Content-Type: application/json" \
    -H "POLY_ADDRESS: ..." \
    -H "POLY_SIGNATURE: ..." \
    -H "POLY_TIMESTAMP: ..." \
    -H "POLY_API_KEY: ..." \
    -H "POLY_PASSPHRASE: ..." \
    -d '{"orderID": "0xb816482a..."}'
  ```
</CodeGroup>

***

## 取消多个订单

<CodeGroup>
  ```typescript TypeScript theme={null}
  const resp = await client.cancelOrders(["0xb816482a...", "0xc927593b..."]);
  ```

  ```python Python theme={null}
  resp = client.cancel_orders([
      "0xb816482a...",
      "0xc927593b...",
  ])
  ```

  ```bash REST theme={null}
  curl -X DELETE "https://clob.polymarket.com/orders" \
    -H "Content-Type: application/json" \
    -H "POLY_ADDRESS: ..." \
    -H "POLY_SIGNATURE: ..." \
    -H "POLY_TIMESTAMP: ..." \
    -H "POLY_API_KEY: ..." \
    -H "POLY_PASSPHRASE: ..." \
    -d '["0xb816482a...", "0xc927593b..."]'
  ```
</CodeGroup>

***

## 取消所有订单

取消所有市场中的每个未完成订单:

<CodeGroup>
  ```typescript TypeScript theme={null}
  const resp = await client.cancelAll();
  ```

  ```python Python theme={null}
  resp = client.cancel_all()
  ```

  ```bash REST theme={null}
  curl -X DELETE "https://clob.polymarket.com/cancel-all" \
    -H "POLY_ADDRESS: ..." \
    -H "POLY_SIGNATURE: ..." \
    -H "POLY_TIMESTAMP: ..." \
    -H "POLY_API_KEY: ..." \
    -H "POLY_PASSPHRASE: ..."
  ```
</CodeGroup>

***

## 按市场取消

取消特定市场的所有订单,可选择性地筛选到单个代币。`market` 和 `asset_id` 都是可选的——同时省略两者将取消所有订单。

<CodeGroup>
  ```typescript TypeScript theme={null}
  const resp = await client.cancelMarketOrders({
    market: "0xbd31dc8a...", // optional: condition ID
    asset_id: "52114319501245...", // optional: specific token
  });
  ```

  ```python Python theme={null}
  resp = client.cancel_market_orders(
      market="0xbd31dc8a...",
      asset_id="52114319501245...",  # optional
  )
  ```

  ```bash REST theme={null}
  curl -X DELETE "https://clob.polymarket.com/cancel-market-orders" \
    -H "Content-Type: application/json" \
    -H "POLY_ADDRESS: ..." \
    -H "POLY_SIGNATURE: ..." \
    -H "POLY_TIMESTAMP: ..." \
    -H "POLY_API_KEY: ..." \
    -H "POLY_PASSPHRASE: ..." \
    -d '{"market": "0xbd31dc8a...", "asset_id": "52114319501245..."}'
  ```
</CodeGroup>

***

## 查询订单

### 获取单个订单

<CodeGroup>
  ```typescript TypeScript theme={null}
  const order = await client.getOrder("0xb816482a...");
  console.log(order.status, order.size_matched);
  ```

  ```python Python theme={null}
  order = client.get_order("0xb816482a...")
  print(order["status"], order["size_matched"])
  ```
</CodeGroup>

### 获取未完成订单

检索所有未完成订单,可选择性地按市场或代币筛选:

<CodeGroup>
  ```typescript TypeScript theme={null}
  // All open orders
  const orders = await client.getOpenOrders();

  // Filtered by market
  const marketOrders = await client.getOpenOrders({
    market: "0xbd31dc8a...",
  });

  // Filtered by token
  const tokenOrders = await client.getOpenOrders({
    asset_id: "52114319501245...",
  });
  ```

  ```python Python theme={null}
  from py_clob_client_v2 import OpenOrderParams

  # All open orders
  orders = client.get_orders()

  # Filtered by market
  market_orders = client.get_orders(
      OpenOrderParams(market="0xbd31dc8a...")
  )
  ```
</CodeGroup>

### OpenOrder 对象

| 字段                 | 类型        | 描述                       |
| ------------------ | --------- | ------------------------ |
| `id`               | string    | 订单 ID                    |
| `status`           | string    | 当前订单状态                   |
| `market`           | string    | Condition ID             |
| `asset_id`         | string    | Token ID                 |
| `side`             | string    | `BUY` 或 `SELL`           |
| `original_size`    | string    | 下单时的数量                   |
| `size_matched`     | string    | 已成交数量                    |
| `price`            | string    | 限价                       |
| `outcome`          | string    | 人类可读的结果(例如,"Yes","No")   |
| `order_type`       | string    | 订单类型(GTC, GTD, FOK, FAK) |
| `maker_address`    | string    | 资金提供者地址                  |
| `owner`            | string    | 订单所有者的 API key           |
| `associate_trades` | string\[] | 此订单包含的交易 ID              |
| `expiration`       | string    | Unix 过期时间戳(如果没有则为 `0`)   |
| `created_at`       | string    | Unix 创建时间戳               |

***

## 交易历史

当订单匹配时,会创建一笔交易。交易经历以下状态:

| Status      | Terminal | Description   |
| ----------- | -------- | ------------- |
| `MATCHED`   | No       | 已匹配并发送至链上提交   |
| `MINED`     | No       | 已在链上挖出,尚未最终确认 |
| `CONFIRMED` | Yes      | 已达到最终性——交易成功  |
| `RETRYING`  | No       | 交易失败——正在重试    |
| `FAILED`    | Yes      | 永久失败          |

<CodeGroup>
  ```typescript TypeScript theme={null}
  // All trades
  const trades = await client.getTrades();

  // Filtered by market
  const marketTrades = await client.getTrades({
    market: "0xbd31dc8a...",
  });
  ```

  ```python Python theme={null}
  from py_clob_client_v2 import TradeParams

  trades = client.get_trades()

  market_trades = client.get_trades(
      TradeParams(market="0xbd31dc8a...")
  )
  ```
</CodeGroup>

其他筛选参数: `id`, `maker_address`, `asset_id`, `before`, `after`。

对于大型结果集,使用分页变体:

<CodeGroup>
  ```typescript TypeScript theme={null}
  const page = await client.getTradesPaginated({ market: "0xbd31dc8a..." });
  console.log(page.trades, page.count); // trades array + total count
  ```

  ```python Python theme={null}
  page = client.get_trades_paginated(TradeParams(market="0xbd31dc8a..."))
  ```
</CodeGroup>

### Trade 对象

| 字段                 | 类型            | 描述                |
| ------------------ | ------------- | ----------------- |
| `id`               | string        | 交易 ID             |
| `taker_order_id`   | string        | Taker 订单哈希        |
| `market`           | string        | Condition ID      |
| `asset_id`         | string        | Token ID          |
| `side`             | string        | `BUY` 或 `SELL`    |
| `size`             | string        | 交易数量              |
| `price`            | string        | 执行价格              |
| `fee_rate_bps`     | string        | 费率(基点)            |
| `status`           | string        | 交易状态(见上表)         |
| `match_time`       | string        | 匹配时的 Unix 时间戳     |
| `last_update`      | string        | 最后状态更改的 Unix 时间戳  |
| `outcome`          | string        | 人类可读的结果(例如,"Yes") |
| `maker_address`    | string        | Maker 的资金提供者地址    |
| `owner`            | string        | 交易所有者的 API key    |
| `transaction_hash` | string        | 链上交易哈希            |
| `bucket_index`     | number        | 用于交易对账的索引         |
| `trader_side`      | string        | `TAKER` 或 `MAKER` |
| `maker_orders`     | MakerOrder\[] | 填充此交易的 Maker 订单   |

<Note>
  由于 gas 限制,单笔交易可能会被拆分到多个链上交易中。使用 `bucket_index` 和 `match_time` 将相关交易对账回单个逻辑交易。
</Note>

***

## 订单评分

检查你的挂单是否符合 [maker 返利](/market-makers/maker-rebates)评分资格:

<CodeGroup>
  ```typescript TypeScript theme={null}
  // Single order
  const scoring = await client.isOrderScoring({ orderId: "0x..." });

  // Multiple orders
  const batch = await client.areOrdersScoring({
    orderIds: ["0x...", "0x..."],
  });
  ```

  ```python Python theme={null}
  from py_clob_client_v2 import OrderScoringParams, OrdersScoringParams

  scoring = client.is_order_scoring(
      OrderScoringParams(orderId="0x...")
  )

  batch = client.are_orders_scoring(
      OrdersScoringParams(orderIds=["0x...", "0x..."])
  )
  ```
</CodeGroup>

***

## 下一步

<CardGroup cols={2}>
  <Card title="订单归因" icon="tag" href="/trading/orders/attribution">
    将订单归属到你的 Builder 账户以获得交易量信用
  </Card>

  <Card title="费用" icon="receipt" href="/trading/fees">
    了解费用结构和 Maker 返利
  </Card>
</CardGroup>
