priceTicker method

Future<List<BinancePriceTicker>> priceTicker({
  1. String baseUri = defaultUri,
  2. String? symbol,
})

Will get ticker(s) for current price(s).

API Key required : no

Query weight : 1 for a specific symbol, 2 otherwise

Returns a list of BinancePriceTicker containing all returned data when request is a success.

Throws a BinanceApiError if an error occurs.

Implementation

Future<List<BinancePriceTicker>> priceTicker({
  String baseUri = defaultUri,
  String? symbol,
}) async {
  final response = await sendRequest(
    baseUri,
    priceTickerPath,
    queryParameters: symbol != null ? {'symbol': symbol} : null,
  );
  if (symbol == null) {
    // list of tickers
    if (response is List) {
      final tickers = <BinancePriceTicker>[];
      for (final ticker in response) {
        if (ticker is Map<String, dynamic>) {
          tickers.add(BinancePriceTicker.fromJson(ticker));
        } else {
          throw const BinanceApiError(-1, 'unexpected nested ticker format');
        }
      }
      return tickers;
    }
  } else {
    // one ticker
    if (response is Map) {
      if (response is Map<String, dynamic>) {
        return [BinancePriceTicker.fromJson(response)];
      }
    }
  }
  throw const BinanceApiError(-1, 'unexpected ticker format');
}