getProductCandlesAuthorized function
Gets product candles.
GET /v3/brokerage/products/{product_id}/candles https://docs.cdp.coinbase.com/api-reference/advanced-trade-api/rest-api/products/get-product-candles
This function makes a GET request to the /products/{product_id}/candles endpoint of the Coinbase Advanced Trade API.
productId - The ID of the product to be returned.
start - A start time for the candles.
end - A end time for the candles.
granularity - The granularity of the candles.
credential - The user's API credentials.
isSandbox - Whether to use the sandbox environment.
Returns a list of Candle objects.
Implementation
Future<List<Candle>> getProductCandlesAuthorized(
{required String productId,
required String start,
required String end,
required String granularity,
http.Client? client,
required Credential credential,
bool isSandbox = false}) async {
List<Candle> candles = [];
Map<String, String> queryParameters = {
'start': start,
'end': end,
'granularity': granularity,
};
http.Response response = await getAuthorized('/products/$productId/candles',
queryParameters: queryParameters,
client: client,
credential: credential,
isSandbox: isSandbox);
if (response.statusCode == 200) {
var jsonResponse = jsonDecode(response.body);
var jsonCandles = jsonResponse['candles'];
for (var jsonObject in jsonCandles) {
candles.add(Candle.fromJson(jsonObject));
}
} else {
throw CoinbaseException(
'Failed to get product candles', response.statusCode, response.body);
}
return candles;
}