---
openapi: 3.1.0
info:
  title: CfdOrders
  version: '4.0'
  contact: {}
  description: Cfd Orders in TradingApi
servers:
  - url: '[ts-host]'
tags:
  - name: CFDOrderController
    description: CFD Orders operations
paths:
  /frontoffice/api/cfd/v4/order-data:
    post:
      tags:
        - CFDOrderController
      summary: Validate Order data
      description: '<p><b>Required operations:</b><br/>frontoffice-ui</p>'
      operationId: validateOrder
      parameters:
        - schema:
            type: string
          in: header
          name: accountId
          required: true
          description: Account ID
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApiGetCfdOrderDataV4.Request'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiGetCfdOrderDataV4.Response'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorData'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorData'
  /frontoffice/api/cfd/v4/orders:
    post:
      summary: Place Order
      description: '<p><b>Required operations:</b><br/>trading-ui</p>'
      operationId: placeCfdOrder
      tags:
        - CFDOrderController
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiCreateCfdOrderV4.Response'
              examples:
                Example 1:
                  value:
                    order:
                      orderId: 65f1990aae5ec088da163949
                      status: Working
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorData'
              examples:
                Example 1:
                  value:
                    code: TR0110
                    message: Leverage is required
                Example 2:
                  value:
                    code: TR0113
                    message: Leverage must be equal to Max Leverage
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorData'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApiCreateCfdOrderV4.Request'
            examples:
              Example 1:
                value:
                  order:
                    marketId: cfd.btc_usdt
                    orderType: Market
                    side: Buy
                    requestedPrice: '0.002'
                    requestedLotAmount: '0.002'
                    timeInForce: Gtc
                    cancellationDate: '2019-08-24T14:15:22Z'
                    leverage: 1
      parameters:
        - schema:
            type: string
          in: header
          name: accountId
          required: true
          description: Account ID
