Skip to contents

Splits a time range into segments based on a maximum number of candles, given a candle duration in seconds, adding an overlap to ensure data continuity.

Usage

split_time_range_by_candles(
  from,
  to,
  candle_duration_s,
  max_candles = 1500,
  overlap = 1
)

Arguments

from

POSIXct object representing the start time.

to

POSIXct object representing the end time.

candle_duration_s

Numeric value; duration of one candle in seconds.

max_candles

Integer; maximum number of candles per segment (default 1500).

overlap

Numeric; seconds to extend each segment’s end for overlap (default 1).

Value

data.table with columns from and to, each row defining a segment as POSIXct objects.

Details

Workflow Overview

  1. Time Validation: Ensures from is earlier than to, aborting if not.

  2. Frequency Validation: Confirms candle_duration_s is an allowed KuCoin frequency using check_allowed_frequency_s().

  3. Time Conversion: Converts from and to to UNIX seconds with time_convert_to_kucoin().

  4. Segment Calculation: Calculates segment start times based on max_candles and candle_duration_s, extending ends by overlap seconds, capped at to.

  5. Output Construction: Returns a data.table with from and to columns for each segment.

API Endpoint

Not applicable (helper segmentation function).

Usage

Utilised to divide large time ranges into manageable segments for fetching KuCoin klines data, respecting the API’s 1500-candle limit per request.

Official Documentation

Not directly tied to a specific endpoint; supports KuCoin klines API pagination.

Examples

if (FALSE) { # \dontrun{
from <- lubridate::now() - 2 * 3600
to <- lubridate::now()
candle_duration_s <- 60
segments <- split_time_range_by_candles(from = from, to = to, candle_duration_s = candle_duration_s)
print(segments)
} # }