etfHoldings method

  1. @override
Future<EtfHoldings> etfHoldings(
  1. SecurityIdentifier id
)
override

The etfHoldings method is used to get the ETF holdings for a given ETF symbol.

The id argument is used to specify the ETF id e.g. symbol

// Get ETF holdings for SPY
final client = BavestRestClient(api_key);
final etfHoldings = client.etfHoldings('SPY');

Implementation

@override
Future<EtfHoldings> etfHoldings(SecurityIdentifier id) async {
  const url = '$_baseUrl/etf/holdings';
  final params = id.toJson();

  var response = await _post(url, params);
  if (_isSuccess(response)) {
    return EtfHoldings.fromJson(jsonDecode(response!.data));
  }

  throw Exception("could not receive etf profile for $id");
}