asyncapi: 3.0.0
info:
  title: BBP Trading Server Account WebSocket API
  version: 4.0.0
  description: WebSocket API for receiving trading account data in real-time via SignalR JSON Protocol
servers:
  production:
    host: '{hostname}'
    pathname: /frontoffice/ws/v4/account
    protocol: wss
    variables:
      hostname:
        default: api.example.com
    security:
      - $ref: '#/components/securitySchemes/accessTokenQuery'
channels:
  streamInvocation:
    address: StreamInvocation
    messages:
      subscribeRequest:
        $ref: '#/components/messages/StreamInvocationRequest'
  openOrders:
    address: OpenOrders
    messages:
      openOrdersMessage:
        $ref: '#/components/messages/OpenOrdersMessage'
  fullBalance:
    address: FullBalance
    messages:
      fullBalanceMessage:
        $ref: '#/components/messages/FullBalanceMessage'
  marginData:
    address: MarginData
    messages:
      marginDataMessage:
        $ref: '#/components/messages/MarginDataMessage'
  openPositions:
    address: OpenPositions
    messages:
      openPositionsMessage:
        $ref: '#/components/messages/OpenPositionsMessage'
  closePositionsOrders:
    address: ClosePositionsOrders
    messages:
      closePositionsOrdersMessage:
        $ref: '#/components/messages/ClosePositionsOrdersMessage'
operations:
  sendStreamInvocation:
    action: send
    channel:
      $ref: '#/channels/streamInvocation'
    messages:
      - $ref: '#/channels/streamInvocation/messages/subscribeRequest'
  receiveOpenOrders:
    action: receive
    channel:
      $ref: '#/channels/openOrders'
    messages:
      - $ref: '#/channels/openOrders/messages/openOrdersMessage'
  receiveFullBalance:
    action: receive
    channel:
      $ref: '#/channels/fullBalance'
    messages:
      - $ref: '#/channels/fullBalance/messages/fullBalanceMessage'
  receiveMarginData:
    action: receive
    channel:
      $ref: '#/channels/marginData'
    messages:
      - $ref: '#/channels/marginData/messages/marginDataMessage'
  receiveOpenPositions:
    action: receive
    channel:
      $ref: '#/channels/openPositions'
    messages:
      - $ref: '#/channels/openPositions/messages/openPositionsMessage'
  receiveClosePositionsOrders:
    action: receive
    channel:
      $ref: '#/channels/closePositionsOrders'
    messages:
      - $ref: '#/channels/closePositionsOrders/messages/closePositionsOrdersMessage'
