# Candlesticks

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /v1/candlesticks/{instrument_code}:
    get:
      summary: Candlesticks
      deprecated: false
      description: >-
        Get instrument candlesticks. The response contains up to `countBack`
        candles (default and maximum 5000), newest first, ending at the last
        complete candle before `to`. `from` is validated (it must be a valid
        timestamp, not in the future and not after `to`) but does not limit the
        results: to receive only the candles in a range, set `countBack` to the
        number of candles you need. Fewer candles than requested may be returned
        where there are gaps in the history.

        If there is trading volume in a candle's period, it is based on trades.
        If there is no volume in a candle's period, it is based on the mid price
        (bid/ask average).

        When no candles are found, `status` is `no_data` and `candlesticks` is
        omitted; `next_bar` then gives the start time of the most recent candle
        before `from`, if there is one.
      tags:
        - One Trading Public REST API/Public
        - public
      parameters:
        - name: instrument_code
          in: path
          description: The instrument code, e.g. `BTC_USDC`.
          required: true
          example: BTC_USDC
          schema:
            type: string
        - name: unit
          in: query
          description: Defines the unit of candlestick time granularity (case-insensitive).
          required: true
          example: MINUTES
          schema:
            type: string
            enum:
              - MINUTES
              - HOURS
              - DAYS
              - WEEKS
              - MONTHS
            x-apidog-enum:
              - value: MINUTES
                name: ''
                description: ''
              - value: HOURS
                name: ''
                description: ''
              - value: DAYS
                name: ''
                description: ''
              - value: WEEKS
                name: ''
                description: ''
              - value: MONTHS
                name: ''
                description: ''
        - name: period
          in: query
          description: >-
            Defines the period of candlestick time granularity.


            Combined with the unit, supported resolutions are 1, 5, 15, 30
            MINUTES & 1, 4 HOURS & 1 DAYS & 1 WEEKS & 1 MONTHS.
          required: true
          example: '30'
          schema:
            type: string
        - name: from
          in: query
          description: >-
            ISO 8601 timestamp. Must be a valid date, not in the future, and not
            after `to`. It does not limit the candles returned (see
            description).
          required: true
          example: '2026-02-11T16:42:33.450Z'
          schema:
            type: string
            format: date-time
        - name: to
          in: query
          description: >-
            ISO 8601 timestamp. Candles are returned ending at the last complete
            candle before this time.
          required: true
          example: '2026-12-12T16:42:33.450Z'
          schema:
            type: string
            format: date-time
        - name: countBack
          in: query
          description: >-
            Number of candles to return, newest first. Integer between 1 and
            5000; defaults to 5000.
          required: false
          schema:
            type: string
            default: '5000'
            pattern: ^[0-9]+$
      responses:
        '200':
          x-apidog-name: Success
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    description: '`data` when candles were found, otherwise `no_data`.'
                    enum:
                      - data
                      - no_data
                    x-apidog-enum:
                      - value: data
                        name: ''
                        description: ''
                      - value: no_data
                        name: ''
                        description: ''
                  candlesticks:
                    type: array
                    items:
                      $ref: '#/components/schemas/Candlestick'
                    description: >-
                      Candles, newest first. Present only when `status` is
                      `data`.
                  next_bar:
                    type: string
                    format: date-time
                    description: >-
                      Only when `status` is `no_data`: start time of the most
                      recent candle before `from`, if any.
                x-apidog-orders:
                  - status
                  - candlesticks
                  - next_bar
                required:
                  - status
                x-apidog-ignore-properties: []
              example:
                status: data
                candlesticks:
                  - last_sequence: 1730900885466242800
                    instrument_code: BTC_EUR
                    granularity:
                      unit: MINUTES
                      period: 30
                    high: '100000'
                    low: '100000'
                    open: '100000'
                    close: '100000'
                    volume: '2000.00'
                    time: '2024-11-06T13:59:59.999Z'
                    start_time: '2024-11-06T13:30:00.000Z'
                  - last_sequence: 1730369352914576100
                    instrument_code: BTC_EUR
                    granularity:
                      unit: MINUTES
                      period: 30
                    high: '100000'
                    low: '100000'
                    open: '100000'
                    close: '100000'
                    volume: '100.00'
                    time: '2024-10-31T10:29:59.999Z'
                    start_time: '2024-10-31T10:00:00.000Z'
                  - last_sequence: 1730368016064669000
                    instrument_code: BTC_EUR
                    granularity:
                      unit: MINUTES
                      period: 30
                    high: '10000'
                    low: '10000'
                    open: '10000'
                    close: '10000'
                    volume: '20.00'
                    time: '2024-10-31T09:59:59.999Z'
                    start_time: '2024-10-31T09:30:00.000Z'
                  - last_sequence: 1730362835479252000
                    instrument_code: BTC_EUR
                    granularity:
                      unit: MINUTES
                      period: 30
                    high: '100000'
                    low: '100000'
                    open: '100000'
                    close: '100000'
                    volume: '100.00'
                    time: '2024-10-31T08:29:59.999Z'
                    start_time: '2024-10-31T08:00:00.000Z'
                  - last_sequence: 1730330727170770700
                    instrument_code: BTC_EUR
                    granularity:
                      unit: MINUTES
                      period: 30
                    high: '100000'
                    low: '100000'
                    open: '100000'
                    close: '100000'
                    volume: '200.00'
                    time: '2024-10-30T23:29:59.999Z'
                    start_time: '2024-10-30T23:00:00.000Z'
                  - last_sequence: 1730328614342880500
                    instrument_code: BTC_EUR
                    granularity:
                      unit: MINUTES
                      period: 30
                    high: '100000'
                    low: '100000'
                    open: '100000'
                    close: '100000'
                    volume: '100.00'
                    time: '2024-10-30T22:59:59.999Z'
                    start_time: '2024-10-30T22:30:00.000Z'
          headers: {}
        '400':
          x-apidog-name: Bad Request
          description: >-
            Invalid request. `error` is a human-readable message describing the
            problem.
          content:
            application/json:
              schema: &ref_0
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                '2':
                  summary: Unknown market
                  value:
                    error: The requested market BTC_XYZ is not available.
                '3':
                  summary: Missing unit
                  value:
                    error: No unit parameter.
                '4':
                  summary: Missing period
                  value:
                    error: No period parameter.
                '5':
                  summary: Invalid resolution
                  value:
                    error: Invalid unit and period combination.
                '6':
                  summary: Missing from
                  value:
                    error: No from parameter.
                '7':
                  summary: Invalid from
                  value:
                    error: 'From date: yesterday is not a valid date.'
                '8':
                  summary: From in the future
                  value:
                    error: 'From date: 2099-01-01T00:00:00.000Z is in the future.'
                '9':
                  summary: Missing to
                  value:
                    error: No to parameter.
                '10':
                  summary: Invalid to
                  value:
                    error: 'To date: tomorrow is not a valid date.'
                '11':
                  summary: From after to
                  value:
                    error: >-
                      From date: 2026-02-12T00:00:00.000Z is greater than To
                      date: 2026-02-11T00:00:00.000Z
                '12':
                  summary: Invalid countBack
                  value:
                    error: Countback must be an integer, between 1 and 5000
          headers: {}
        '500':
          x-apidog-name: Server Error
          description: Unexpected server error. `error` is a human-readable message.
          content:
            application/json:
              schema: *ref_0
              examples:
                '13':
                  summary: Server error
                  value:
                    error: Server error.
                '14':
                  summary: Server configuration error
                  value:
                    error: Server configuration error.
          headers: {}
      security: []
      x-apidog-folder: One Trading Public REST API/Public
      x-apidog-status: released
      x-run-in-apidog: https://app.eu.apidog.com/web/project/349694/apis/api-3612083-run
