getCandles method

dynamic getCandles({
  1. required Coin coinData,
  2. required String interval,
})

Implementation

getCandles({required Coin coinData, required String interval}) async {
  if (coinData.pairWith.toUpperCase() == "INR") {
    try {
      fetchCandles(
        symbol: "${coinData.shortName.toUpperCase()}USDT",
        interval: interval,
      ).then((value) {
        kChartCandles.clear();
        lineChart.clear();
        for (int i = 0; i < value.length; i++) {
          kChartCandles.add(KLineEntity.fromCustom(
              time: value[i].date.millisecondsSinceEpoch,
              amount: value[i].high * inrRate,
              change: value[i].volume,
              close: value[i].close * inrRate,
              high: value[i].high * inrRate,
              low: value[i].low * inrRate,
              open: value[i].open * inrRate,
              vol: value[i].volume,
              ratio: value[i].low * inrRate));

          lineChart.add(FlSpot(
            double.parse(value[i].date.millisecondsSinceEpoch.toString()),
            value[i].close * inrRate,
          ));
        }
      });
    } catch (e) {
      kChartCandles.clear();
      lineChart.clear();
      return;
    }
  } else {
    try {
      fetchCandles(
        symbol: coinData.symbol.toUpperCase(),
        interval: interval,
      ).then(
        (value) {
          kChartCandles.clear();
          lineChart.clear();
          for (int i = 0; i < value.length; i++) {
            kChartCandles.add(KLineEntity.fromCustom(
                time: value[i].date.millisecondsSinceEpoch,
                amount: value[i].high,
                change: value[i].volume,
                close: value[i].close,
                high: value[i].high,
                low: value[i].low,
                open: value[i].open,
                vol: value[i].volume,
                ratio: value[i].low));

            lineChart.add(
              FlSpot(
                double.parse(value[i].date.millisecondsSinceEpoch.toString()),
                value[i].close,
              ),
            );
          }
        },
      );
    } catch (e) {
      kChartCandles.clear();
      lineChart.clear();
      return;
    }
  }

  connectToBinanceServer(coinData, interval);
  update();
}