getProduct function

Future<Product?> getProduct({
  1. required String productId,
  2. Client? client,
  3. bool isSandbox = false,
})

Gets a single product by product ID.

GET /api/v3/brokerage/market/products/{product_id} https://docs.cdp.coinbase.com/api-reference/advanced-trade-api/rest-api/public/get-public-product

This function makes a GET request to the /products/{product_id} endpoint of the Coinbase Advanced Trade API.

productId - The ID of the product to be returned. isSandbox - Whether to use the sandbox environment.

Returns a Product object, or null if no product is found for the given product ID.

Implementation

Future<Product?> getProduct(
    {required String productId,
    http.Client? client,
    bool isSandbox = false}) async {
  http.Response response = await get('/market/products/$productId',
      client: client, isSandbox: isSandbox);

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

    return Product.fromCBJson(jsonResponse);
  } else {
    throw CoinbaseException(
        'Failed to get product', response.statusCode, response.body);
  }
}