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

# Update a resting limit or stop order



## OpenAPI

````yaml /developer/trading-api/openapi.json patch /v1/{chain}/orders/{id}
openapi: 3.1.0
info:
  title: Gains Trading API
  version: 1.0.0
  description: >-
    Native REST and WebSocket API for trading on Gains Network.
    Resource-oriented, JSON in and out, decimal strings for every price and
    size, one EIP-712 signing scheme, and an order lifecycle that hides the
    oracle two-step.
servers:
  - url: https://api.gains.trade
security: []
tags:
  - name: Markets
    description: Public market data
  - name: Account
    description: 'Private reads: balances, positions, orders, fills'
  - name: Orders
    description: Place, update and cancel orders
  - name: Positions
    description: Close and manage open positions
  - name: Agents
    description: Non-custodial agent authorisation
  - name: System
    description: Health
paths:
  /v1/{chain}/orders/{id}:
    patch:
      tags:
        - Orders
      summary: Update a resting limit or stop order
      operationId: updateOrder
      parameters:
        - schema:
            type: string
            enum:
              - arbitrum
              - base
              - polygon
              - megaeth
              - arbitrum-sepolia
            example: arbitrum
          required: true
          name: chain
          in: path
        - schema:
            type: string
            example: '5316911983139663'
          required: true
          name: id
          in: path
      requestBody:
        description: Fields to change
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateOrderRequest'
      responses:
        '200':
          description: The updated order
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PreparedOrder'
        '400':
          description: Malformed request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Missing or invalid credentials
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Credentials valid but not allowed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: Domain rule rejected the request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - AgentSignature: []
components:
  schemas:
    UpdateOrderRequest:
      type: object
      properties:
        price:
          type: string
          pattern: ^-?(?:0|[1-9]\d*)(?:\.\d+)?$
          example: '0.5'
          description: Decimal number encoded as a string to preserve precision.
        size:
          type: string
          pattern: ^-?(?:0|[1-9]\d*)(?:\.\d+)?$
          example: '0.5'
          description: Decimal number encoded as a string to preserve precision.
        sl:
          type: string
          pattern: ^-?(?:0|[1-9]\d*)(?:\.\d+)?$
          example: '0.5'
          description: Decimal number encoded as a string to preserve precision.
        tp:
          type: string
          pattern: ^-?(?:0|[1-9]\d*)(?:\.\d+)?$
          example: '0.5'
          description: Decimal number encoded as a string to preserve precision.
        slippage:
          type: string
          pattern: ^-?(?:0|[1-9]\d*)(?:\.\d+)?$
          example: '0.5'
          description: Decimal number encoded as a string to preserve precision.
    PreparedOrder:
      type: object
      properties:
        order:
          $ref: '#/components/schemas/Order'
        transaction:
          anyOf:
            - $ref: '#/components/schemas/PreparedTransaction'
            - type: 'null'
          description: Null when nothing has to reach the chain for this call.
      required:
        - order
        - transaction
    Error:
      type: object
      properties:
        code:
          type: string
          enum:
            - VALIDATION_ERROR
            - UNAUTHENTICATED
            - INVALID_SIGNATURE
            - TIMESTAMP_OUT_OF_WINDOW
            - NONCE_REUSED
            - AGENT_UNKNOWN
            - API_KEY_UNKNOWN
            - AGENT_NOT_DELEGATED
            - AGENT_EXPIRED
            - AGENT_REVOKED
            - SCOPE_READ_ONLY
            - SCOPE_MARKET_NOT_ALLOWED
            - SCOPE_LEVERAGE_EXCEEDED
            - SCOPE_SPEND_CAP_EXCEEDED
            - TRADER_MISMATCH
            - CHAIN_NOT_FOUND
            - CHAIN_READ_ONLY
            - MARKET_NOT_FOUND
            - ORDER_NOT_FOUND
            - POSITION_NOT_FOUND
            - AGENT_NOT_FOUND
            - IDEMPOTENCY_CONFLICT
            - ORDER_NOT_MODIFIABLE
            - PRECISION_ERROR
            - LEVERAGE_OUT_OF_RANGE
            - SIZE_BELOW_MINIMUM
            - MARKET_CLOSED
            - COLLATERAL_NOT_SUPPORTED
            - SIMULATION_REVERTED
            - SUBMISSION_MISMATCH
            - UNSUPPORTED
            - RATE_LIMITED
            - INTERNAL
            - UPSTREAM_UNAVAILABLE
            - NOT_READY
        message:
          type: string
        details:
          type: object
          additionalProperties: {}
      required:
        - code
        - message
    Order:
      type: object
      properties:
        id:
          type: string
          pattern: ^[1-9]\d{0,15}$
          example: '5316911983139663'
          description: Order id. A decimal string that fits in a 53-bit integer.
        trader:
          type: string
          pattern: ^0x[0-9a-fA-F]{40}$
          example: '0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523'
        market:
          type: string
          pattern: ^[A-Z0-9.]{1,15}\/[A-Z0-9]{1,10}$
          example: BTC/USD
          description: Gains market symbol, `<base>/<quote>`.
        side:
          type: string
          enum:
            - long
            - short
        type:
          type: string
          enum:
            - market
            - limit
            - stop
        size:
          type: string
          pattern: ^-?(?:0|[1-9]\d*)(?:\.\d+)?$
          example: '0.5'
          description: Decimal number encoded as a string to preserve precision.
        price:
          type:
            - string
            - 'null'
          pattern: ^-?(?:0|[1-9]\d*)(?:\.\d+)?$
          example: '0.5'
          description: Decimal number encoded as a string to preserve precision.
        leverage:
          type: string
          pattern: ^-?(?:0|[1-9]\d*)(?:\.\d+)?$
          example: '0.5'
          description: Decimal number encoded as a string to preserve precision.
        collateral:
          type: string
        sl:
          type:
            - string
            - 'null'
          pattern: ^-?(?:0|[1-9]\d*)(?:\.\d+)?$
          example: '0.5'
          description: Decimal number encoded as a string to preserve precision.
        tp:
          type:
            - string
            - 'null'
          pattern: ^-?(?:0|[1-9]\d*)(?:\.\d+)?$
          example: '0.5'
          description: Decimal number encoded as a string to preserve precision.
        reduceOnly:
          type: boolean
        slippage:
          type: string
          pattern: ^-?(?:0|[1-9]\d*)(?:\.\d+)?$
          example: '0.5'
          description: Decimal number encoded as a string to preserve precision.
        clientId:
          type:
            - string
            - 'null'
        status:
          type: string
          enum:
            - prepared
            - pending
            - open
            - filled
            - rejected
            - timed_out
            - canceled
            - expired
        txHash:
          type:
            - string
            - 'null'
          pattern: ^0x[0-9a-fA-F]*$
          example: '0xabc123'
        expiresAt:
          type:
            - integer
            - 'null'
          description: >-
            For prepared orders, when the prepared transaction stops being
            valid.
        fill:
          anyOf:
            - $ref: '#/components/schemas/Fill'
            - type: 'null'
        reason:
          type:
            - string
            - 'null'
          enum:
            - NONE
            - PAUSED
            - MARKET_CLOSED
            - SLIPPAGE
            - TP_REACHED
            - SL_REACHED
            - EXPOSURE_LIMITS
            - PRICE_IMPACT
            - MAX_LEVERAGE
            - NO_TRADE
            - WRONG_TRADE
            - NOT_HIT
            - LIQ_REACHED
            - OTHER
            - null
        createdAt:
          type: integer
        updatedAt:
          type: integer
      required:
        - id
        - trader
        - market
        - side
        - type
        - size
        - price
        - leverage
        - collateral
        - sl
        - tp
        - reduceOnly
        - slippage
        - clientId
        - status
        - txHash
        - expiresAt
        - fill
        - reason
        - createdAt
        - updatedAt
    PreparedTransaction:
      type: object
      properties:
        to:
          type: string
          pattern: ^0x[0-9a-fA-F]{40}$
          example: '0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523'
        data:
          type: string
          pattern: ^0x[0-9a-fA-F]*$
          example: '0xabc123'
        value:
          type: string
          enum:
            - '0'
        chainId:
          type: integer
        gas:
          type:
            - string
            - 'null'
          description: >-
            Gas estimate from the agent's account, null when it could not be
            estimated.
        expiresAt:
          type: integer
          description: Unix ms; re-prepare after this.
      required:
        - to
        - data
        - value
        - chainId
        - gas
        - expiresAt
      description: >-
        A transaction for the agent to sign and broadcast: the Diamond as `to`,
        zero value, no sender or nonce (the wallet fills them).
    Fill:
      type: object
      properties:
        price:
          type: string
          pattern: ^-?(?:0|[1-9]\d*)(?:\.\d+)?$
          example: '0.5'
          description: Decimal number encoded as a string to preserve precision.
        size:
          type: string
          pattern: ^-?(?:0|[1-9]\d*)(?:\.\d+)?$
          example: '0.5'
          description: Decimal number encoded as a string to preserve precision.
        collateral:
          type: string
          pattern: ^-?(?:0|[1-9]\d*)(?:\.\d+)?$
          example: '0.5'
          description: Decimal number encoded as a string to preserve precision.
        feeCollateral:
          type: string
          pattern: ^-?(?:0|[1-9]\d*)(?:\.\d+)?$
          example: '0.5'
          description: Decimal number encoded as a string to preserve precision.
        txHash:
          type: string
          pattern: ^0x[0-9a-fA-F]*$
          example: '0xabc123'
        timestamp:
          type: integer
        positionId:
          type:
            - string
            - 'null'
          pattern: ^[1-9]\d{0,15}$
          example: '5316911983139663'
          description: Order id. A decimal string that fits in a 53-bit integer.
      required:
        - price
        - size
        - collateral
        - feeCollateral
        - txHash
        - timestamp
        - positionId
  securitySchemes:
    AgentSignature:
      type: apiKey
      in: header
      name: X-Gains-Signature
      description: >-
        EIP-712 signature by an authorised agent over {method, path, body,
        timestamp, nonce}, sent with X-Gains-Agent, X-Gains-Timestamp and
        X-Gains-Nonce.

````