# Create Order

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /v1/account/orders:
    post:
      summary: Create Order
      deprecated: false
      description: >
        ## Create a New Order


        :::warning[]

        Ensure your API key has the `TRADE` scope. You can generate an API key
        through the One Trading UI.

        :::


        This endpoint is rate-limited per account holder (see `429`).


        This endpoint allows you to create a new order of type **LIMIT**.


        ### Time in Force Options

        For **LIMIT** orders, you can specify one of the following
        `time_in_force` options:

        - **GOOD_TILL_CANCELLED** (default): The order remains open until
        canceled.

        - **IMMEDIATE_OR_CANCELLED**: The order is filled immediately, either in
        full or partially, with any unfilled portion canceled.

        - **FILL_OR_KILL**: The order must be filled in full immediately;
        otherwise, it is canceled.

        - **POST_ONLY**: Ensures the order is added to the order book as a maker
        order and will be rejected if it would execute immediately as a taker
        order.


        If no `time_in_force` is specified, **GOOD_TILL_CANCELLED** is assumed.


        ### Order Size and Precision

        Each order must meet a minimum size requirement. You can retrieve this
        minimum, along with precision limitations, by querying the
        `/instruments` endpoint.


        **Note:** There is a global limit of 200 open orders per user across all
        markets.


        ### Client ID for Order Tracking

        Optionally, you can set a `client_id` to track orders without waiting
        for the assigned `order_id`.


        **Important:** You are responsible for ensuring the uniqueness of each
        `client_id`. If multiple orders share the same `client_id`, only the
        newest order can be canceled via `client_id`; older orders will require
        the specific `order_id` or use of the "Cancel All Orders" endpoint.


        ### Take Profit / Stop Loss

        You can attach a take profit and/or stop loss (TP/SL) to the order. It
        is held in a separate service, not on the exchange itself, and when the
        price reaches a level, a reduce-only limit order is placed on the
        exchange to close for you.


        - `take_profit` and `stop_loss` are each `{ "value": "<price>", "type":
        "MID" | "BBO" }` (`type` defaults to `MID`). Send at least one.

        - `tpsl_mode` is required with them. `order` closes this order's filled
        amount. `position` closes the whole position on the instrument, as it is
        when the level is reached (futures only).

        - `tpsl_force: true`, in position mode, replaces the instrument's
        existing position TP/SL. Without it a second position TP/SL is refused
        with `POSITION_TPSL_EXISTS`.

        - `tpsl_slippage_bps` bounds the price of the close: a limit order at
        the level less the slippage when selling, or plus it when buying.
        Defaults to 500 (5%), or the instrument's price collar if that is less.


        The TP/SL is registered under the order's `client_id` before the order
        is placed, and is `PENDING` until the order fills:


        - When the order first fills, the TP/SL becomes `ACTIVE`. A position
        TP/SL sent with `tpsl_force` replaces the existing one at that moment,
        not before: until then the existing one stays `ACTIVE`.

        - If the order is rejected, or is cancelled or closes without a fill,
        the TP/SL is cancelled with it.

        - If a level has already been reached when the TP/SL becomes `ACTIVE`,
        it could never fire, so it is cancelled instead
        (`VALIDATION_FAILED_AT_ACTIVATION`).

        - Once `ACTIVE`, the TP/SL no longer depends on the order: cancelling
        what is left of the order, or Cancel All Orders, leaves it in place. It
        ends when a level fires, when you cancel it, or when its position is
        closed or flips.


        A TP/SL is not an exchange order, so it does not appear in Get Orders.
        Read it back with [Get Exotic Orders
        (TP/SL)](https://docs.onetrading.com/get-exotic-orders-tpsl-4589055e0.md),
        change its levels with [Update Exotic Order
        (TP/SL)](https://docs.onetrading.com/update-exotic-order-tpsl-4589057e0.md)
        and cancel it with [Cancel Exotic Order
        (TP/SL)](https://docs.onetrading.com/cancel-exotic-order-tpsl-4589058e0.md):
        by the order's `client_id`, or for a position TP/SL by
        `instrument_code`. To add one to an order or position you already have,
        use [Create Exotic Order
        (TP/SL)](https://docs.onetrading.com/create-exotic-order-tpsl-4589056e0.md).
        Every change of state is sent on the WebSocket `ACCOUNT` channel.


        A TP/SL that is not accepted rejects the whole request and the order is
        not placed: see `400`, `409`, `410` and `503`.
      tags:
        - One Trading Public REST API/Trading
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateOrder'
      responses:
        '200':
          x-apidog-name: Success
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  order_id:
                    type: string
                    format: uuid
                  client_id:
                    type: string
                    format: uuid
                  account_id:
                    type: string
                    format: uuid
                  instrument_code:
                    type: string
                  time:
                    type: string
                    format: date-time
                  side:
                    type: string
                    enum:
                      - BUY
                      - SELL
                    x-apidog-enum:
                      - value: BUY
                        name: ''
                        description: ''
                      - value: SELL
                        name: ''
                        description: ''
                  price:
                    type: string
                  amount:
                    type: string
                  type:
                    type: string
                    enum:
                      - LIMIT
                    x-apidog-enum:
                      - value: LIMIT
                        name: ''
                        description: ''
                  time_in_force:
                    type: string
                    enum:
                      - GOOD_TILL_CANCELLED
                      - IMMEDIATE_OR_CANCELLED
                      - FILL_OR_KILL
                      - POST_ONLY
                    x-apidog-enum:
                      - value: GOOD_TILL_CANCELLED
                        name: ''
                        description: ''
                      - value: IMMEDIATE_OR_CANCELLED
                        name: ''
                        description: ''
                      - value: FILL_OR_KILL
                        name: ''
                        description: ''
                      - value: POST_ONLY
                        name: ''
                        description: ''
                    description: >-
                      The time in force applied to the order (the requested
                      value, or GOOD_TILL_CANCELLED by default)
                  status:
                    type: string
                    description: >-
                      Status reported by the exchange when the order was
                      accepted, e.g. OPEN, FILL or FILLED_FULLY. Rejections are
                      returned as `422` instead.
                x-apidog-orders:
                  - order_id
                  - client_id
                  - account_id
                  - instrument_code
                  - time
                  - side
                  - price
                  - amount
                  - type
                  - time_in_force
                  - status
                required:
                  - order_id
                  - client_id
                  - account_id
                  - instrument_code
                  - time
                  - side
                  - price
                  - amount
                  - type
                  - time_in_force
                  - status
                x-apidog-ignore-properties: []
              example:
                order_id: dc3239e2-e808-433a-8875-12ab7c537ce4
                client_id: 58503f2b-ca87-4816-9338-93c443e6fdde
                account_id: 726288e6-a463-4f88-9068-024ae8f97a34
                instrument_code: SOL_EUR
                time: '2024-11-14T14:36:36.286Z'
                side: SELL
                price: '150'
                amount: '1'
                type: LIMIT
                time_in_force: GOOD_TILL_CANCELLED
                status: OPEN
          headers: {}
        '400':
          x-apidog-name: Bad Request
          description: >-
            The request was invalid. Order validation errors return a message in
            `error`; take profit / stop loss errors return a code in `error`
            with `error_message`.
          content:
            application/json:
              schema: &ref_0
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                '2':
                  summary: Invalid JSON
                  value:
                    error: Invalid JSON.
                '3':
                  summary: Invalid instrument
                  value:
                    error: Invalid instrument code.
                '4':
                  summary: Invalid side
                  value:
                    error: Invalid side.
                '5':
                  summary: Invalid type
                  value:
                    error: Invalid type.
                '6':
                  summary: Invalid amount
                  value:
                    error: Invalid amount.
                '7':
                  summary: Invalid amount precision
                  value:
                    error: Invalid amount precision.
                '8':
                  summary: Invalid price
                  value:
                    error: Invalid price.
                '9':
                  summary: Invalid price precision
                  value:
                    error: Invalid price precision.
                '10':
                  summary: Price too low
                  value:
                    error: Price too low.
                '11':
                  summary: Price too high
                  value:
                    error: Price too high.
                '12':
                  summary: Invalid time in force
                  value:
                    error: Invalid time in force.
                '13':
                  summary: Invalid client ID
                  value:
                    error: Invalid client ID.
                '14':
                  summary: Client ID not v4
                  value:
                    error: Client ID must be a v4 UUID.
                '15':
                  summary: Invalid take profit
                  value:
                    error: INVALID_TAKE_PROFIT
                    error_message: >-
                      take_profit must be an object with a positive decimal
                      string value no greater than 9007199254740991 and a type
                      of MID or BBO
                '16':
                  summary: Missing TP/SL
                  value:
                    error: MISSING_TP_SL
                    error_message: At least one of take_profit or stop_loss must be provided
                '17':
                  summary: Invalid TP/SL mode
                  value:
                    error: INVALID_TPSL_MODE
                    error_message: tpsl_mode must be order or position
                '18':
                  summary: Invalid TP/SL slippage
                  value:
                    error: INVALID_TPSL_SLIPPAGE_BPS
                    error_message: tpsl_slippage_bps must be an integer from 1 to 9999
                '19':
                  summary: TP/SL slippage over the price collar
                  value:
                    error: SLIPPAGE_ABOVE_PRICE_COLLAR
                    error_message: >-
                      The slippage is over the instrument's price collar, so the
                      close could never place (maximum 1000 bps)
                '20':
                  summary: TP/SL close below the minimum order value
                  value:
                    error: BELOW_MIN_ORDER_VALUE
                    error_message: >-
                      A take profit or stop loss would place an order below the
                      market's minimum order value (SL, minimum 10)
                '21':
                  summary: Position TP/SL on spot
                  value:
                    error: SPOT_POSITION_MODE_UNSUPPORTED
                    error_message: >-
                      A spot market has no position; a spot take profit / stop
                      loss must use tpsl_mode order
          headers: {}
        '401':
          description: >-
            Unauthorized. The token was accepted by the gateway but rejected by
            the endpoint: `UNAUTHORIZED`, or `INVALID_REQUEST_SIGNATURE` when
            the API key requires signed requests and the signature is missing or
            invalid.
          content:
            application/json:
              schema: *ref_0
              examples:
                '22':
                  summary: Unauthorized
                  value:
                    error: UNAUTHORIZED
                    error_message: Unauthorized access
                '23':
                  summary: Invalid signature
                  value:
                    error: INVALID_REQUEST_SIGNATURE
                    error_message: The request signature is missing or invalid
          headers: {}
          x-apidog-name: Unauthorized
        '403':
          x-apidog-name: Forbidden
          description: >-
            Forbidden. Either the gateway rejected the token
            (`{"message":"Forbidden"}`), the API key lacks the `TRADE` scope
            (`PERMISSION_DENIED`), the account has no exchange account
            (`EXCHANGE_ACCOUNT_NOT_PROVISIONED`), or the account is not
            permitted to trade the product.
          content:
            application/json:
              schema:
                oneOf:
                  - *ref_0
                  - $ref: '#/components/schemas/GatewayError'
              examples:
                '24':
                  summary: Gateway
                  value:
                    message: Forbidden
                '25':
                  summary: Missing scope
                  value:
                    error: PERMISSION_DENIED
                    error_message: Permission denied
                '26':
                  summary: Not provisioned
                  value:
                    error: EXCHANGE_ACCOUNT_NOT_PROVISIONED
                    error_message: >-
                      The account is authenticated but has no exchange account
                      yet
                '27':
                  summary: Product not permitted
                  value:
                    error: You do not have permission to trade spot.
          headers: {}
        '409':
          x-apidog-name: Conflict
          description: The attached take profit / stop loss conflicts with an existing one.
          content:
            application/json:
              schema: *ref_0
              examples:
                '28':
                  summary: Position TP/SL exists
                  value:
                    error: POSITION_TPSL_EXISTS
                    error_message: >-
                      An active position take profit / stop loss already exists
                      for this instrument; set tpsl_force to replace it
                      (existing client_id 0d0b1f0c-7f0e-4f55-9a53-6f6f3c1c2a10)
                '29':
                  summary: Already registered
                  value:
                    error: ORDER_ALREADY_EXISTS
                    error_message: >-
                      A take profit / stop loss is already registered for this
                      client_id
          headers: {}
        '410':
          x-apidog-name: Gone
          description: >-
            `take_profit` or `stop_loss` was sent without `tpsl_mode`. Send
            `tpsl_mode` with every TP/SL.
          content:
            application/json:
              schema: *ref_0
              example:
                error: EXOTIC_ORDERS_V1_DISABLED
                error_message: >-
                  The V1 take profit / stop loss API is switched off; use
                  /v2/account/exotic-orders
          headers: {}
        '422':
          x-apidog-name: Unprocessable
          description: >-
            The exchange rejected the order. `error` is either the rejection
            status (see OrderStatus) or the exchange's error message.
          content:
            application/json:
              schema: *ref_0
              examples:
                '30':
                  summary: Insufficient funds
                  value:
                    error: INSUFFICIENT_FUNDS
                '31':
                  summary: Post only would match
                  value:
                    error: MATCHING_POST_ONLY_RESULTS_IN_MATCH
          headers: {}
        '429':
          x-apidog-name: Too Many Requests
          description: >-
            Rate limit exceeded. Limits are per account holder per minute: 600
            (retail), 2,000 (institutional), 10,000 (market maker).
          content:
            application/json:
              schema: *ref_0
              example:
                error: Too many requests.
          headers: {}
        '500':
          x-apidog-name: Server Error
          description: >-
            The order could not be confirmed. `Order response timeout` means the
            exchange did not confirm the order in time; the order may still have
            been created, so check it by `client_id` before retrying.
          content:
            application/json:
              schema: *ref_0
              examples:
                '33':
                  summary: Timeout
                  value:
                    error: Order response timeout
                '34':
                  summary: TP/SL registration failed
                  value:
                    error: Failed to create order. Please try again.
          headers: {}
        '503':
          x-apidog-name: Service Unavailable
          description: >-
            The market could not be checked for the attached take profit / stop
            loss. The order was not placed: try again.
          content:
            application/json:
              schema: *ref_0
              example:
                error: INSTRUMENTS_UNAVAILABLE
                error_message: The market could not be checked; try again
          headers: {}
      security: []
      x-apidog-folder: One Trading Public REST API/Trading
      x-apidog-status: released
      x-run-in-apidog: https://app.eu.apidog.com/web/project/349694/apis/api-3612092-run
components:
  schemas:
    CreateOrder:
      type: object
      properties:
        instrument_code:
          type: string
          description: >-
            The id of the market to create the order on. Use the /instruments
            endpoint to get the ids of ACTIVE markets to trade on
        type:
          type: string
          enum:
            - LIMIT
          x-apidog-enum:
            - value: LIMIT
              name: ''
              description: ''
          description: The type of order you wish to create
        side:
          type: string
          enum:
            - BUY
            - SELL
          x-apidog-enum:
            - value: BUY
              name: ''
              description: ''
            - value: SELL
              name: ''
              description: ''
          description: BUY or SELL
        amount:
          type: string
          description: >-
            The amount of currency for this order, as a positive decimal string
            within the instrument's amount precision
        price:
          type: string
          description: >-
            The price at which the order is set to execute, as a positive
            decimal string within the instrument's price precision and between
            its `min_price` and `max_price`
        client_id:
          type: string
          format: uuid
          description: >-
            Unique client identifier for the order. Must be a version 4 UUID. If
            omitted, one is generated. It is your responsibility for the
            uniqueness of the client_id, if you create multiple orders with the
            same client_id, any subsequent operation performed using this
            client_id will only apply to the latest
        time_in_force:
          type: string
          description: >-
            Defines the duration and conditions under which an order is
            considered valid in the market. Defaults to GOOD_TILL_CANCELLED
          enum:
            - GOOD_TILL_CANCELLED
            - IMMEDIATE_OR_CANCELLED
            - FILL_OR_KILL
            - POST_ONLY
          x-apidog-enum:
            - value: GOOD_TILL_CANCELLED
              name: ''
              description: ''
            - value: IMMEDIATE_OR_CANCELLED
              name: ''
              description: ''
            - value: FILL_OR_KILL
              name: ''
              description: ''
            - value: POST_ONLY
              name: ''
              description: ''
        reserve_price:
          type: string
          description: Used for MOVE orders and is the max we can move to
        take_profit:
          type: object
          description: >-
            Take profit level attached to the order. Requires `tpsl_mode`.
            Unknown keys are rejected.
          properties:
            value:
              type: string
              pattern: ^\d+(\.\d+)?$
              description: The level, as a positive decimal string
            type:
              type: string
              enum:
                - MID
                - BBO
              x-apidog-enum:
                - value: MID
                  name: ''
                  description: ''
                - value: BBO
                  name: ''
                  description: ''
              default: MID
              description: >-
                The price the level is watched against. `MID`: the midpoint of
                the best bid and the best ask. `BBO`: the side of the book the
                close hits, the best bid for a long, the best ask for a short
          required:
            - value
          additionalProperties: false
          x-apidog-orders:
            - value
            - type
          x-apidog-ignore-properties: []
        stop_loss:
          type: object
          description: >-
            Stop loss level attached to the order. Requires `tpsl_mode`. Unknown
            keys are rejected.
          properties:
            value:
              type: string
              pattern: ^\d+(\.\d+)?$
              description: The level, as a positive decimal string
            type:
              type: string
              enum:
                - MID
                - BBO
              x-apidog-enum:
                - value: MID
                  name: ''
                  description: ''
                - value: BBO
                  name: ''
                  description: ''
              default: MID
              description: >-
                The price the level is watched against. `MID`: the midpoint of
                the best bid and the best ask. `BBO`: the side of the book the
                close hits, the best bid for a long, the best ask for a short
          required:
            - value
          additionalProperties: false
          x-apidog-orders:
            - value
            - type
          x-apidog-ignore-properties: []
        tpsl_mode:
          type: string
          enum:
            - order
            - position
          x-apidog-enum:
            - value: order
              name: ''
              description: ''
            - value: position
              name: ''
              description: ''
          description: >-
            Required when `take_profit` or `stop_loss` is sent. `order`: the
            TP/SL closes this order's filled amount. `position`: it closes the
            whole position on this instrument, as it is when a level is reached
            (futures only).
        tpsl_force:
          type: boolean
          default: false
          description: >-
            With `tpsl_mode: position`, replace the existing position take
            profit / stop loss on this instrument once this order fills, instead
            of failing with `POSITION_TPSL_EXISTS`.
        tpsl_slippage_bps:
          type: integer
          minimum: 1
          maximum: 9999
          description: >-
            How far from its level the take profit / stop loss close may trade,
            in basis points. At most the instrument's price collar
            (`price_collar_percentage` × 100 on Instruments; 1000 for an
            instrument without one). Defaults to 500 (5%), or the collar if that
            is less. It cannot be changed later.
      x-apidog-orders:
        - instrument_code
        - type
        - side
        - amount
        - price
        - client_id
        - time_in_force
        - reserve_price
        - take_profit
        - stop_loss
        - tpsl_mode
        - tpsl_force
        - tpsl_slippage_bps
      required:
        - instrument_code
        - type
        - side
        - amount
        - price
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
    ErrorResponse:
      type: object
      description: >-
        Error body. `error` is a machine-readable code (e.g.
        `INVALID_INSTRUMENT_CODE`) on most endpoints; a few older endpoints
        return a human-readable message in `error` instead and omit
        `error_message`.
      properties:
        error:
          type: string
          description: Error code (or, on older endpoints, a human-readable message).
        error_message:
          type: string
          description: >-
            Human-readable detail. Present on endpoints that return an error
            code in `error`.
      required:
        - error
      x-apidog-orders:
        - error
        - error_message
      x-apidog-folder: ''
      x-apidog-ignore-properties: []
    GatewayError:
      type: object
      description: >-
        Returned by the API gateway itself when the bearer token is missing,
        invalid, expired or revoked, or the calling IP is not on the API key's
        allowlist.
      properties:
        message:
          type: string
          enum:
            - Forbidden
            - Unauthorized
      required:
        - message
      x-apidog-orders:
        - message
      x-apidog-folder: ''
      x-apidog-ignore-properties: []
  securitySchemes:
    bearerAuth:
      type: bearer
      scheme: bearer
      description: >-
        API key issued to the account holder, sent as `Authorization: Bearer
        <token>`. The key must hold the `SUBACCOUNT_TRANSFER` scope.
    bearer:
      type: bearer
      scheme: bearer
servers:
  - url: https://api.onetrading.com/fast
    description: Production Env
security: []

```