getAccount function

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

Gets a single account for the current user by account ID.

This function makes a GET request to the /accounts/{account_id} endpoint of the Coinbase Pro API.

accountId - The ID 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 account ID.

Implementation

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

  if (response.statusCode == 200) {
    var jsonObject = jsonDecode(response.body);
    return Account.convertJson(jsonObject);
  } 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;
}