houseofapis / currencyapi
Composer package for the CurrencyApi.net JSON & XML live currency feed
Requires
- php: >=7.1.0|^8
- ext-curl: *
- ext-json: *
- ext-simplexml: *
Requires (Dev)
- php-coveralls/php-coveralls: ^2.6
- php-mock/php-mock-phpunit: ^2.7
- phpunit/phpunit: ^8.5|^9.6
This package is auto-updated.
Last update: 2024-11-05 15:54:03 UTC
README
CurrencyApi.net provides live currency rates via a REST API. A live currency feed for over 152 currencies, including physical (USD, GBP, EUR + more) and cryptos (Bitcoin, Litecoin, Ethereum + more). A JSON and XML currency api updated every 60 seconds.
Features:
- Live exchange rates (updated every 60 seconds).
- 152 currencies world currencies.
- Popular cryptocurrencies included; Bitcoin, Litecoin etc.
- Convert currencies on the fly with the convert endpoint.
- Historical currency rates back to year 2000.
- Easy to follow documentation
Signup for a free or paid account here.
This package is a:
PHP wrapper for CurrencyApi.net endpoints.
Developer Guide
For an easy to following developer guide, check out our PHP Developer Guide.
Alternatively keep reading below.
Prerequisites
- Minimum PHP 7.1+
- Working on PHP 8.2.10
- Free or Paid account with CurrencyApi.net
- Composer or clone this repo
Test Coverage
- 100% coverage
Installation
Using composer:
composer require houseofapis/currencyapi
then include the package with:
use HouseOfApis\CurrencyApi\CurrencyApi;
Without composer:
require_once('/path/to/currencyapi/src/CurrencyApi.php'); $currencyApi = new \CurrencyApi\CurrencyApi('API_KEY');
Usage
Live rates:
$result = $currencyApi->rates();
Example with all available methods:
$result = $currencyApi ->setBase('USD') ->setOutput('JSON') ->setLimit('BTC,EUR,GBP') ->rates();
Available methods for rates endpoint
List of available currencies:
$result = $currencyApi->currencies();
Example with all available methods:
$result = $currencyApi ->setOutput('XML') ->currencies();
Available methods for currencies endpoint
Convert:
$result = $currencyApi ->setAmount(100) ->setFrom('BTC') ->setTo('GBP') ->convert();
Available methods for convert endpoint
Historical:
$result = $currencyApi->setDate('2019-01-01')->historical();
Example with all available methods:
$result = $currencyApi ->setDate('2019-01-01') ->setBase('GBP') ->setLimit('USD') ->setOutput('JSON') ->historical();
Available methods for historical endpoint
Timeframe:
$result = $currencyApi->setStartDate('2019-01-01')->setEndDate('2019-01-05')->historical();
Example with all available methods:
$result = $currencyApi ->setStartDate('2019-01-01') ->setEndDate('2019-01-05') ->setBase('GBP') ->setLimit('USD,BTC') ->setOutput('XML') ->timeframe();
Available methods for timeframe endpoint