portfolioSector method

  1. @override
Future<List<PortfolioSector>> portfolioSector(
  1. Portfolio portfolio, {
  2. String currency = "EUR",
})
override

The portfolioSector method is used to get the portfolio sectors for a given portfolio.

The portfolio argument is used to specify the portfolio.

// Get portfolio sectors for portfolio
final client = BavestRestClient(api_key);
final portfolioSector = client.portfolioSector(portfolio);

Implementation

@override
Future<List<PortfolioSector>> portfolioSector(Portfolio portfolio,
    {String currency = "EUR"}) async {
  const url = '$_baseUrl/portfolio/sector';
  final params = portfolio.toJson()..addAll({'currency': currency});

  final response = await _post(url, params);
  if (_isSuccess(response)) {
    List<dynamic> sectors = jsonDecode(response!.data);
    return sectors.map((e) => PortfolioSector.fromJson(e)).toList();
  }

  throw Exception("could not receive portfolio metrics for $portfolio");
}