components:
  messages:
    StreamInvocationRequest:
      contentType: application/json
      payload:
        $ref: '#/components/schemas/SignalRStreamInvocation'
      examples:
        - name: OpenOrders
          payload:
            type: 4
            invocationId: '0'
            target: 'OpenOrders'
            arguments:
              - '6839712e47201389687ba09f'
        - name: FullBalance
          payload:
            type: 4
            invocationId: '1'
            target: 'FullBalance'
            arguments:
              - '6839712e47201389687ba09f'
        - name: MarginData
          payload:
            type: 4
            invocationId: '2'
            target: 'MarginData'
            arguments:
              - '6839712e47201389687ba09f'
        - name: OpenPositions
          payload:
            type: 4
            invocationId: '3'
            target: 'OpenPositions'
            arguments:
              - '6839712e47201389687ba09f'
        - name: ClosePositionsOrders
          payload:
            type: 4
            invocationId: '4'
            target: 'ClosePositionsOrders'
            arguments:
              - '6839712e47201389687ba09f'
    OpenOrdersMessage:
      contentType: application/json
      payload:
        type: object
        required:
          - type
          - invocationId
          - item
        properties:
          type:
            type: integer
            const: 2
          invocationId:
            type: string
          item:
            $ref: '#/components/schemas/OpenOrdersStreamItem'
      examples:
        - payload:
            type: 2
            invocationId: '0'
            item:
              item:
                - marketId: 'BTCUSD'
                  marketType: 'Cfd'
                  marketDisplayName: 'Bitcoin / US Dollar'
                  marketFullName: 'Bitcoin vs US Dollar'
                  orderId: '123e4567-e89b-12d3-a456-426614174000'
                  timeInForce: 'Gtc'
                  status: 'Working'
                  source: 'Manual'
                  reason: 'Trader'
                  side: 'Buy'
                  orderType: 'Limit'
                  requestedAmount: 0.5
                  remainingAmount: 0.3
                  requestedPrice: 50000.00
                  executionPrice: 49950.00
                  createdAt: '2026-01-21T10:00:00Z'
                  updatedAt: '2026-01-21T10:05:00Z'
                  commissionAssetId: 'USDT'
                  commissionAmount: 2.5
                  leverage: 10
                  fillFactor: 0.4
                  comment: 'Updated order status'
              snapshot: true
    FullBalanceMessage:
      contentType: application/json
      payload:
        type: object
        required:
          - type
          - invocationId
          - item
        properties:
          type:
            type: integer
            const: 2
          invocationId:
            type: string
          item:
            type: object
            properties:
              item:
                type: array
                items:
                  type: object
              snapshot:
                type: boolean
    MarginDataMessage:
      contentType: application/json
      payload:
        type: object
        required:
          - type
          - invocationId
          - item
        properties:
          type:
            type: integer
            const: 2
          invocationId:
            type: string
          item:
            type: object
            properties:
              item:
                type: object
              snapshot:
                type: boolean
    OpenPositionsMessage:
      contentType: application/json
      payload:
        type: object
        required:
          - type
          - invocationId
          - item
        properties:
          type:
            type: integer
            const: 2
          invocationId:
            type: string
          item:
            type: object
            properties:
              item:
                type: array
                items:
                  type: object
              snapshot:
                type: boolean
    ClosePositionsOrdersMessage:
      contentType: application/json
      payload:
        type: object
        required:
          - type
          - invocationId
          - item
        properties:
          type:
            type: integer
            const: 2
          invocationId:
            type: string
          item:
            type: object
            properties:
              item:
                type: array
                items:
                  type: object
              snapshot:
                type: boolean
  schemas:
    SignalRStreamInvocation:
      type: object
      required:
        - type
        - invocationId
        - target
        - arguments
      properties:
        type:
          type: integer
          const: 4
          description: SignalR message type for StreamInvocation
        invocationId:
          type: string
          description: Unique identifier for this invocation
        target:
          type: string
          description: Target stream name
          enum:
            - OpenOrders
            - FullBalance
            - MarginData
            - OpenPositions
            - ClosePositionsOrders
        arguments:
          type: array
          description: Array containing the account ID
          items:
            type: string
          minItems: 1
          maxItems: 1
    OpenOrdersStreamItem:
      type: object
      properties:
        item:
          type: array
          items:
            type: object
            properties:
              marketId:
                type: string
              marketType:
                type: string
              marketDisplayName:
                type: string
              marketFullName:
                type: string
              orderId:
                type: string
              timeInForce:
                type: string
              status:
                type: string
              source:
                type: string
              reason:
                type: string
              side:
                type: string
              orderType:
                type: string
              requestedAmount:
                type: number
              remainingAmount:
                type: number
              requestedPrice:
                type: number
              executionPrice:
                type: number
              createdAt:
                type: string
                format: date-time
              updatedAt:
                type: string
                format: date-time
              commissionAssetId:
                type: string
              commissionAmount:
                type: number
              leverage:
                type: integer
              fillFactor:
                type: number
              comment:
                type: string
        snapshot:
          type: boolean
  securitySchemes:
    accessTokenQuery:
      type: httpApiKey
      name: access_token
      in: query
      description: Access token passed as query parameter