components:
  schemas:
    Candlestick:
      type: object
      properties:
        last_sequence:
          type: integer
          description: >-
            Nanosecond timestamp of the last trade or tick included in the
            candle. The value exceeds 2^53, so JSON parsers that use IEEE-754
            doubles will lose precision in the last digits.
        instrument_code:
          type: string
          description: The instrument the candle belongs to.
        granularity:
          type: object
          properties:
            unit:
              type: string
              enum:
                - MINUTES
                - HOURS
                - DAYS
                - WEEKS
                - MONTHS
              x-apidog-enum:
                - value: MINUTES
                  name: ''
                  description: ''
                - value: HOURS
                  name: ''
                  description: ''
                - value: DAYS
                  name: ''
                  description: ''
                - value: WEEKS
                  name: ''
                  description: ''
                - value: MONTHS
                  name: ''
                  description: ''
            period:
              type: integer
              description: Number of units per candle.
          x-apidog-orders:
            - unit
            - period
          required:
            - unit
            - period
          x-apidog-ignore-properties: []
        high:
          type: string
          description: Highest price in the candle.
        low:
          type: string
          description: Lowest price in the candle.
        open:
          type: string
          description: Opening price.
        close:
          type: string
          description: Closing price.
        volume:
          type: string
          description: >-
            Traded volume in the candle. `0` for candles derived from mid
            prices.
        time:
          type: string
          format: date-time
          description: >-
            End of the candle period (start + granularity − 1 ms). For `MONTHS`,
            a month is counted as 30 days.
        start_time:
          type: string
          format: date-time
          description: Start of the candle period.
      x-apidog-orders:
        - last_sequence
        - instrument_code
        - granularity
        - high
        - low
        - open
        - close
        - volume
        - time
        - start_time
      required:
        - last_sequence
        - instrument_code
        - granularity
        - high
        - low
        - open
        - close
        - volume
        - time
        - start_time
      x-apidog-folder: ''
      x-apidog-ignore-properties: []
    ErrorResponse:
      type: object
      description: >-
        Error body. `error` is a machine-readable code (e.g.
        `INVALID_INSTRUMENT_CODE`) on most endpoints; a few older endpoints
        return a human-readable message in `error` instead and omit
        `error_message`.
      properties:
        error:
          type: string
          description: Error code (or, on older endpoints, a human-readable message).
        error_message:
          type: string
          description: >-
            Human-readable detail. Present on endpoints that return an error
            code in `error`.
      required:
        - error
      x-apidog-orders:
        - error
        - error_message
      x-apidog-folder: ''
      x-apidog-ignore-properties: []
  securitySchemes:
    bearerAuth:
      type: bearer
      scheme: bearer
      description: >-
        API key issued to the account holder, sent as `Authorization: Bearer
        <token>`. The key must hold the `SUBACCOUNT_TRANSFER` scope.
    bearer:
      type: bearer
      scheme: bearer
servers:
  - url: https://api.onetrading.com/fast
    description: Production Env
security: []

```