getAccounts function
Gets a list of accounts for the current user.
This function makes a GET request to the /accounts endpoint of the Coinbase Pro API.
credential - The user's API credentials.
isSandbox - Whether to use the sandbox environment.
Returns a list of Account objects.
Implementation
Future<List<Account>> getAccounts(
{required Credential credential, bool isSandbox = false}) async {
List<Account> accounts = [];
http.Response response = await getAuthorized('/accounts',
credential: credential, isSandbox: isSandbox);
if (response.statusCode == 200) {
String data = response.body;
var jsonResponse = jsonDecode(data);
for (var jsonObject in jsonResponse) {
accounts.add(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 accounts;
}