portfolioStats method
Future<PortfolioStats>
portfolioStats(
- Portfolio portfolio, {
- String currency = "EUR",
- required int from,
- required int to,
- required CandleResolution resolution,
override
The portfolioStats method is used to get the portfolio stats for a given portfolio.
The portfolio
argument is used to specify the portfolio.
// Get portfolio stats for portfolio
final client = BavestRestClient(api_key);
final portfolioStats = client.portfolioStats(portfolio, from: 1630352898, to: 1655848800, resolution: CandleType.day);
Implementation
@override
Future<PortfolioStats> portfolioStats(Portfolio portfolio,
{String currency = "EUR",
required int from,
required int to,
required CandleResolution resolution}) async {
const url = '$_baseUrl/portfolio/stats';
var params = portfolio.toJson()
..addAll({
"currency": currency,
"from": from,
"to": to,
"resolution": resolution.str,
});
final response = await _post(url, params);
if (_isSuccess(response)) {
var parsedJson = json.decode(response!.data);
Candles candles = Candles.fromJson(parsedJson["series"]);
List<PortfolioRiskModel> riskModels = [];
for (var key in parsedJson["riskReturnRatio"].keys) {
riskModels.add(PortfolioRiskModel.fromValue(
key, parsedJson["riskReturnRatio"][key]));
}
List<List<PortfolioRiskModel>> correlation = [];
for (var key in parsedJson["correlation"].keys) {
List<PortfolioRiskModel> correlationModels = [];
for (var key2 in parsedJson["correlation"][key].keys) {
correlationModels.add(PortfolioRiskModel.fromValue(
key2, parsedJson["correlation"][key][key2]));
}
correlation.add(correlationModels);
}
return PortfolioStats.fromJson(
parsedJson, candles, riskModels, correlation);
}
throw Exception("could not receive portfolio stats for $portfolio");
}