> ## 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.

# Editar uma ordem

> Muda o preço ou o volume de uma ordem em aberto

Muda o preço (`orderOdds`) e/ou o volume (`orderVolume`) de uma ordem **limit** existente.

Em ordens parcialmente casadas, a 4casters cancela a ordem existente e envia uma nova com os valores indicados. O novo `orderVolume` **não** desconta o volume já casado: se você originalmente colocou `bet: 10`, $5 casaram e você edita para `orderVolume: 10`, a ordem anterior é cancelada (reembolsando $5) e uma nova é criada por $10 (debitando $10), deixando você com \$5 líquidos a menos.

> [!NOTE]
>
> Existe uma variante gRPC mais recente em `POST /session/v4/editOrder`. Ela aceita o mesmo corpo de requisição e também retorna `errorType` em falhas de validação. Prefira-a em integrações novas quando você tiver confirmado que a forma funciona para você.

## Requisição

`POST /session/editOrder`

**sessionID** `string` *required*

Id da ordem a editar. Obtenha-o de `data.unmatched.orderID` de `/session/v3/place` ou de `id` de `/user/getUnmatched`.

**orderOdds** `integer`

Novas odds americanas. Passe `null` para deixar as odds sem alteração.

**orderVolume** `number`

Novo valor de `bet`. Passe `null` para deixar o volume sem alteração.

**orderType** `string`

O valor padrão é `limit`. Consulte [tipos de ordem](https://docs.4casters.io/pt-BR/pages/rest/orders/place-order.md#order-types).

**userReference** `string`

Opcional. Substitui o `userReference` existente da ordem.

**intendedOrderVolume** `number`

Opcional. O volume que você originalmente pretendia colocar; o servidor o usa ao conciliar casamentos parciais.

**expiryChange** `string`

Opcional. Nova expiração em minutos (string).

**blockIfNoOtherSideOrders** `boolean`

Somente v4. Rejeita a edição se não houver liquidez em aberto do lado contrário.

```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 Corpo JSON theme={null}
{
  "sessionID": "6549b6df6634097d2704716f",
  "orderOdds": 185,
  "orderVolume": 100
}
```

## Resposta

O resultado reflete a forma de resposta de [enviar ordens](https://docs.4casters.io/pt-BR/pages/rest/orders/place-order.md#response): um resumo `cancelled` mais o resultado novo `matched` / `unmatched`:

**data.cancelled** `object`

Resumo da ordem original cancelada e substituída.

**data.matched** `array`

Casamentos produzidos ao reenviar ao novo preço/volume. Mesma forma que um `MatchedFill` em [enviar ordens](https://docs.4casters.io/pt-BR/pages/rest/orders/place-order.md#response).

**data.unmatched** `object`

Oferta em aberto do restante não casado da nova ordem.

## Erros

| Status | Significado |
| - | - |
| `400` | Erro de validação (`v4/editOrder` retorna `errorType` nesses casos). |
| `503` | O serviço de ordens não está disponível. |


## 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.