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

# private/batch_order

> Places, replaces and cancels orders for one subaccount in a single request. `orders` holds post-only limit orders and `cancels` holds open orders to cancel, each by order_id and instrument_name; together they hold 1 to 1000 items. Each order is a signed private/order payload; an order that also sets order_id_to_cancel or nonce_to_cancel replaces that open order, which must be on the same instrument. Every order must use the batch subaccount_id, the same signer, time_in_force post_only and order_type limit, with no trigger or algo fields, reduce_only or is_atomic_signing. The batch is checked as a whole first, including margin for all of its orders together; open orders that it cancels or replaces do not count. If a check fails, no order is placed or cancelled, and the error data names the failing order as `index=<n>` or the failing cancel as `cancel index=<n>`. A batch of cancels alone has no margin check. Otherwise, on each instrument the cancels apply before the orders. Returns one result per order with its nonce, order_id, status (open, rejected with its error, or pending if it had no result yet), final limit_price and cancelled_order_id, and one result per cancel with its order_id and status (cancelled, rejected with its error, or pending). A cancel of an order that is not open on the named instrument is rejected and does not affect the rest of the batch. A replace cancels its old order even when the new order is then rejected. A batch costs 50 matching rate-limit points, whatever its size. A batch refused for lack of points costs nothing. Requires Orderbook trade scope for the instrument of every order; a batch of cancels alone requires any trade scope.



## OpenAPI

````yaml /openapi.json post /private/batch_order
openapi: 3.1.0
info:
  title: Derive v3 API
  version: 0.2.0
  description: JSON-RPC 2.0 methods, served over WebSocket and HTTP POST.
servers:
  - url: https://api.derive.xyz/v3
    description: Production (HTTP POST base)
  - url: https://testnet.api.derive.xyz/v3
    description: Testnet (HTTP POST base)
security: []
tags:
  - name: Subaccounts
    description: >-
      List, inspect, and label subaccounts, portfolios, positions, and
      collateral.
  - name: Session Keys
    description: Register, edit, and list delegated signing keys.
  - name: Account
    description: Wallet-level account information and settings.
  - name: Orderbook
    description: Place, replace, cancel, and query orders, trigger orders, and algos.
  - name: RFQ
    description: 'Request-for-quote: send RFQs, quote, and execute block trades.'
  - name: Liquidations
    description: >-
      Open a Dutch auction against a breaching subaccount, quote the auctions
      running right now, bid on them, and review past ones.
  - name: Vault Shareholders
    description: >-
      Deposit into and withdraw from vaults, and track shares, requests, and
      performance.
  - name: Vault Curators
    description: >-
      Create and operate curated vaults: settle deposit and withdrawal requests,
      and manage vault metadata.
  - name: History
    description: >-
      Per-account historical records: orders, trades, transfers, and
      settlements.
  - name: Market Maker Protection
    description: Configure, read, and reset market-maker protection.
  - name: Transfers & Withdrawals
    description: Move collateral between subaccounts, to other wallets, and on-chain.
  - name: Onchain Actions
    description: >-
      L1 onchain actions submitted via OnchainActionManager: register deposit
      addresses, list pending deposits, and inspect onchain action history.
  - name: System
    description: Rate limits, transaction lookups, and live incidents.
  - name: Market Data
    description: Instruments, currencies, tickers, and market-wide feeds.
  - name: Maker Scoring
    description: Maker programs, score breakdowns, and detailed scoring snapshots.
  - name: Referrals
    description: Referral codes and program performance.
  - name: Other
    description: Uncategorized.
