getOrderByClientOid function

Future<Order?> getOrderByClientOid({
  1. required String clientOid,
  2. required Credential credential,
  3. bool isSandbox = false,
})

Gets a single order for the current user by client OID.

This function makes a GET request to the /orders/client:{client_oid} endpoint of the Coinbase Pro API.

clientOid - The client OID 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 client OID.

Implementation

Future<Order?> getOrderByClientOid(
    {required String clientOid,
    required Credential credential,
    bool isSandbox = false}) async {
  Order? order;

  http.Response response = await getAuthorized('/orders/client:$clientOid',
      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;
}