Official PHP client for the Commodities-API.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/commodities-api/sdk
Requires
- php: >=8.0
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpunit/phpunit: ^10.0
This package is not auto-updated.
Last update: 2026-02-10 17:34:01 UTC
README
Official PHP client for the Commodities-API.
Installation
composer require commodities-api/sdk
Usage
<?php require 'vendor/autoload.php'; use CommoditiesApi\CommoditiesClient; $client = new CommoditiesClient('YOUR_ACCESS_KEY'); $response = $client->getLatest([ 'base' => 'USD', 'symbols' => 'RICE,WHEAT,SUGAR', ]); print_r($response);
Methods
// Latest rates $client->getLatest([ 'base' => 'USD', 'symbols' => 'RICE,WHEAT,SUGAR', ]); // Historical (YYYY-MM-DD) $client->getHistorical('2024-05-15', [ 'base' => 'USD', 'symbols' => 'WTIOIL,GOLD', ]); // Time-series $client->getTimeSeries([ 'start_date' => '2024-01-01', 'end_date' => '2024-01-31', 'base' => 'USD', 'symbols' => 'WTIOIL', ]); // Fluctuation $client->getFluctuation([ 'start_date' => '2024-01-01', 'end_date' => '2024-01-31', 'base' => 'USD', 'symbols' => 'WTIOIL,GOLD', ]); // Convert $client->convert([ 'from' => 'USD', 'to' => 'WTIOIL', 'amount' => 100, ]); // Symbols $client->getSymbols(); // Seasonality (cuando exista el endpoint) $client->getSeasonality([ 'symbol' => 'WTIOIL', 'group_by' => 'month', 'years' => 5, ]);
Error handling
use CommoditiesApi\CommoditiesApiException; try { $response = $client->getLatest(['base' => 'USD']); } catch (CommoditiesApiException $e) { echo $e->getMessage(); echo $e->getStatusCode(); var_dump($e->getRaw()); }