PHP code example of cmbuckley / exchange-rates
1. Go to this page and download the library: Download cmbuckley/exchange-rates library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cmbuckley / exchange-rates example snippets
use StarSquare\ExchangeRates\Classes\ExchangeRate;
$exchangeRates = new ExchangeRate();
$exchangeRates->setServiceOptions([
'access_key' => '123abc',
]);
$exchangeRates->setServiceOptions([
'access_key' => '123abc',
'tls' => true,
]);
$exchangeRates->currencies();
$result = $exchangeRates->exchangeRate('GBP', 'EUR');
// $result: '1.10086'
$result = $exchangeRates->exchangeRate('GBP', ['EUR', 'USD']);
// $result: [
// 'GBPEUR' => '1.10086',
// 'GBPUSD' => '1.25622'
// ];
$result = $exchangeRates->exchangeRateBetweenDateRange(
'GBP',
'EUR',
(new DateTime)->sub(new DateInterval('P3D')),
new DateTime
);
// $result: [
// '2020-07-07' => [
// 'GBPEUR' => '1.1092623405',
// ],
// '2020-07-08' => [
// 'GBPEUR' => '1.1120625424',
// ],
// '2020-07-09' => [
// 'GBPEUR' => '1.1153867604',
// ],
// ];
$result = $exchangeRates->exchangeRateBetweenDateRange(
'GBP',
['EUR', 'USD'],
(new DateTime)->sub(new DateInterval('P3D')),
new DateTime
);
// $result: [
// '2020-07-07' => [
// 'GBPEUR' => '1.1092623405',
// 'GBPUSD' => '1.2523571825',
// ],
// '2020-07-08' => [
// 'GBPEUR' => '1.1120625424',
// 'GBPUSD' => '1.2550737853',
// ],
// '2020-07-09' => [
// 'GBPEUR' => '1.1153867604',
// 'GBPUSD' => '1.2650716636',
// ],
// ];
$result = $exchangeRates->convert(100, 'GBP', 'EUR');
// $result: '110.15884906'
$result = $exchangeRates->convert(
100,
'GBP',
['EUR', 'USD']
);
// $result: [
// 'GBPEUR' => '110.15884906',
// 'GBPUSD' => '125.30569081'
// ];
$result = $exchangeRates->convertBetweenDateRange(
100,
'GBP',
'EUR',
(new DateTime)->sub(new DateInterval('P3D')),
new DateTime
);
// $result: [
// '2020-07-07' => [
// 'GBPEUR' => '110.92623405',
// ],
// '2020-07-08' => [
// 'GBPEUR' => '111.20625424',
// ],
// '2020-07-09' => [
// 'GBPEUR' => '111.53867604',
// ],
// ];
$result = $exchangeRates->convertBetweenDateRange(
100,
'GBP',
['EUR', 'USD'],
(new DateTime)->sub(new DateInterval('P3D')),
new DateTime
);
// $result: [
// '2020-07-07' => [
// 'GBPEUR' => '110.92623405',
// 'GBPUSD' => '125.23571825',
// ],
// '2020-07-08' => [
// 'GBPEUR' => '111.20625424',
// 'GBPUSD' => '125.50737853',
// ],
// '2020-07-09' => [
// 'GBPEUR' => '111.53867604',
// 'GBPUSD' => '126.50716636',
// ],
// ];