components:
  schemas:
    ApiCreateCfdOrderV4.Request:
      title: ApiCreateCfdOrderV4.Request
      type: object
      properties:
        order:
          $ref: '#/components/schemas/ApiCreateCfdOrderV4.Request.CfdOrderRequestModel'
    ApiCreateCfdOrderV4.Response:
      title: ApiCreateCfdOrderV4.Response
      type: object
      properties:
        order:
          $ref: '#/components/schemas/ApiCreateCfdOrderV4.Response.ApiCreateOrderResponseModel'
    ApiGetCfdOrderDataV4.Request:
      title: ApiGetCfdOrderDataV4.Request
      type: object
      properties:
        order:
          $ref: '#/components/schemas/ApiGetCfdOrderDataV4.Request.OrderDataModel'
    ApiGetCfdOrderDataV4.Response:
      title: ApiGetCfdOrderDataV4.Response
      type: object
      properties:
        order:
          $ref: '#/components/schemas/ApiGetCfdOrderDataV4.Response.OrderResponse'
    ApiCreateCfdOrderV4.Request.CfdOrderRequestModel:
      title: ApiCreateCfdOrderV4.Request.CfdOrderRequestModel
      type: object
      properties:
        marketId:
          type: string
          pattern: '^cfd.{0,1}[a-z0-9]{1,15}_[a-z0-9]{1,15}$'
        orderType:
          $ref: '#/components/schemas/ApiOrderType'
        side:
          $ref: '#/components/schemas/ApiOrderSide'
        requestedPrice:
          $ref: '#/components/schemas/StringDecimalNullable'
        requestedLotAmount:
          $ref: '#/components/schemas/StringDecimal'
        timeInForce:
          $ref: '#/components/schemas/ApiOrderTimeInForce'
        cancellationDate:
          type:
            - string
            - 'null'
          format: date-time
        leverage:
          type: integer
          minimum: 1
        takeProfit:
          $ref: '#/components/schemas/ApiCreateCfdOrderV4.Request.TakeProfitPlaceOrderRequest'
        stopLoss:
          $ref: '#/components/schemas/ApiCreateCfdOrderV4.Request.StopLossPlaceOrderRequest'
      required:
        - marketId
        - orderType
        - side
        - requestedLotAmount
        - timeInForce
        - leverage
    ApiCreateCfdOrderV4.Response.ApiCreateOrderResponseModel:
      title: ApiCreateOrderResponseModel
      x-stoplight:
        id: 7c102b7908e45
      type: object
      examples:
        - orderId: 65f1990aae5ec088da163949
          status: Working
      properties:
        orderId:
          type: string
        status:
          $ref: '#/components/schemas/ApiOrderStatus'
    ApiGetCfdOrderDataV4.Request.OrderDataModel:
      title: ApiGetCfdOrderDataV4.Request.OrderDataModel
      type: object
      properties:
        marketId:
          type: string
        orderType:
          $ref: '#/components/schemas/ApiOrderType'
        side:
          $ref: '#/components/schemas/ApiOrderSide'
        requestedPrice:
          $ref: '#/components/schemas/StringDecimalNullable'
        requestedLotAmount:
          $ref: '#/components/schemas/StringDecimal'
        leverage:
          type: integer
        takeProfit:
          $ref: '#/components/schemas/ApiGetCfdOrderDataV4.Request.TakeProfitRequest'
        stopLoss:
          $ref: '#/components/schemas/ApiGetCfdOrderDataV4.Request.StopLossRequest'
    ApiGetCfdOrderDataV4.Response.OrderResponse:
      title: ApiGetCfdOrderDataV4.Response.OrderResponse
      type: object
      properties:
        requiredMarginInRAT:
          $ref: '#/components/schemas/StringDecimal'
        quoteAmount:
          $ref: '#/components/schemas/StringDecimal'
        commissionAmountInRAT:
          $ref: '#/components/schemas/StringDecimal'
        marginLevel:
          $ref: '#/components/schemas/StringDecimalNullable'
        takeProfit:
          $ref: '#/components/schemas/ApiGetCfdOrderDataV4.Response.TakeProfitResponse'
        stopLoss:
          $ref: '#/components/schemas/ApiGetCfdOrderDataV4.Response.StopLossResponse'
    ErrorData:
      title: ErrorData
      type: object
      examples:
        - code: TR0110
          message: Leverage is required
        - code: TR0111
          message: Leverage must be greater than 0
        - code: TR0112
          message: Leverage must be less than or equal to Max Leverage
        - code: TR0113
          message: Leverage must be equal to Max Leverage
      properties:
        code:
          type: string
          pattern: '^TR\d{4}$'
        message:
          type: string
      required:
        - code
      details:
        $ref: '#/components/schemas/ErrorData.ErrorDetails'
    ErrorData.ErrorDetails:
      type: object
      properties:
        source:
          type: string
        message:
          type: string
        stackTrace:
          type: string
    StringDecimal:
      title: StringDecimal
      type: string
      pattern: '^\d+(\.\d+){0,1}'
      examples:
        - '0.002'
        - '10.015'
        - '0.000001'
    StringDecimalNullable:
      title: StringDecimalNullable
      type:
        - string
        - 'null'
      pattern: '^\d+(\.\d+){0,1}'
      examples:
        - '0.002'
        - '10.015'
        - '0.000001'
        - null
    ApiOrderType:
      title: ApiOrderType
      type: string
      enum:
        - Market
        - Limit
      examples: []
    ApiOrderSide:
      title: ApiOrderSide
      type: string
      enum:
        - Buy
        - Sell
    ApiOrderStatus:
      title: ApiOrderStatus
      type: string
      enum:
        - Started
        - Pending
        - Working
        - Completed
        - Cancelled
        - Expired
        - Rejected
    ApiOrderTimeInForce:
      title: ApiOrderTimeInForce
      type: string
      enum:
        - Gtc
        - Ioc
        - Fok
        - Gtd
        - Day
        - Retry
    ApiTriggerType:
      title:
      type: string
      enum:
        - price
        - rate
        - points
        - pnl
    ApiGetCfdOrderDataV4.Request.TakeProfitRequest:
      type: object
      properties:
        triggerType:
          $ref: '#/components/schemas/ApiTriggerType'
        triggerSize:
          $ref: '#/components/schemas/StringDecimal'
    ApiGetCfdOrderDataV4.Request.StopLossRequest:
      type: object
      properties:
        triggerType:
          $ref: '#/components/schemas/ApiTriggerType'
        triggerSize:
          $ref: '#/components/schemas/StringDecimal'
        isTrailing:
          type: boolean
    ApiGetCfdOrderDataV4.Response.TakeProfitResponse:
      type: object
      properties:
        price:
          $ref: '#/components/schemas/StringDecimal'
        rate:
          $ref: '#/components/schemas/StringDecimal'
        points:
          type: integer
        pnl:
          $ref: '#/components/schemas/StringDecimal'
    ApiGetCfdOrderDataV4.Response.StopLossResponse:
      type: object
      properties:
        price:
          $ref: '#/components/schemas/StringDecimal'
        rate:
          $ref: '#/components/schemas/StringDecimal'
        points:
          type: integer
        pnl:
          $ref: '#/components/schemas/StringDecimal'
    ApiCreateCfdOrderV4.Request.TakeProfitPlaceOrderRequest:
      type: object
      properties:
        price:
          $ref: '#/components/schemas/StringDecimal'
    ApiCreateCfdOrderV4.Request.StopLossPlaceOrderRequest:
      type: object
      properties:
        price:
          $ref: '#/components/schemas/StringDecimal'
        isTrailing:
          type: boolean
