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

# 修改訂單

> 更改掛單的價格或數量

更改現有 **limit** 訂單的價格（`orderOdds`）和/或數量（`orderVolume`）。

對於部分成交的訂單，4casters 會取消現有訂單並按所提供的值提交一筆新訂單。新的 `orderVolume` **不會**計入此前已成交的數量 — 如果你最初下單 `bet: 10`，其中 $5 已成交，然後改單為 `orderVolume: 10`，則原訂單被取消（退回 $5），並建立一筆 $10 的新訂單（扣款 $10），淨效果是你少了 \$5。

<Note>
  更新的 gRPC 變體位於 `POST /session/v4/editOrder`。它接受相同的請求主體，並在校驗失敗時額外回傳 `errorType`。確認形態適合你後，新整合請優先使用它。
</Note>

<h2 id="request">
  請求
</h2>

`POST /session/editOrder`

<ParamField body="sessionID" type="string" required>
  要修改的訂單 ID。可從 `/session/v3/place` 的 `data.unmatched.orderID` 或 `/user/getUnmatched` 的 `id` 獲取。
</ParamField>

<ParamField body="orderOdds" type="integer">
  新的美式賠率。傳 `null` 表示賠率不變。
</ParamField>

<ParamField body="orderVolume" type="number">
  新的 `bet` 金額。傳 `null` 表示數量不變。
</ParamField>

