getHistoricalData method

  1. @override
Future<List<Candle>> getHistoricalData({
  1. required String symbol,
  2. required Timeframe timeframe,
  3. int count = 500,
  4. DateTime? before,
})
override

Fetches historical OHLCV bars for the specified symbol and timeframe. Optionally pass before to fetch candles older than that timestamp (for pagination).

Implementation

@override
Future<List<Candle>> getHistoricalData({
  required String symbol,
  required Timeframe timeframe,
  int count = 500,
  DateTime? before,
}) async {
  if (_candles.isEmpty) return [];
  final eligible = before != null
      ? _candles.where((c) => c.timestamp.isBefore(before)).toList()
      : _candles;
  if (eligible.isEmpty) return [];
  if (eligible.length <= count) {
    return List.unmodifiable(eligible);
  }
  return List.unmodifiable(eligible.sublist(eligible.length - count));
}