getFillsByOrderId function

Future<List<Fill>> getFillsByOrderId(
  1. String orderID, {
  2. String profileId = 'default',
  3. required Credential credential,
  4. bool isSandbox = false,
})

Gets a list of recent fills for a given order.

This function makes a GET request to the /fills endpoint of the Coinbase Pro API.

orderID - The order ID to get fills for. profileId - The profile ID to get fills for. credential - The user's API credentials. isSandbox - Whether to use the sandbox environment.

Returns a list of Fill objects.

Implementation

Future<List<Fill>> getFillsByOrderId(String orderID,
    {String profileId = 'default',
    required Credential credential,
    bool isSandbox = false}) async {
  List<Fill> fills = [];

  Map<String, dynamic>? queryParameters = {
    "profile_id": profileId,
    "order_id": orderID
  };

  http.Response response = await getAuthorized('/fills',
      queryParameters: queryParameters,
      credential: credential,
      isSandbox: isSandbox);

  if (response.statusCode == 200) {
    String data = response.body;
    var jsonResponse = jsonDecode(data);

    for (var jsonObject in jsonResponse) {
      fills.add(Fill.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 fills;
}