---
openapi: 3.0.1
info:
  title: Trading API v4
  description: APIs related to trading operations
  version: v4
paths:
  /frontoffice/api/cfd/v4/order-data:
    post:
      tags:
        - CfdOrderControllerV
      description: "Required operations: trading-ui"
      parameters:
        - name: accountId
          in: header
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: >-
                #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Request
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Response
        '400':
          description: Bad Request
          content:
            application/json; x-api-version=4.0:
              schema:
                $ref: '#/components/schemas/BBP.Platform.Http.ErrorData'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BBP.Platform.Http.ErrorData'
  /frontoffice/api/cfd/v4/guest/order-data:
    post:
      tags:
        - GuestCfdOrderControllerV
      description: >-
        Anonymous counterpart of POST /frontoffice/api/cfd/v4/order-data. No
        authentication, no required operations, and no accountId header. Accepts
        the same request body and returns the same field set, calculated without
        any account-specific settings and with the tenant-default commission rule
        evaluated at a traded volume of 0. marginLevel is always null for guests
        because it needs a balance and open positions.
        Only markets visible to guests are accepted; any other market symbol
        returns 400. There is no guest counterpart of the order placement
        endpoints — guests cannot trade.
      requestBody:
        content:
          application/json:
            schema:
              $ref: >-
                #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Request
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/BBP.TradingServer.TradingApi.Controllers.v4.Guest.ApiGuestGetCfdOrderDataV4.Response
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BBP.Platform.Http.ErrorData'
  /frontoffice/api/cfd/v4/orders:
    post:
      tags:
        - CfdOrderControllerV
      description: "Required operations: trading-ui"
      parameters:
        - name: accountId
          in: header
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: >-
                #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiCreateCfdOrderV4.Request
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiCreateCfdOrderV4.Response
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BBP.Platform.Http.ErrorData'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BBP.Platform.Http.ErrorData'
        '429':
          description: Too Many Requests
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BBP.Platform.Http.ErrorData'
components:
  schemas:
    BBP.Platform.Http.ErrorData:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
        details:
          $ref: '#/components/schemas/BBP.Platform.Http.ErrorData.ErrorDetails'
      additionalProperties: false
    BBP.Platform.Http.ErrorData.ErrorDetails:
      type: object
      properties:
        source:
          type: string
          nullable: true
        message:
          type: string
          nullable: true
        stackTrace:
          type: string
          nullable: true
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Enums.ApiOrderType:
      enum:
        - Market
        - Limit
      type: string
    # TECHNICAL DEBT. This enum ApiOrderTypeExtended is created for the task B2TD-20309, extending the base OrderType enum with the 'StopMarket' element.
    # This enum is using in:
    #   - POST /frontoffice/api/v3/order-data - TradingAPI/v3/OrderOpenAPI.yaml
    #   - POST /frontoffice/api/cfd/v4/order-data - TradingAPI/v4/CfdOrderOpenAPI.yaml
    #   - POST /frontoffice/api/perpetual/v4/order-data - TradingAPI/v4/PerpetualOrderOpenAPI.yaml
    # FUTURE: Refactor code to use a single, unified enum for order types, including [Market, Limit, StopMarket, StopLimit] and maybe other elements.
    BBP.TradingServer.TradingApi.Models.Enums.ApiOrderTypeExtended:
      enum:
        - Market
        - Limit
        - StopMarket
      type: string
    BBP.TradingServer.TradingApi.Models.Enums.ApiOrderSide:
      enum:
        - Buy
        - Sell
      type: string
    BBP.TradingServer.TradingApi.Models.Enums.ApiTriggerType:
      enum:
        - Price
        - Rate
        - Points
        - Pnl
      type: string
    BBP.TradingServer.TradingApi.Models.Enums.ApiOrderTimeInForce:
      enum:
        - Gtc
        - Ioc
        - Fok
        - Gtd
        - Day
        - Retry
      type: string
    BBP.TradingServer.TradingApi.Models.Enums.ApiOrderStatus:
      enum:
        - Started
        - Pending
        - Working
        - Completed
        - Cancelled
        - Expired
        - Rejected
      type: string
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Request:
      type: object
      properties:
        order:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Request.OrderDataModel
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Request.OrderDataModel:
      type: object
      properties:
        marketId:
          type: string
        orderType:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderTypeExtended
        side:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderSide
        requestedPrice:
          type: string
          nullable: true
        requestedLotAmount:
          type: string
          nullable: true
        leverage:
          type: integer
          format: int32
          nullable: true
        takeProfit:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Request.TakeProfitRequest
        stopLoss:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Request.StopLossRequest
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Request.TakeProfitRequest:
      type: object
      properties:
        triggerType:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiTriggerType
        triggerSize:
          type: string
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Request.StopLossRequest:
      type: object
      properties:
        triggerType:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiTriggerType
        triggerSize:
          type: string
        isTrailing:
          type: boolean
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Response:
      required:
        - order
      type: object
      properties:
        order:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Response.OrderResponse
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Response.OrderResponse:
      type: object
      properties:
        requiredMarginInRAT:
          type: string
        quoteAmount:
          type: string
        commissionAmountInRAT:
          type: string
        marginLevel:
          type: string
          nullable: true
        takeProfit:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Response.TakeProfitResponse
        stopLoss:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Response.StopLossResponse
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Response.TakeProfitResponse:
      type: object
      properties:
        price:
          type: string
        rate:
          type: string
        points:
          type: integer
          format: int64
        pnl:
          type: string
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetCfdOrderDataV4.Response.StopLossResponse:
      type: object
      properties:
        price:
          type: string
        rate:
          type: string
        points:
          type: integer
          format: int64
        pnl:
          type: string
      additionalProperties: false
    BBP.TradingServer.TradingApi.Controllers.v4.Guest.ApiGuestGetCfdOrderDataV4.Response:
      required:
        - order
      type: object
      properties:
        order:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Controllers.v4.Guest.ApiGuestGetCfdOrderDataV4.Response.OrderResponse
      additionalProperties: false
    BBP.TradingServer.TradingApi.Controllers.v4.Guest.ApiGuestGetCfdOrderDataV4.Response.OrderResponse:
      required:
        - lotAmount
        - requiredMarginInRAT
        - quoteAmount
        - commissionAmountInRAT
      type: object
      properties:
        lotAmount:
          type: string
        requiredMarginInRAT:
          type: string
        quoteAmount:
          type: string
        commissionAmountInRAT:
          type: string
        marginLevel:
          type: string
          nullable: true
          description: Always null for anonymous callers.
        takeProfit:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Controllers.v4.Guest.ApiGuestGetCfdOrderDataV4.Response.ProfitTrigger
        stopLoss:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Controllers.v4.Guest.ApiGuestGetCfdOrderDataV4.Response.ProfitTrigger
      additionalProperties: false
    BBP.TradingServer.TradingApi.Controllers.v4.Guest.ApiGuestGetCfdOrderDataV4.Response.ProfitTrigger:
      type: object
      nullable: true
      properties:
        price:
          type: string
        rate:
          type: string
        points:
          type: integer
          format: int64
        pnl:
          type: string
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiCreateCfdOrderV4.Request:
      type: object
      properties:
        order:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiCreateCfdOrderV4.CfdOrderRequestModel
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiCreateCfdOrderV4.CfdOrderRequestModel:
      type: object
      properties:
        marketId:
          type: string
          nullable: true
        orderType:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderType
        side:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderSide
        requestedPrice:
          type: string
          nullable: true
        requestedLotAmount:
          type: string
          nullable: true
        timeInForce:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderTimeInForce
        cancellationDate:
          type: string
          nullable: true
        leverage:
          type: integer
          format: int32
          nullable: true
        takeProfit:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiCreateCfdOrderV4.CfdOrderRequestModel.TakeProfitPlaceOrderRequest
        stopLoss:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiCreateCfdOrderV4.CfdOrderRequestModel.StopLossPlaceOrderRequest
        comment:
          type: string
          nullable: true
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiCreateCfdOrderV4.CfdOrderRequestModel.TakeProfitPlaceOrderRequest:
      type: object
      properties:
        price:
          type: string
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiCreateCfdOrderV4.CfdOrderRequestModel.StopLossPlaceOrderRequest:
      type: object
      properties:
        price:
          type: string
        isTrailing:
          type: boolean
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiCreateCfdOrderV4.Response:
      type: object
      properties:
        order:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiCreateCfdOrderV4.ApiCfdOrderResponseModel
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiCreateCfdOrderV4.ApiCfdOrderResponseModel:
      type: object
      properties:
        orderId:
          type: string
        status:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderStatus
      additionalProperties: false
