movePortfolioFunds function

Future<bool> movePortfolioFunds({
  1. required Map<String, String> funds,
  2. required String sourcePortfolioUuid,
  3. required String targetPortfolioUuid,
  4. Client? client,
  5. required Credential credential,
  6. bool isSandbox = false,
})

Moves funds between portfolios.

POST /api/v3/brokerage/portfolios/move_funds https://docs.cdp.coinbase.com/api-reference/advanced-trade-api/rest-api/portfolios/move-portfolios-funds

This function makes a POST request to the /portfolios/move_funds endpoint of the Coinbase Advanced Trade API.

funds - A map containing the amount and currency of the funds to be moved. sourcePortfolioUuid - The UUID of the source portfolio. targetPortfolioUuid - The UUID of the target portfolio. credential - The user's API credentials. isSandbox - Whether to use the sandbox environment.

Returns true if the funds were moved successfully.

Implementation

Future<bool> movePortfolioFunds(
    {required Map<String, String> funds,
    required String sourcePortfolioUuid,
    required String targetPortfolioUuid,
    http.Client? client,
    required Credential credential,
    bool isSandbox = false}) async {
  Map<String, dynamic> body = {
    'funds': funds,
    'source_portfolio_uuid': sourcePortfolioUuid,
    'target_portfolio_uuid': targetPortfolioUuid
  };

  http.Response response = await postAuthorized('/portfolios/move_funds',
      body: jsonEncode(body),
      client: client,
      credential: credential,
      isSandbox: isSandbox);

  if (response.statusCode == 200) {
    return true;
  } else {
    throw CoinbaseException(
        'Failed to move portfolio funds', response.statusCode, response.body);
  }
}