asyncapi: 3.0.0
info:
  title: BBP Trading Server Guest Market Data WebSocket API
  version: 5.0.0
  description: >
    Anonymous WebSocket API for receiving market data in real-time via the SignalR
    JSON Protocol. Anonymous counterpart of the authenticated market data hub at
    /marketdata/v5: it exposes the same five streams with the same item shapes and
    requires no access token. A guest connection carries no account, so nothing
    account-specific is applied to the prices it streams: the same instrument can
    quote differently here and on the authenticated hub. Only public market data is
    served; no account-scoped data is reachable through this hub.
servers:
  production:
    host: '{hostname}'
    pathname: /marketdata/v5/guest
    protocol: wss
    variables:
      hostname:
        default: api.example.com
channels:
  streamInvocation:
    address: StreamInvocation
    messages:
      subscribeRequest:
        $ref: '#/components/messages/StreamInvocationRequest'
  chart:
    address: Chart
    messages:
      chartMessage:
        $ref: '#/components/messages/ChartMessage'
  summary:
    address: Summary
    messages:
      summaryMessage:
        $ref: '#/components/messages/SummaryMessage'
  tradingData:
    address: TradingData
    messages:
      tradingDataMessage:
        $ref: '#/components/messages/TradingDataMessage'
  book:
    address: Book
    messages:
      bookMessage:
        $ref: '#/components/messages/BookMessage'
  tob:
    address: Tob
    messages:
      tobMessage:
        $ref: '#/components/messages/TobMessage'
operations:
  sendStreamInvocation:
    action: send
    channel:
      $ref: '#/channels/streamInvocation'
    messages:
      - $ref: '#/channels/streamInvocation/messages/subscribeRequest'
  receiveChart:
    action: receive
    channel:
      $ref: '#/channels/chart'
    messages:
      - $ref: '#/channels/chart/messages/chartMessage'
  receiveSummary:
    action: receive
    channel:
      $ref: '#/channels/summary'
    messages:
      - $ref: '#/channels/summary/messages/summaryMessage'
  receiveTradingData:
    action: receive
    channel:
      $ref: '#/channels/tradingData'
    messages:
      - $ref: '#/channels/tradingData/messages/tradingDataMessage'
  receiveBook:
    action: receive
    channel:
      $ref: '#/channels/book'
    messages:
      - $ref: '#/channels/book/messages/bookMessage'
  receiveTob:
    action: receive
    channel:
      $ref: '#/channels/tob'
    messages:
      - $ref: '#/channels/tob/messages/tobMessage'
