---
openapi: 3.0.1
info:
  title: Trading API v3
  description: APIs related to trading operations
  version: v3
paths:
  /frontoffice/api/v3/order-data:
    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.v3.ApiGetOrderData.Request'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v3.ApiGetOrderData.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/v3/guest/order-data:
    post:
      tags:
        - GuestOrderControllerV
      description: >-
        Anonymous counterpart of POST /frontoffice/api/v3/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. 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.v3.ApiGetOrderData.Request'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Controllers.v3.Guest.ApiGuestGetOrderDataV3.Response'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BBP.Platform.Http.ErrorData'
  /frontoffice/api/v3/orders:
    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.v3.ApiCreateOrder.Request'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v3.ApiCreateOrder.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'
    delete:
      tags:
        - OrderControllerV
      description: "Required operations: trading-ui"
      parameters:
        - name: accountId
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v3.ApiCancelAllOrders.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'
  /frontoffice/api/v3/orders/{orderId}:
    delete:
      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
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v3.ApiCancelOrder.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.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.Order.v3.ApiGetOrderData.Request:
      type: object
      properties:
        order:
          $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v3.ApiGetOrderData.Request.OrderDataModel'
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v3.ApiGetOrderData.Request.OrderDataModel:
      type: object
      properties:
        marketId:
          type: string
          nullable: true
        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
        requestedBaseAmount:
          type: string
          nullable: true
        requestedQuoteAmount:
          type: string
          nullable: true
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v3.ApiGetOrderData.Response:
      required:
        - order
      type: object
      properties:
        order:
          $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v3.ApiGetOrderData.Response.OrderResponse'
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v3.ApiGetOrderData.Response.OrderResponse:
      type: object
      properties:
        baseAmount:
          type: string
        quoteAmount:
          type: string
        commissionAmount:
          type: string
        total:
          type: string
      additionalProperties: false
    BBP.TradingServer.TradingApi.Controllers.v3.Guest.ApiGuestGetOrderDataV3.Response:
      required:
        - order
      type: object
      properties:
        order:
          $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Controllers.v3.Guest.ApiGuestGetOrderDataV3.Response.OrderResponse'
      additionalProperties: false
    BBP.TradingServer.TradingApi.Controllers.v3.Guest.ApiGuestGetOrderDataV3.Response.OrderResponse:
      required:
        - baseAmount
        - quoteAmount
        - commissionAmount
        - total
      type: object
      properties:
        baseAmount:
          type: string
        quoteAmount:
          type: string
        commissionAmount:
          type: string
        total:
          type: string
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v3.ApiCreateOrder.Request:
      type: object
      properties:
        order:
          $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v3.ApiCreateOrder.OrderRequestModel'
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v3.ApiCreateOrder.OrderRequestModel:
      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
        requestedAmount:
          type: string
          nullable: true
        timeInForce:
          $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderTimeInForce'
        cancellationDate:
          type: string
          nullable: true
        comment:
          type: string
          nullable: true
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v3.ApiCreateOrder.Response:
      type: object
      properties:
        order:
          $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v3.ApiOrderResponseModel'
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v3.ApiOrderResponseModel:
      type: object
      properties:
        marketId:
          type: string
        marketDisplayName:
          type: string
        orderId:
          type: string
        orderType:
          $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderType'
        side:
          $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderSide'
        status:
          $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderStatus'
        source:
          $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderSource'
        timeInForce:
          $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Enums.ApiOrderTimeInForce'
        commission:
          type: string
        requestedAmount:
          type: string
        remainingAmount:
          type: string
        requestedPrice:
          type: string
          nullable: true
        executionPrice:
          type: string
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        rejectDetails:
          type: string
        cancellationDate:
          type: string
          format: date-time
          nullable: true
        fillFactor:
          type: string
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v3.ApiCancelOrder.Response:
      type: object
      properties:
        order:
          $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v3.ApiOrderResponseModel'
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v3.ApiCancelAllOrders.Response:
      required:
        - failed
        - successful
      type: object
      properties:
        successful:
          $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v3.ApiCancelAllOrders.Response.SuccessfulItems'
        failed:
          type: array
          items:
            $ref: '#/components/schemas/BBP.TradingServer.TradingApi.Models.Order.v3.ApiCancelAllOrders.Response.FailedItem'
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v3.ApiCancelAllOrders.Response.FailedItem:
      required:
        - errorCode
        - orderId
      type: object
      properties:
        orderId:
          title: ULID
          maxLength: 26
          pattern: '^[0-9A-HJKMNP-TV-Z]{26}$'
          uniqueItems: true
          type: string
          description: A 26-character Universally Unique Lexicographically Sortable Identifier
          format: ulid
          example: 01KBMWFZP17N9NQ7KY0JHGAVXX
        errorCode:
          minLength: 1
          type: string
      additionalProperties: false
    BBP.TradingServer.TradingApi.Models.Order.v3.ApiCancelAllOrders.Response.SuccessfulItems:
      required:
        - orderIds
      type: object
      properties:
        orderIds:
          type: array
          items:
            title: ULID
            maxLength: 26
            minLength: 26
            pattern: '^[0-9A-HJKMNP-TV-Z]{26}$'
            uniqueItems: true
            type: string
            description: A 26-character Universally Unique Lexicographically Sortable Identifier
            format: ulid
            example: 01KBMWFZP0ZA7M6QFHBE03A74P
      additionalProperties: false