<ParamField body="orderType" type="string">
  預設為 `limit`。見 [訂單型別](/zh-Hant/pages/rest/orders/place-order#order-types)。
</ParamField>

<ParamField body="userReference" type="string">
  可選。替換訂單上現有的 `userReference`。
</ParamField>

<ParamField body="intendedOrderVolume" type="number">
  可選。你最初打算下單的數量；伺服器在對帳部分成交時使用。
</ParamField>

<ParamField body="expiryChange" type="string">
  可選。新的過期時間（分鐘，字串）。
</ParamField>

<ParamField body="blockIfNoOtherSideOrders" type="boolean">
  僅 v4。若對面沒有掛單流動性，則拒絕此次改單。
</ParamField>

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://api.4casters.io/session/editOrder \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "sessionID": "6549b6df6634097d2704716f",
      "orderOdds": 185,
      "orderVolume": 100
    }'
  ```

  ```json JSON 請求主體 theme={null}
  {
    "sessionID": "6549b6df6634097d2704716f",
    "orderOdds": 185,
    "orderVolume": 100
  }
  ```
</CodeGroup>

<h2 id="response">
  回應
</h2>

結果鏡像 [下單](/zh-Hant/pages/rest/orders/place-order#response) 的回應形態 — 一個 `cancelled` 彙總，加上新的 `matched` / `unmatched` 結果：

<ResponseField name="data.cancelled" type="object">
  被取消並替換的原訂單彙總。
</ResponseField>

<ResponseField name="data.matched" type="array">
  按新價格/數量重新提交所產生的成交。形態與 [下單](/zh-Hant/pages/rest/orders/place-order#response) 中的 `MatchedFill` 相同。
</ResponseField>

<ResponseField name="data.unmatched" type="object">
  新訂單未成交剩餘部分的掛單。
</ResponseField>

<h2 id="errors">
  錯誤
</h2>

| 狀態 | 含義 |
| - | - |
| `400` | 校驗錯誤（`v4/editOrder` 會為這些錯誤回傳 `errorType`）。 |
| `503` | 訂單服務不可達。 |


## OpenAPI

````yaml POST /session/editOrder
openapi: 3.1.0
info:
  title: 4casters REST API
  version: 1.0.0
  description: >-
    Public REST API for the 4casters peer-to-peer betting exchange. Use this API
    to manage your account, query the orderbook and games, and place / edit /
    cancel orders.


    All responses (unless noted otherwise) are JSON envelopes of the form `{
    "data": ... }`.
  contact:
    name: 4casters
    url: https://4casters.io
servers:
  - url: https://api.4casters.io
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Authentication
    description: Login and account session management
  - name: User
    description: Read account info, bets, and orders
  - name: Orders
    description: Place, edit, look up, and cancel orders
  - name: Markets
    description: Browse leagues, games, participants, and orderbooks
  - name: Affiliate
    description: Affiliate / referral commission
paths:
  /session/editOrder:
    post:
      tags:
        - Orders
      summary: Edit an order
      description: >-
        Change the price (`orderOdds`) and/or volume (`orderVolume`) of an
        existing **limit** order. For partially filled orders, 4casters cancels
        the existing order and submits a new one with the supplied values; the
        new `orderVolume` does **not** account for previously filled volume.


        The newer gRPC variant `POST /session/v4/editOrder` accepts the same
        body shape and also returns `errorType` on validation failures.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EditOrderRequest'
            example:
              sessionID: 6549b6df6634097d2704716f
              orderOdds: 185
              orderVolume: 100
      responses:
        '200':
          description: >-
            Edit result. Mirrors the place-order response shape: a `cancelled`
            summary plus the new `matched` / `unmatched` outcome.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/EditOrderResult'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '503':
          description: Orders service unreachable
components:
  schemas:
    EditOrderRequest:
      type: object
      required:
        - sessionID
      properties:
        sessionID:
          type: string
          description: Order id to edit.
        orderOdds:
          type: integer
          nullable: true
          description: New American odds. Pass `null` to leave odds unchanged.
        orderVolume:
          type: number
          nullable: true
          description: >-
            New `bet` amount. Pass `null` to leave volume unchanged. **Does
            not** account for previously-filled volume.
        orderType:
          $ref: '#/components/schemas/OrderType'
        userReference:
          type: string
        intendedOrderVolume:
          type: number
          description: >-
            Optional. The volume you originally intended to place; used by the
            server when reconciling partial fills.
        expiryChange:
          type: string
          description: Optional. New expiration in minutes (string).
        blockIfNoOtherSideOrders:
          type: boolean
          description: >-
            v4 only. Reject the edit if there is no resting opposite-side
            liquidity.
    EditOrderResult:
      type: object
      properties:
        cancelled:
          type: object
          description: Summary of the cancelled-and-replaced original order.
        matched:
          type: array
          items:
            $ref: '#/components/schemas/MatchedFill'
        unmatched:
          $ref: '#/components/schemas/UnmatchedOffer'
    OrderType:
      type: string
      enum:
        - limit
        - post
        - postArb
        - fillAndKill
        - fillOrKill
      description: >-
        Order placement strategy.


        - `limit` — default. Match against any liquidity at your price or better
        as a taker, rest the remainder as a maker.

        - `post`  — guarantee maker. Reject if the order would match resting
        liquidity.

        - `postArb` — like `post`, but allowed to match if the matched odds are
        within 1% of yours, avoiding taker fees.

        - `fillAndKill` — guarantee taker. Match whatever size is available at
        your price or better and cancel the remainder; never rests. A partial
        fill is a success; rejected only when there is no matchable liquidity at
        all.

        - `fillOrKill` — all-or-nothing taker. Match the entire `bet`
        immediately or the whole order is rejected and any partial fills are
        rolled back; never rests.
    MatchedFill:
      type: object
      description: A portion of an order that matched against existing liquidity.
      properties:
        amount:
          type: number
          description: Stake on the matched portion.
        odds:
          type: integer
          description: American odds of the fill.
        number:
          type: number
          nullable: true
          description: Spread or total of the fill (`null` for moneylines).
        type:
          $ref: '#/components/schemas/MarketType'
        side:
          $ref: '#/components/schemas/MarketSide'
        market:
          type: string
          description: Present for `moneyline1x2`.
        orderID:
          type: string
          description: Order id of the matched offer on the other side.
        txID:
          type: string
          description: Transaction id of the fill.
        wagerRequestID:
          type: string
          description: >-
            Server-generated id grouping every fill / offer derived from the
            input order.
        userReference:
          type: string
        risk:
          type: number
        win:
          type: number
          description: Win amount, net of taker commission.
        winWithoutCommission:
          type: number
          description: Win amount before commission.
    UnmatchedOffer:
      type: object
      description: >-
        Resting offer created from the unfilled remainder of a place request.
        May be empty (`{}`) when the order matched fully.
      properties:
        orderID:
          type: string
          description: Id of the new resting order.
        wagerRequestID:
          type: string
        offered:
          type: number
        odds:
          type: integer
        type:
          $ref: '#/components/schemas/MarketType'
        side:
          $ref: '#/components/schemas/MarketSide'
        market:
          type: string
          description: Present for `moneyline1x2`.
        number:
          type: number
          nullable: true
        userReference:
          type: string
    HttpError:
      type: object
      properties:
        error:
          type: string
          description: Human-readable error message.
    MarketType:
      type: string
      enum:
        - moneyline
        - spread
        - total
        - moneyline1x2
      description: >-
        Market type. `moneyline1x2` is **soccer-only** (three-way money line:
        home / away / draw).
    MarketSide:
      type: string
      description: |-
        Order side. Meaning depends on `type`:

        - `moneyline`, `spread` — the participant id you are backing.
        - `total` — `"over"` or `"under"`.
        - `moneyline1x2` — `"yes"` or `"no"` on the outcome named by `market`.
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/HttpError'
    Unauthorized:
      description: Missing or invalid auth token
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Pass your auth token in the `Authorization` header. The `Bearer` prefix
        is optional; the server also accepts a signed `auth` cookie or a `token`
        field in the request body.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.