asyncapi: 3.0.0
info:
  title: BBP Trading Server Stop Orders WebSocket API
  version: 4.0.0
  description: WebSocket API for receiving stop orders data in real-time via SignalR JSON Protocol

servers:
  production:
    host: '{hostname}'
    pathname: /frontoffice/ws/v4/stop-orders
    protocol: wss
    variables:
      hostname:
        default: api.example.com
    security:
      - $ref: '#/components/securitySchemes/accessTokenQuery'

channels:
  streamInvocation:
    address: StreamInvocation
    messages:
      subscribeRequest:
        $ref: '#/components/messages/StreamInvocationRequest'

  openStopOrders:
    address: OpenStopOrders
    messages:
      openStopOrdersMessage:
        $ref: '#/components/messages/OpenStopOrdersMessage'

operations:
  sendStreamInvocation:
    action: send
    channel:
      $ref: '#/channels/streamInvocation'
    messages:
      - $ref: '#/channels/streamInvocation/messages/subscribeRequest'

  receiveOpenStopOrders:
    action: receive
    channel:
      $ref: '#/channels/openStopOrders'
    messages:
      - $ref: '#/channels/openStopOrders/messages/openStopOrdersMessage'

components:
  messages:
    StreamInvocationRequest:
      contentType: application/json
      payload:
        $ref: '#/components/schemas/SignalRStreamInvocation'
      examples:
        - name: OpenStopOrders
          payload:
            type: 4
            invocationId: "0"
            target: "OpenStopOrders"
            arguments:
              - "6839712e47201389687ba09f"

    OpenStopOrdersMessage:
      contentType: application/json
      payload:
        type: object
        required:
          - type
          - invocationId
          - item
        properties:
          type:
            type: integer
            const: 2
          invocationId:
            type: string
          item:
            $ref: '#/components/schemas/StopOrdersStreamItem'
      examples:
        - payload:
            type: 2
            invocationId: "0"
            item:
              data:
                - orderId: "01HQXYZ9K3M7N8P2Q4R5S6T7V8"
                  orderType: "Limit"
                  timeInForce: "Gtc"
                  side: "Buy"
                  requestedAmount: 1.5
                  requestedPrice: 45000.00
                  activationPrice: 44000.00
                  marketId: "BTCUSD"
                  marketDisplayName: "Bitcoin / US Dollar"
                  marketType: "Cfd"
                  marketFullName: "Bitcoin vs US Dollar"
                  createdAt: "2026-01-21T10:00:00Z"
                  updatedAt: "2026-01-21T10:00:00Z"
                  status: "WaitingForActivation"
                  leverage: 10
                  comment: "Stop order waiting for activation"

  schemas:
    SignalRStreamInvocation:
      type: object
      required:
        - type
        - target
        - arguments
      properties:
        type:
          type: integer
          const: 4
        invocationId:
          type: string
        target:
          type: string
          enum:
            - OpenStopOrders
        arguments:
          type: array
          minItems: 1
          maxItems: 1
          items:
            type: string

    StopOrdersStreamItem:
      type: object
      required:
        - data
      properties:
        data:
          $ref: '#/components/schemas/StopOrdersCollection'

    StopOrdersCollection:
      type: array
      items:
        $ref: '#/components/schemas/StopOrderMessageV4'

    StopOrderMessageV4:
      type: object
      required:
        - orderId
        - orderType
        - timeInForce
        - side
        - requestedAmount
        - requestedPrice
        - marketId
        - marketDisplayName
        - marketType
        - marketFullName
        - createdAt
        - updatedAt
        - status
      properties:
        orderId:
          type: string
          description: Unique order identifier (ULID format)
        orderType:
          $ref: '#/components/schemas/ApiOrderType'
        timeInForce:
          $ref: '#/components/schemas/ApiOrderTimeInForce'
        side:
          $ref: '#/components/schemas/ApiOrderSide'
        requestedAmount:
          type: number
        requestedPrice:
          type: number
        activationPrice:
          type: number
        marketId:
          type: string
        marketDisplayName:
          type: string
        marketType:
          $ref: '#/components/schemas/ApiMarketType'
        marketFullName:
          type: string
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        cancellationDate:
          type: string
          format: date-time
        status:
          $ref: '#/components/schemas/ApiStopOrderStatus'
        leverage:
          type: integer
        comment:
          type: string

    ApiOrderType:
      type: string
      enum:
        - Market
        - Limit

    ApiOrderSide:
      type: string
      enum:
        - Buy
        - Sell

    ApiOrderTimeInForce:
      type: string
      enum:
        - Gtc
        - Ioc
        - Fok
        - Gtd
        - Day

    ApiStopOrderStatus:
      type: string
      enum:
        - WaitingForActivation
        - Activated
        - Rejected

    ApiMarketType:
      type: string
      enum:
        - Spot
        - Cfd
        - Perpetual

  securitySchemes:
    accessTokenQuery:
      type: httpApiKey
      in: query
      name: access_token
