getPortfolioBreakdown function

Future<PortfolioBreakdown?> getPortfolioBreakdown({
  1. required String uuid,
  2. Client? client,
  3. required Credential credential,
  4. bool isSandbox = false,
})

Gets the breakdown of a portfolio.

GET /api/v3/brokerage/portfolios/{portfolio_uuid} https://docs.cdp.coinbase.com/api-reference/advanced-trade-api/rest-api/portfolios/get-portfolio-breakdown

This function makes a GET request to the /portfolios/{uuid} endpoint of the Coinbase Advanced Trade API.

uuid - The UUID of the portfolio to be retrieved. credential - The user's API credentials. isSandbox - Whether to use the sandbox environment.

Returns a PortfolioBreakdown object.

Implementation

Future<PortfolioBreakdown?> getPortfolioBreakdown(
    {required String uuid,
    http.Client? client,
    required Credential credential,
    bool isSandbox = false}) async {
  http.Response response = await getAuthorized('/portfolios/$uuid',
      client: client, credential: credential, isSandbox: isSandbox);

  if (response.statusCode == 200) {
    var jsonResponse = jsonDecode(response.body);
    return PortfolioBreakdown.fromCBJson(jsonResponse['breakdown']);
  } else {
    throw CoinbaseException('Failed to get portfolio breakdown',
        response.statusCode, response.body);
  }
}