updateBtcToCurrencyWithCoinbase function

void updateBtcToCurrencyWithCoinbase(
  1. String currencyCode,
  2. ExchangeRates rates,
  3. {bool rateLimit = false}
)

Updates BTC → currency.

Implementation

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

  /// {"data":{"base":"BTC","currency":"USD","amount":"11784.005"}}
  rates.httpClient
      .request('https://api.coinbase.com/v2/prices/spot?currency=$currencyCode')
      .then((resp) {
    Map<String, dynamic> data = jsonDecode(resp.text)['data'];
    String base = data['base'], currency = data['currency'];
    assert(base == 'BTC');
    assert(currency == currencyCode);
    rates.updateRate(base, currency, num.parse(data['amount']), 'Coinbase');
  });
}