getProductCandles method

Future<List<Candle>> getProductCandles({
  1. required String productId,
  2. GranularityEnum? granularity,
  3. DateTime? start,
  4. DateTime? end,
})

Get product candles

Historic rates for a product. Rates are returned in grouped buckets. Candle schema is of the form [timestamp, price_low, price_high, price_open, price_close]

https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductcandles

Implementation

Future<List<Candle>> getProductCandles({
  required String productId,
  GranularityEnum? granularity,
  DateTime? start,
  DateTime? end,
}) async {
  var response = await _productsRestClient.getProductCandles(
    productId: productId,
    granularity: granularity,
    start: start,
    end: end,
  );

  if (response.statusCode != 200) throw response;

  List<List> body = List<List>.from(json.decode(response.body));
  return body.map((candle) => Candle.fromList(candle)).toList();
}