You'll need an API key to use the API client. Get a Free Trial API Key.
With Composer:
composer require fastforex/fastforex-php-clientSet the API key once in your bootstrap code.
\FastForex\Client::setApiKey('YOUR_API_KEY');Fetch all currencies, with USD base:
$response = (new FastForex\Client())->fetchAll('USD');
print_r($response);stdClass Object
(
[base] => USD
[results] => stdClass Object
(
[AED] => 3.67246
[AFN] => 77.19882
[ALL] => 101.68772
...
)
[updated] => 2021-02-15 22:13:51
[ms] => 5
)
Fetch GBP, with USD base:
$response = (new FastForex\Client())->fetchOne('USD', 'GBP');
echo $response->result->GBP;Fetch several currencies with USD base:
$response = (new FastForex\Client())->fetchMulti('USD', ['GBP', 'EUR', 'CHF']);Convert 200 USD to GBP:
$response = (new FastForex\Client())->convert('USD', 'GBP', 199.99);Fetch a list of supported currencies
$response = (new FastForex\Client())->currencies();Fetch recent API usage
$response = (new FastForex\Client())->usage();Get all the historical exchange rates for 1st April 2021, with USD base:
$response = (new FastForex\Client())->historical(new \DateTime('2021-04-01'), 'USD');Get a subset of historical exchange rates for 1st April 2021, with USD base:
$response = (new FastForex\Client())->historical(new \DateTime('2021-04-01'), 'USD', ['EUR', 'GBP', 'CHF']);Get a 7-day time-series dataset for EUR to CHF
$response = (new FastForex\Client())->timeSeries(
new \DateTime('2021-04-01'),
new \DateTime('2021-04-07'),
'EUR',
'CHF'
);We throw the following Exceptions:
Usually when input parameters to the client are wrong
When there is problem making the API call, or when there is an error response from the server.
We include the HTTP response code and error message wherever possible:
try {
\FastForex\Client::setApiKey('invalid key');
$response = (new FastForex\Client())->fetchAll('USD');
} catch (\FastForex\Exception\APIException $exception) {
echo $exception->getMessage(), PHP_EOL;
}Our 7-day free trial API keys are unrestricted. All features and full API quota.
This client implements our OpenAPI spec. Interactive documentation available:
- ReadMe - https://fastforex.readme.io
- SwaggerHub - https://app.swaggerhub.com/apis/fastforex/fastFOREX.io