getOrders function
Future<List<Order> >
getOrders({
- int limit = 1000,
- String status = 'all',
- required Credential credential,
- bool isSandbox = false,
Gets a list of orders for the current user.
This function makes a GET request to the /orders endpoint of the Coinbase Pro API.
limit - A limit on the number of orders to be returned.
status - The status of the orders to be returned.
credential - The user's API credentials.
isSandbox - Whether to use the sandbox environment.
Returns a list of Order objects.
Implementation
Future<List<Order>> getOrders(
{int limit = 1000,
String status = 'all',
required Credential credential,
bool isSandbox = false}) async {
List<Order> orders = [];
Map<String, dynamic>? queryParameters = {'limit': '$limit', 'status': status};
http.Response response = await getAuthorized('/orders',
queryParameters: queryParameters,
credential: credential,
isSandbox: isSandbox);
if (response.statusCode == 200) {
String data = response.body;
var jsonResponse = jsonDecode(data);
for (var jsonObject in jsonResponse) {
orders.add(Order.fromCBJson(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 orders;
}