getOrder function
Future<Order?>
getOrder({
- required String orderId,
- required Credential credential,
- bool isSandbox = false,
Gets a single order for the current user by order ID.
This function makes a GET request to the /orders/{order_id} endpoint of the Coinbase Pro API.
orderId - The ID of the order to be returned.
credential - The user's API credentials.
isSandbox - Whether to use the sandbox environment.
Returns an Order object, or null if no order is found for the given order ID.
Implementation
Future<Order?> getOrder(
{required String orderId,
required Credential credential,
bool isSandbox = false}) async {
Order? order;
http.Response response = await getAuthorized('/orders/$orderId',
credential: credential, isSandbox: isSandbox);
if (response.statusCode == 200) {
String data = response.body;
var jsonResponse = jsonDecode(data);
order = Order.fromCBJson(jsonResponse);
} else {
var url = response.request?.url.toString();
print('Request to URL $url failed: Response code ${response.statusCode}');
print('Error Response Message: ${response.body}');
}
return order;
}