---
openapi: 3.0.1
info:
  title: Trading API v4
  description: APIs related to trading operations
  version: v4
paths:
  /frontoffice/api/v4/order-list:
    post:
      tags:
        - OrderControllerV
      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.ApiGetHistoryOrdersV4.Request
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetHistoryOrders.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'
  /frontoffice/api/v4/orders/closed-positions:
    post:
      tags:
        - OrderControllerV
      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.ApiGetClosedPositionsOrdersV4.Request
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetClosedPositionsOrdersV4.Response
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BBP.Platform.Http.ErrorData'
  /frontoffice/api/v4/orders/executions/list:
    post:
      tags:
        - OrderControllerV
      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.ApiGetClosedPositionOrderExecutionsV4.Request
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetClosedPositionOrderExecutionsV4.Response
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BBP.Platform.Http.ErrorData'
  /frontoffice/api/v4/orders/{orderId}/executions/list:
    post:
      tags:
        - OrderControllerV
      description: "Required operations: trading-ui"
      parameters:
        - name: orderId
          in: path
          required: true
          schema:
            type: string
        - name: accountId
          in: header
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: >-
                #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetClosedPositionOrderExecutionsV4.RequestSingle.BodyModel
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetClosedPositionOrderExecutionsV4.ResponseSingle
        '400':
          description: Bad Request
          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.Order.v4.RealizedPnlBreakdownItem:
      type: object
      required:
        - assetId
        - amount
      properties:
        assetId:
          type: string
          description: Asset identifier.
        amount:
          type: string
          description: Amount.
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Enums.ApiMarketType:
      enum:
        - Spot
        - Cfd
        - Perpetual
      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.Enums.ApiOrderSource:
      enum:
        - Manual
        - StopOrder
        - FixApi
        - System
      type: string
    BBP.TradingServer.TradingApi.Models.Enums.ApiOrderReason:
      enum:
        - Admin
        - Trader
        - StopOut
        - MarketHalted
        - MarketDisabled
        - UserTerminated
        - TakeProfit
        - StopLoss
      type: string
    BBP.TradingServer.TradingApi.Models.Enums.ApiOrderSide:
      enum:
        - Buy
        - Sell
      type: string
    BBP.TradingServer.TradingApi.Models.Enums.ApiOrderType:
      enum:
        - Market
        - Limit
      type: string
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetHistoryOrdersV4.Request:
      type: object
      properties:
        limit:
          type: integer
          format: int32
          nullable: true
        createdAtFrom:
          type: string
          format: date-time
          nullable: true
        createdAtTo:
          type: string
          format: date-time
          nullable: true
        orderStatus:
          type: array
          items:
            $ref: >-
              #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderStatus
        lastOrderId:
          type: string
          nullable: true
        marketType:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiMarketType
          nullable: true
        marketId:
          type: string
          nullable: true
        updatedAtFrom:
          type: string
          format: date-time
          nullable: true
        updatedAtTo:
          type: string
          format: date-time
          nullable: true
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetHistoryOrders.Response:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: >-
              #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiHistoryOrder
          readOnly: true
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiHistoryOrder:
      required:
        - commissionAssetId
        - marketDisplayName
        - marketFullName
        - marketId
        - orderId
        - rejectDetails
      type: object
      properties:
        marketId:
          minLength: 1
          type: string
        marketType:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiMarketType
        marketDisplayName:
          minLength: 1
          type: string
        marketFullName:
          minLength: 1
          type: string
        orderId:
          minLength: 1
          type: string
        timeInForce:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderTimeInForce
        status:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderStatus
        source:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderSource
        reason:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderReason
        side:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderSide
        orderType:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderType
        requestedAmount:
          type: string
        remainingAmount:
          type: string
        requestedPrice:
          type: string
        executionPrice:
          type: string
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        cancellationDate:
          type: string
          format: date-time
          nullable: true
        commissionAssetId:
          minLength: 1
          type: string
        commissionAmount:
          type: string
        leverage:
          type: integer
          format: int32
          nullable: true
        rejectDetails:
          minLength: 1
          type: string
        fillFactor:
          type: string
        comment:
          type: string
          nullable: true
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetClosedPositionsOrdersV4.Request:
      type: object
      properties:
        createdAtFrom:
          type: string
          format: date-time
          nullable: true
        createdAtTo:
          type: string
          format: date-time
          nullable: true
        limit:
          type: integer
          format: int32
          nullable: true
        lastOrderId:
          type: string
          nullable: true
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetClosedPositionsOrdersV4.Response:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: >-
              #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiClosedPositionOrderV4
          readOnly: true
        isExceeded:
          type: boolean
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiClosedPositionOrderV4:
      required:
        - marketId
        - orderId
        - positionId
      type: object
      properties:
        marketId:
          minLength: 1
          type: string
        marketFullName:
          type: string
          nullable: true
        marketDisplayName:
          type: string
          nullable: true
        marketType:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiMarketType
        orderId:
          minLength: 1
          type: string
        orderType:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderType
        timeInForce:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderTimeInForce
        side:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderSide
        positionCloseLotAmount:
          type: string
        reason:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderReason
        realizedPnlInRAT:
          type: string
        realizedPnls:
          type: array
          items:
            $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.RealizedPnlBreakdownItem'
        closedAt:
          type: string
          format: date-time
          nullable: true
        positionId:
          minLength: 1
          type: string
        openPrice:
          type: string
        closePrice:
          type: string
        positionPriceInRAT:
          type: string
        rateToRAT:
          type: string
        openedAt:
          type: string
          format: date-time
        comment:
          type: string
          nullable: true
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetClosedPositionOrderExecutionsV4.Request:
      type: object
      properties:
        orderIds:
          type: array
          items:
            type: string
        limit:
          type: integer
          format: int32
          nullable: true
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetClosedPositionOrderExecutionsV4.Response:
      type: object
      properties:
        executions:
          type: array
          items:
            $ref: >-
              #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetClosedPositionOrderExecutionsV4.Execution
        isExceeded:
          type: boolean
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetClosedPositionOrderExecutionsV4.Execution:
      type: object
      properties:
        positionId:
          type: string
        orderId:
          type: string
        side:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderSide
        reason:
          $ref: >-
            #/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderReason
        createdAt:
          type: string
          format: date-time
        executionId:
          type: string
        baseAmount:
          type: string
        executionPrice:
          type: string
        realizedPnlInRAT:
          type: string
        realizedPnls:
          type: array
          items:
            $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.RealizedPnlBreakdownItem'
        commissionAmountInRAT:
          type: string
        commissions:
          type: array
          items:
            $ref: >-
              #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetClosedPositionOrderExecutionsV4.Commission
        positionSizeIncreased:
          type: boolean
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetClosedPositionOrderExecutionsV4.Commission:
      type: object
      properties:
        assetId:
          type: string
        amount:
          type: string
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetClosedPositionOrderExecutionsV4.RequestSingle.BodyModel:
      type: object
      properties:
        limit:
          type: integer
          format: int32
          nullable: true
        lastExecutionId:
          type: string
          nullable: true
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetClosedPositionOrderExecutionsV4.ResponseSingle:
      type: object
      properties:
        executions:
          type: array
          items:
            $ref: >-
              #/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v4.ApiGetClosedPositionOrderExecutionsV4.Execution
        isExceeded:
          type: boolean
      additionalProperties: false
