updateCruzToBtcWithQtrade function

void updateCruzToBtcWithQtrade(
  1. ExchangeRates rates,
  2. {bool rateLimit = false}
)

Updates CRUZ → BTC.

Implementation

void updateCruzToBtcWithQtrade(ExchangeRates rates, {bool rateLimit = false}) {
  if (rates.prepareUpdateRate('CRUZ', 'BTC', rateLimit: rateLimit) == null) {
    return;
  }

  /// {"id":32,"market_currency":"CRUZ","base_currency":"BTC","maker_fee":"0","taker_fee":"0.015","metadata":{},"can_trade":true,"can_cancel":true,"can_view":true},
  /// Reference: https://api.qtrade.io/v1/markets
  int qtradeCruzMarketId = 32;

  /// {"data":{"market":{"id":32,"market_currency":"CRUZ","base_currency":"BTC","maker_fee":"0","taker_fee":"0.015","metadata":{},"can_trade":true,"can_cancel":true,"can_view":false},"recent_trades":[{"id":55989,"amount":"6.70380253","price":"0.00001499","created_at":"2019-08-09T11:27:24.430434Z"}]}}
  rates.httpClient
      .request('https://api.qtrade.io/v1/market/$qtradeCruzMarketId')
      .then((resp) {
    Map<String, dynamic> data = jsonDecode(resp.text)['data'],
        market = data['market'];
    String base = market['market_currency'], currency = market['base_currency'];
    assert(base == 'CRUZ');
    assert(currency == 'BTC');
    rates.updateRate(
        base, currency, num.parse(data['recent_trades'][0]['price']), 'qTrade');
  });
}