paths:
  /private/batch_order:
    post:
      tags:
        - Orderbook
      summary: private/batch_order
      description: >-
        Places, replaces and cancels orders for one subaccount in a single
        request. `orders` holds post-only limit orders and `cancels` holds open
        orders to cancel, each by order_id and instrument_name; together they
        hold 1 to 1000 items. Each order is a signed private/order payload; an
        order that also sets order_id_to_cancel or nonce_to_cancel replaces that
        open order, which must be on the same instrument. Every order must use
        the batch subaccount_id, the same signer, time_in_force post_only and
        order_type limit, with no trigger or algo fields, reduce_only or
        is_atomic_signing. The batch is checked as a whole first, including
        margin for all of its orders together; open orders that it cancels or
        replaces do not count. If a check fails, no order is placed or
        cancelled, and the error data names the failing order as `index=<n>` or
        the failing cancel as `cancel index=<n>`. A batch of cancels alone has
        no margin check. Otherwise, on each instrument the cancels apply before
        the orders. Returns one result per order with its nonce, order_id,
        status (open, rejected with its error, or pending if it had no result
        yet), final limit_price and cancelled_order_id, and one result per
        cancel with its order_id and status (cancelled, rejected with its error,
        or pending). A cancel of an order that is not open on the named
        instrument is rejected and does not affect the rest of the batch. A
        replace cancels its old order even when the new order is then rejected.
        A batch costs 50 matching rate-limit points, whatever its size. A batch
        refused for lack of points costs nothing. Requires Orderbook trade scope
        for the instrument of every order; a batch of cancels alone requires any
        trade scope.
      operationId: private_batch_order
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BatchOrderRequest'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BatchOrderResponse'
        default:
          description: JSON-RPC error (see Error Codes)
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    $ref: '#/components/schemas/RPCError'
      security:
        - DeriveWallet: []
          DeriveTimestamp: []
          DeriveSignature: []
