editPortfolio function

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

Edits a portfolio.

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

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

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

Returns a Portfolio object.

Implementation

Future<Portfolio?> editPortfolio(
    {required String uuid,
    required String name,
    http.Client? client,
    required Credential credential,
    bool isSandbox = false}) async {
  Map<String, dynamic> body = {'name': name};

  http.Response response = await putAuthorized('/portfolios/$uuid',
      body: jsonEncode(body),
      client: client,
      credential: credential,
      isSandbox: isSandbox);

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