Split a Time Range into Segments by Maximum Candle Count
Source:R/impl_spottrading_market_data_get_klines.R
split_time_range_by_candles.RdSplits 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.
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).
Details
Workflow Overview
Time Validation: Ensures
fromis earlier thanto, aborting if not.Frequency Validation: Confirms
candle_duration_sis an allowed KuCoin frequency usingcheck_allowed_frequency_s().Time Conversion: Converts
fromandtoto UNIX seconds withtime_convert_to_kucoin().Segment Calculation: Calculates segment start times based on
max_candlesandcandle_duration_s, extending ends byoverlapseconds, capped atto.Output Construction: Returns a
data.tablewithfromandtocolumns for each segment.