getAccountByCurrency function

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

Gets a single account for the current user by currency.

This function makes a GET request to the /accounts endpoint of the Coinbase Pro API and filters the results by currency.

currency - The currency 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 currency.

Implementation

Future<Account?> getAccountByCurrency(String currency,
    {required Credential credential, bool isSandbox = false}) async {
  List<Account> accounts =
      await getAccounts(credential: credential, isSandbox: isSandbox);

  if (accounts.isNotEmpty) {
    for (Account account in accounts) {
      if (account.currency == currency) {
        return account;
      }
    }
  }
  return null;
}