components:
  messages:
    StreamInvocationRequest:
      contentType: application/json
      payload:
        $ref: '#/components/schemas/SignalRStreamInvocation'
      examples:
        - name: Chart
          payload:
            type: 4
            invocationId: '0'
            target: 'Chart'
            arguments:
              - 'spot.btc_usdt@5m'
        - name: Summary
          payload:
            type: 4
            invocationId: '1'
            target: 'Summary'
            arguments:
              - - 'spot.btc_usdt'
                - 'cfd.eur_usd'
        - name: TradingData
          payload:
            type: 4
            invocationId: '2'
            target: 'TradingData'
            arguments:
              - - 'spot.btc_usdt'
                - 'cfd.eur_usd'
        - name: Book
          payload:
            type: 4
            invocationId: '3'
            target: 'Book'
            arguments:
              - 'spot.btc_usdt'
        - name: Tob
          payload:
            type: 4
            invocationId: '4'
            target: 'Tob'
            arguments:
              - - 'spot.btc_usdt'
                - 'cfd.eur_usd'
    ChartMessage:
      contentType: application/json
      payload:
        type: object
        required:
          - type
          - invocationId
          - item
        properties:
          type:
            type: integer
            const: 2
          invocationId:
            type: string
          item:
            $ref: '#/components/schemas/CandleStreamItem'
      examples:
        - payload:
            type: 2
            invocationId: '0'
            item:
              instrument: 'spot.btc_usdt'
              low: '64100.5'
              high: '64980.0'
              open: '64200.0'
              close: '64870.5'
              start: '2026-01-21T10:00:00Z'
              end: '2026-01-21T10:05:00Z'
    SummaryMessage:
      contentType: application/json
      payload:
        type: object
        required:
          - type
          - invocationId
          - item
        properties:
          type:
            type: integer
            const: 2
          invocationId:
            type: string
          item:
            $ref: '#/components/schemas/SummaryStreamItem'
      examples:
        - payload:
            type: 2
            invocationId: '1'
            item:
              items:
                - marketId: 'spot.btc_usdt'
                  last: '64870.5'
                  high24hr: '65900.0'
                  low24hr: '63120.0'
                  percentChange: '0.0212'
              snapshot: true
    TradingDataMessage:
      contentType: application/json
      payload:
        type: object
        required:
          - type
          - invocationId
          - item
        properties:
          type:
            type: integer
            const: 2
          invocationId:
            type: string
          item:
            $ref: '#/components/schemas/TradingDataStreamItem'
      examples:
        - payload:
            type: 2
            invocationId: '2'
            item:
              markets:
                - marketId: 'spot.btc_usdt'
                  type: 'Spot'
                  displayName: 'BTC / USDT'
                  fullName: 'Bitcoin vs Tether'
                  price: '64870.5'
                  priceInRAT: '64870.5'
                  priceChange24hr: '0.0212'
                  priceChangeAbs24hr: '1345.0'
                  highPrice24hr: '65900.0'
                  lowPrice24hr: '63120.0'
              snapshot: true
    BookMessage:
      contentType: application/json
      payload:
        type: object
        required:
          - type
          - invocationId
          - item
        properties:
          type:
            type: integer
            const: 2
          invocationId:
            type: string
          item:
            $ref: '#/components/schemas/OrderBookStreamItem'
      examples:
        - payload:
            type: 2
            invocationId: '3'
            item:
              instrument: 'spot.btc_usdt'
              askTotalAmount: '12.5'
              bidTotalAmount: '11.2'
              asks:
                - price: '64880.0'
                  amount: '0.5'
                  total: '0.5'
              bids:
                - price: '64870.0'
                  amount: '0.7'
                  total: '0.7'
              version: '184213'
              snapshot: true
    TobMessage:
      contentType: application/json
      payload:
        type: object
        required:
          - type
          - invocationId
          - item
        properties:
          type:
            type: integer
            const: 2
          invocationId:
            type: string
          item:
            $ref: '#/components/schemas/TopOfTheBookStreamItem'
      examples:
        - payload:
            type: 2
            invocationId: '4'
            item:
              markets:
                - marketId: 'spot.btc_usdt'
                  ask: '64880.0'
                  bid: '64870.0'
              snapshot: true
  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:
            - Chart
            - Summary
            - TradingData
            - Book
            - Tob
        arguments:
          type: array
          description: >
            Single-element array — unlike the authenticated hub, no accountId is
            passed. Chart takes one "marketSymbol@period" string, where period is
            one of 1m, 5m, 15m, 30m, 1h, 4h, 12h, 1d, 1w, 1M. Book takes one
            market symbol string. Summary, TradingData, and Tob each take an
            array of market symbols.
          minItems: 1
          maxItems: 1
          items:
            oneOf:
              - type: string
              - type: array
                items:
                  type: string
    CandleStreamItem:
      type: object
      required:
        - instrument
        - low
        - high
        - open
        - close
        - start
        - end
      properties:
        instrument:
          type: string
        low:
          type: string
          pattern: \d+(\.\d+){0,1}
        high:
          type: string
          pattern: \d+(\.\d+){0,1}
        open:
          type: string
          pattern: \d+(\.\d+){0,1}
        close:
          type: string
          pattern: \d+(\.\d+){0,1}
        start:
          type: string
          format: date-time
        end:
          type: string
          format: date-time
    SummaryStreamItem:
      type: object
      required:
        - items
        - snapshot
      properties:
        items:
          type: array
          items:
            type: object
            required:
              - marketId
            properties:
              marketId:
                type: string
              last:
                type: string
                nullable: true
              high24hr:
                type: string
                nullable: true
              low24hr:
                type: string
                nullable: true
              percentChange:
                type: string
                nullable: true
        snapshot:
          type: boolean
    TradingDataStreamItem:
      type: object
      required:
        - markets
        - snapshot
      properties:
        markets:
          type: array
          items:
            type: object
            required:
              - marketId
              - type
              - displayName
              - fullName
            properties:
              marketId:
                type: string
              type:
                type: string
                enum:
                  - Spot
                  - Cfd
                  - Perpetual
              displayName:
                type: string
              fullName:
                type: string
              price:
                type: string
                nullable: true
              priceInRAT:
                type: string
                nullable: true
              priceChange24hr:
                type: string
                nullable: true
              priceChangeAbs24hr:
                type: string
                nullable: true
              highPrice24hr:
                type: string
                nullable: true
              lowPrice24hr:
                type: string
                nullable: true
              markPrice:
                type: string
                nullable: true
                description: Perpetual markets only.
              fundingRate:
                type: string
                nullable: true
                description: Perpetual markets only.
        snapshot:
          type: boolean
    OrderBookStreamItem:
      type: object
      required:
        - instrument
        - askTotalAmount
        - bidTotalAmount
        - asks
        - bids
        - version
        - snapshot
      properties:
        instrument:
          type: string
        askTotalAmount:
          type: string
          pattern: \d+(\.\d+){0,1}
        bidTotalAmount:
          type: string
          pattern: \d+(\.\d+){0,1}
        asks:
          type: array
          items:
            $ref: '#/components/schemas/OrderBookLevel'
        bids:
          type: array
          items:
            $ref: '#/components/schemas/OrderBookLevel'
        version:
          type: string
        snapshot:
          type: boolean
    OrderBookLevel:
      type: object
      required:
        - price
        - amount
        - total
      properties:
        price:
          type: string
          pattern: \d+(\.\d+){0,1}
        amount:
          type: string
          pattern: \d+(\.\d+){0,1}
        total:
          type: string
          pattern: \d+(\.\d+){0,1}
    TopOfTheBookStreamItem:
      type: object
      required:
        - markets
        - snapshot
      properties:
        markets:
          type: array
          items:
            type: object
            required:
              - marketId
            properties:
              marketId:
                type: string
              ask:
                type: string
                nullable: true
              bid:
                type: string
                nullable: true
        snapshot:
          type: boolean
