> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pragma.build/llms.txt
> Use this file to discover all available pages before exploring further.

# Candlestick Aggregation



## OpenAPI

````yaml open-apis/node.json get /node/v1/aggregation/candlestick/{base}/{quote}
openapi: 3.1.0
info:
  title: pragma-node
  description: ''
  license:
    name: ''
  version: 0.1.0
servers:
  - url: https://{environment}.pragma.build
    variables:
      environment:
        default: api.devnet
security: []
tags:
  - name: pragma-node
    description: Pragma Node API
paths:
  /node/v1/aggregation/candlestick/{base}/{quote}:
    get:
      tags:
        - Market Data
      operationId: get_ohlc
      parameters:
        - name: base
          in: path
          description: Base asset symbol
          required: true
          schema:
            type: string
        - name: quote
          in: path
          description: Quote asset symbol
          required: true
          schema:
            type: string
        - name: timestamp
          in: query
          description: >-
            The unix timestamp in seconds to retrieve historical price data.

            This endpoint will return the first update whose timestamp is <= the
            provided value.


            If not provided, returns the latest available price.


            # Examples

            - `1_647_820_800`: Returns price data from March 21, 2022 00:00:00
            UTC

            - `null`: Returns the most recent price update


            NOTE: This only works for `median` aggregation
          required: false
          schema:
            oneOf:
              - type: 'null'
              - 99bf9019-06c1-4240-b828-2ad6fd847bce
        - name: interval
          in: query
          description: >-
            Time interval for aggregated price data. Different intervals affect
            how price data is

            aggregated and can be used to get OHLC (Open/High/Low/Close) data at
            various timeframes.


            # Available intervals

            - `100ms`: 100 milliseconds - High frequency trading

            - `1s`: 1 second - Real-time trading

            - `5s`: 5 seconds - Short-term price movements

            - `1min`: 1 minute - Intraday trading

            - `15min`: 15 minutes - Medium-term analysis

            - `1h`: 1 hour - Daily trading patterns

            - `2h`: 2 hours (default) - Extended market analysis

            - `1d`: 1 day - Long-term trends

            - `1w`: 1 week - Strategic market overview
          required: false
          schema:
            oneOf:
              - type: 'null'
              - $ref: '#/components/schemas/Interval'
        - name: routing
          in: query
          description: >-
            Enable price routing through intermediate pairs.

            When true, if a direct price for the requested pair is not
            available,

            the system will attempt to calculate it using intermediate pairs.


            # Example

            For BTC/EUR when routing is enabled:

            - If direct BTC/EUR price is unavailable

            - System might route through BTC/USD and EUR/USD


            Default: true
          required: false
          schema:
            type:
              - boolean
              - 'null'
        - name: aggregation
          in: query
          description: |-
            Method used to aggregate prices from multiple sources.

            # Available modes
            - `median`: Middle value (default, more manipulation resistant)
            - `mean`: Average of all values
            - `twap`: Time-Weighted Average Price
          required: false
          schema:
            oneOf:
              - type: 'null'
              - $ref: '#/components/schemas/AggregationMode'
        - name: entry_type
          in: query
          description: |-
            Type of market entry to retrieve

            # Available types
            - `spot`: Spot market prices (default)
            - `perp`: Perpetual futures prices
            - `future`: Fixed-expiry futures prices
          required: false
          schema:
            oneOf:
              - type: 'null'
              - $ref: '#/components/schemas/EntryType'
        - name: expiry
          in: query
          description: |-
            Expiry date for future contracts in ISO 8601 format.
            Only applicable when `entry_type` is "future".

            # Example
            - `"2024-12-31"`: December 31, 2024 expiry
            - `null`: Not applicable for spot/perp markets
          required: false
          schema:
            type:
              - string
              - 'null'
        - name: with_components
          in: query
          description: >-
            Include source components in the response.

            When true, the response will include price data from individual
            sources.


            # Example

            - `true`: Include source breakdown in response

            - `false`: Return aggregated data only (default)
          required: false
          schema:
            type:
              - boolean
              - 'null'
      responses:
        '200':
          description: Successfully retrieved OHLC data
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetOHLCResponse'
              example:
                data:
                  - close: '82208749021850000000000'
                    high: '82289627995410000000000'
                    low: '82023393045000000000000'
                    open: '82069269773700000000000'
                    time: '2025-03-10T07:30:00'
                pair_id: BTC/USD
        '400':
          description: Invalid parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EntryError'
              example:
                happened_at: '2025-03-10T08:27:29.324879945Z'
                message: >-
                  Invalid timestamp: Timestamp range error: End timestamp is in
                  the future
                resource: EntryModel
        '404':
          description: No data found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EntryError'
              example:
                happened_at: '2025-03-10T08:27:29.324879945Z'
                message: Entry not found
                resource: EntryModel
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EntryError'
              example:
                happened_at: '2025-03-10T08:27:29.324879945Z'
                message: 'Database error: connection failed'
                resource: EntryModel
      security:
        - api_key: []
