candle method

  1. @override
Future<Candles> candle(
  1. SecurityIdentifier id,
  2. String from,
  3. String to,
  4. CandleResolution resolution, {
  5. String? currency,
})
override

The candle method is used to get the candle data for a given stock symbol. By default, the candle data is returned in EUR. You can specify a different currency by passing the currency argument.

The from and to arguments are used to specify the time range for the candle data in unix timestamp. The resolution argument is used to specify the resolution of the candle data.

Valid resolutions are 1, 5, 60, D, W, M.

// Get candle data for Apple in EUR
final client = BavestRestClient(api_key);
final candle = client.candle(SecurityIdentifier(symbol: "AAPL"), '1630352898', '1655848800',  CandleType.day, currency: 'EUR);

Implementation

@override
Future<Candles> candle(SecurityIdentifier id, String from, String to,
    CandleResolution resolution,
    {String? currency}) async {
  const url = '$_baseUrl/candle';
  final params = {
    "from": from,
    "to": to,
    "resolution": resolution.str,
    "currency": currency ?? "EUR",
  }..addAll(id.toJson());

  final response = await _post(url, params);
  if (_isSuccess(response)) {
    return Candles.fromJson(jsonDecode(response!.data));
  }

  throw Exception('Failed to get candle for $id');
}