getAccount function

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

Gets a single account for the current user by UUID.

GET /api/v3/brokerage/accounts/{account_uuid} https://docs.cdp.coinbase.com/api-reference/advanced-trade-api/rest-api/accounts/get-account

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

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

Returns an Account object, or null if no account is found for the given UUID.

Implementation

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

  if (response.statusCode == 200) {
    var jsonResponse = jsonDecode(response.body);
    var jsonAccount = jsonResponse['account'];

    return Account.fromCBJson(jsonAccount);
  } else {
    var url = response.request?.url.toString();
    print('Request to URL $url failed: Response code ${response.statusCode}');
    print('Error Response Message: ${response.body}');
  }
  return null;
}