components:
  schemas:
    Interval:
      type: string
      enum:
        - 100ms
        - 1s
        - 5s
        - 10s
        - 1min
        - 5min
        - 15min
        - 1h
        - 2h
        - 1d
        - 1w
    AggregationMode:
      type: string
      enum:
        - median
        - twap
    EntryType:
      type: string
      enum:
        - spot
        - perp
        - future
    GetOHLCResponse:
      type: object
      description: Response containing OHLC (candlestick) data for a trading pair
      required:
        - pair_id
        - data
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/OHLCEntry'
          description: Array of OHLC entries ordered by timestamp
        pair_id:
          type: string
          description: Trading pair identifier (e.g., "BTC/USD")
      example:
        data:
          - close: '82208749021850000000000'
            high: '82289627995410000000000'
            low: '82023393045000000000000'
            open: '82069269773700000000000'
            time: '2025-03-10T07:30:00'
        pair_id: BTC/USD
    EntryError:
      oneOf:
        - type: object
          required:
            - InvalidSignature
          properties:
            InvalidSignature:
              $ref: '#/components/schemas/SignerError'
          example: invalid signature
        - type: object
          required:
            - InvalidTimestamp
          properties:
            InvalidTimestamp:
              $ref: '#/components/schemas/TimestampError'
          example: invalid timestamp
        - type: string
          enum:
            - InvalidExpiry
          example: invalid expiry
        - type: object
          required:
            - InvalidInterval
          properties:
            InvalidInterval:
              type: array
              items:
                type: object
              maxItems: 2
              minItems: 2
          example: unsupported interval 1s for aggregation median
        - type: object
          required:
            - InvalidOnchainInterval
          properties:
            InvalidOnchainInterval:
              $ref: '#/components/schemas/Interval'
          example: unsupported interval 1s for onchain data
        - type: object
          required:
            - InvalidLoginMessage
          properties:
            InvalidLoginMessage:
              type: string
        - type: object
          required:
            - InvalidDataTypeForNetwork
          properties:
            InvalidDataTypeForNetwork:
              type: array
              items:
                type: object
              maxItems: 2
              minItems: 2
        - type: object
          required:
            - Unauthorized
          properties:
            Unauthorized:
              type: string
        - type: object
          required:
            - PairNotFound
          properties:
            PairNotFound:
              type: string
        - type: object
          required:
            - EntryNotFound
          properties:
            EntryNotFound:
              type: string
        - type: object
          required:
            - PublisherNotFound
          properties:
            PublisherNotFound:
              type: string
        - type: object
          required:
            - RouteNotFound
          properties:
            RouteNotFound:
              type: string
        - type: string
          enum:
            - HistoryNotFound
        - type: object
          required:
            - PublisherError
          properties:
            PublisherError:
              $ref: '#/components/schemas/PublisherError'
        - type: object
          required:
            - PublishData
          properties:
            PublishData:
              type: string
        - type: object
          required:
            - BuildPublish
          properties:
            BuildPublish:
              type: string
        - type: string
          enum:
            - InvalidSigner
        - type: object
          required:
            - DatabaseError
          properties:
            DatabaseError:
              type: string
        - type: object
          required:
            - InternalServerError
          properties:
            InternalServerError:
              type: string
        - type: object
          required:
            - WebSocketError
          properties:
            WebSocketError:
              $ref: '#/components/schemas/WebSocketError'
      example:
        code: UNAUTHORIZED
        message: 'Unauthorized request: Invalid API key'
        timestamp: '2024-03-20T10:30:00Z'
    OHLCEntry:
      type: object
      required:
        - time
        - open
        - low
        - high
        - close
      properties:
        close:
          type: integer
          format: int64
          minimum: 0
        high:
          type: integer
          format: int64
          minimum: 0
        low:
          type: integer
          format: int64
          minimum: 0
        open:
          type: integer
          format: int64
          minimum: 0
        time:
          type: string
          format: date-time
    SignerError:
      oneOf:
        - type: object
          required:
            - ConversionError
          properties:
            ConversionError:
              $ref: '#/components/schemas/ConversionError'
        - type: object
          required:
            - SigningError
          properties:
            SigningError:
              type: string
        - type: object
          required:
            - InvalidSignature
          properties:
            InvalidSignature:
              type: string
        - type: object
          required:
            - Unauthorized
          properties:
            Unauthorized:
              type: string
        - type: object
          required:
            - InvalidMessage
          properties:
            InvalidMessage:
              type: string
    TimestampError:
      oneOf:
        - type: object
          required:
            - RangeError
          properties:
            RangeError:
              $ref: '#/components/schemas/TimestampRangeError'
        - type: object
          required:
            - ToDatetimeErrorU64
          properties:
            ToDatetimeErrorU64:
              type: integer
              format: int64
              minimum: 0
        - type: object
          required:
            - ToDatetimeErrorI64
          properties:
            ToDatetimeErrorI64:
              type: integer
              format: int64
        - type: object
          required:
            - Other
          properties:
            Other:
              type: string
    PublisherError:
      oneOf:
        - type: object
          required:
            - InvalidKey
          properties:
            InvalidKey:
              type: string
        - type: object
          required:
            - InvalidAddress
          properties:
            InvalidAddress:
              type: string
        - type: object
          required:
            - InactivePublisher
          properties:
            InactivePublisher:
              type: string
        - type: string
          enum:
            - NotFound
        - type: string
          enum:
            - InternalServerError
    WebSocketError:
      oneOf:
        - type: string
          enum:
            - ChannelInit
        - type: object
          required:
            - MessageDecode
          properties:
            MessageDecode:
              type: string
        - type: string
          enum:
            - ChannelClose
    ConversionError:
      oneOf:
        - type: string
          enum:
            - FailedSerialization
        - type: string
          enum:
            - InvalidDateTime
        - type: string
          enum:
            - BigDecimalConversion
        - type: string
          enum:
            - FeltConversion
        - type: string
          enum:
            - U128Conversion
        - type: string
          enum:
            - StringTimestampConversion
        - type: string
          enum:
            - StringPriceConversion
        - type: object
          required:
            - FailedSignature
          properties:
            FailedSignature:
              type: string
    TimestampRangeError:
      oneOf:
        - type: string
          enum:
            - StartAfterEnd
        - type: string
          enum:
            - EndInFuture
        - type: string
          enum:
            - StartEqualsEnd
        - type: string
          enum:
            - ConversionError
        - type: object
          required:
            - Other
          properties:
            Other:
              type: string
  securitySchemes:
    api_key:
      type: apiKey
      in: header
      name: x-api-key

````