getProducts function
Gets a list of available products.
This function makes a GET request to the /products endpoint of the Coinbase Pro API.
isSandbox - Whether to use the sandbox environment.
Returns a list of Product objects.
Implementation
Future<List<Product>> getProducts({bool isSandbox = false}) async {
List<Product> products = [];
http.Response response = await get('/products', isSandbox: isSandbox);
if (response.statusCode == 200) {
String data = response.body;
var jsonResponse = jsonDecode(data);
for (var jsonObject in jsonResponse) {
products.add(Product.convertJson(jsonObject));
}
} else {
var url = response.request?.url.toString();
print('Request to URL $url failed.');
}
return products;
}