components:
  schemas:
    BatchOrderRequest:
      description: '`private/batch_order` params.'
      type: object
      required:
        - subaccount_id
      properties:
        cancels:
          description: >-
            Open orders to cancel. `orders` and `cancels` hold 1 to 1000 items
            in total.
          type: array
          items:
            $ref: '#/components/schemas/BatchCancelRequest'
        orders:
          description: >-
            Post-only limit orders, all with the same signer. An order with
            `order_id_to_cancel` or `nonce_to_cancel` replaces that order.
          type: array
          items:
            $ref: '#/components/schemas/ReplaceOrderRequest'
        subaccount_id:
          type: integer
          format: int64
    BatchOrderResponse:
      type: object
      required:
        - cancels
        - orders
      properties:
        cancels:
          type: array
          items:
            $ref: '#/components/schemas/BatchCancelResult'
        orders:
          type: array
          items:
            $ref: '#/components/schemas/BatchOrderResult'
    RPCError:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int64
        data:
          type:
            - string
            - 'null'
        message:
          type: string
    BatchCancelRequest:
      description: An open order of the batch subaccount to cancel.
      type: object
      required:
        - instrument_name
        - order_id
      properties:
        instrument_name:
          type: string
        order_id:
          description: UUID v4 string
          type: string
          format: uuid
    ReplaceOrderRequest:
      description: >-
        `private/replace` parameters: a `private/order` payload plus the
        cancel-target fields (`order_id_to_cancel`, `nonce_to_cancel`,
        `expected_filled_amount`).
      type: object
      required:
        - amount
        - direction
        - instrument_name
        - limit_price
        - max_fee
        - nonce
        - signature
        - signature_expiry_sec
        - signer
        - subaccount_id
      properties:
        algo_duration_sec:
          default: null
          type:
            - integer
            - 'null'
          format: int32
        algo_num_slices:
          default: null
          type:
            - integer
            - 'null'
          format: int32
        algo_type:
          default: null
          anyOf:
            - $ref: '#/components/schemas/AlgoType'
            - type: 'null'
        amount:
          description: >-
            Order amount in units of the base, as a decimal string (e.g.
            `"1.5"`) or a JSON number.
          type: string
          format: decimal
        client:
          default: null
          type:
            - string
            - 'null'
        direction:
          $ref: '#/components/schemas/Direction'
        expected_filled_amount:
          description: >-
            Optional decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits, or null; a string or JSON number is accepted
          default: null
          type:
            - string
            - 'null'
          format: decimal
        extra_fee:
          description: >-
            Optional builder fee for the whole order, in USDC, as a decimal
            string or JSON number. Each fill pays its pro-rata share. Defaults
            to zero.
          default: null
          type:
            - string
            - 'null'
          format: decimal
        instrument_name:
          type: string
        is_atomic_signing:
          default: null
          type:
            - boolean
            - 'null'
        label:
          default: null
          type:
            - string
            - 'null'
        limit_price:
          description: >-
            Limit price in quote currency, as a decimal string (e.g. `"3100.5"`)
            or a JSON number.
          type: string
          format: decimal
        max_fee:
          description: >-
            Max fee per unit of volume in quote currency, as a decimal string or
            a JSON number.
          type: string
          format: decimal
        mmp:
          description: >-
            Tags the order for market maker protection. Only tagged orders are
            cancelled by cancel on disconnect.
          default: null
          type:
            - boolean
            - 'null'
        nonce:
          type: string
        nonce_to_cancel:
          default: null
          type:
            - string
            - 'null'
        order_id_to_cancel:
          description: Optional UUID v4 string
          default: null
          type:
            - string
            - 'null'
          format: uuid
        order_type:
          $ref: '#/components/schemas/OrderType'
          default: limit
        reduce_only:
          default: null
          type:
            - boolean
            - 'null'
        referral_code:
          default: null
          type:
            - string
            - 'null'
        reject_post_only:
          default: null
          type:
            - boolean
            - 'null'
        reject_timestamp:
          default: null
          type:
            - integer
            - 'null'
          format: int64
        signature:
          type: string
        signature_expiry_sec:
          type: integer
          format: int64
        signer:
          type: string
        subaccount_id:
          type: integer
          format: int64
        time_in_force:
          $ref: '#/components/schemas/TimeInForce'
          default: gtc
        trigger_price:
          description: >-
            Trigger price as a decimal string or JSON number; omit for
            non-trigger orders.
          default: null
          type:
            - string
            - 'null'
          format: decimal
        trigger_price_type:
          default: null
          anyOf:
            - $ref: '#/components/schemas/TriggerPriceType'
            - type: 'null'
        trigger_type:
          default: null
          anyOf:
            - $ref: '#/components/schemas/TriggerType'
            - type: 'null'
    BatchCancelResult:
      type: object
      required:
        - order_id
        - status
      properties:
        error:
          anyOf:
            - $ref: '#/components/schemas/RPCError'
            - type: 'null'
        order_id:
          description: UUID v4 string
          type: string
          format: uuid
        status:
          $ref: '#/components/schemas/BatchCancelStatus'
    BatchOrderResult:
      type: object
      required:
        - cancelled_order_id
        - limit_price
        - nonce
        - order_id
        - status
      properties:
        cancelled_order_id:
          description: Optional UUID v4 string
          type:
            - string
            - 'null'
          format: uuid
        error:
          anyOf:
            - $ref: '#/components/schemas/RPCError'
            - type: 'null'
        limit_price:
          description: >-
            Final limit price of the order; a post-only order sent with
            `reject_post_only: false` can rest at a price other than the signed
            one.
          type:
            - string
            - 'null'
          format: decimal
        nonce:
          type: string
        order_id:
          description: Optional UUID v4 string
          type:
            - string
            - 'null'
          format: uuid
        status:
          $ref: '#/components/schemas/BatchOrderStatus'
    AlgoType:
      type: string
      enum:
        - twap
    Direction:
      type: string
      enum:
        - buy
        - sell
    OrderType:
      type: string
      enum:
        - limit
        - market
    TimeInForce:
      type: string
      enum:
        - gtc
        - post_only
        - fok
        - ioc
    TriggerPriceType:
      type: string
      enum:
        - mark
        - index
    TriggerType:
      type: string
      enum:
        - stoploss
        - takeprofit
    BatchCancelStatus:
      oneOf:
        - type: string
          enum:
            - cancelled
        - description: The order was not cancelled; `error` gives the reason.
          type: string
          enum:
            - rejected
        - description: The cancel had no result yet when the response was sent.
          type: string
          enum:
            - pending
    BatchOrderStatus:
      oneOf:
        - description: The order rests on the book.
          type: string
          enum:
            - open
        - description: The order was not placed; `error` gives the reason.
          type: string
          enum:
            - rejected
        - description: The order had no result yet when the response was sent.
          type: string
          enum:
            - pending
  securitySchemes:
    DeriveWallet:
      type: apiKey
      in: header
      name: X-DeriveWallet
      description: The wallet the request acts for.
    DeriveTimestamp:
      type: apiKey
      in: header
      name: X-DeriveTimestamp
      description: The current time in milliseconds, as a decimal string.
    DeriveSignature:
      type: apiKey
      in: header
      name: X-DeriveSignature
      description: >-
        EIP-191 signature of the timestamp, by the wallet or one of its session
        keys.

````

## Related topics

- [private/order](https://docs.derive.xyz/api-reference/orderbook/privateorder.md)
- [private/get_order](https://docs.derive.xyz/api-reference/orderbook/privateget_order.md)
- [private/order_debug](https://docs.derive.xyz/api-reference/orderbook/privateorder_debug.md)


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