PHP code example of eljump / exchange-rate-fork

1. Go to this page and download the library: Download eljump/exchange-rate-fork 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/ */

    

eljump / exchange-rate-fork example snippets


use CentralBankRussian\ExchangeRate\CBRClient;
use CentralBankRussian\ExchangeRate\Exceptions\ExceptionIncorrectData;
use CentralBankRussian\ExchangeRate\Exceptions\ExceptionInvalidParameter;
use CentralBankRussian\ExchangeRate\ExchangeRate;

 $exchangeRate = new ExchangeRate(new CBRClient());

 try {
     $currencyRateCollection = $exchangeRate
         ->setDate(new DateTime('2020-02-19'))
         ->getCurrencyExchangeRates();

     var_dump($currencyRateCollection);
 }
 catch (ExceptionIncorrectData | ExceptionInvalidParameter $e) {
     echo $e->getMessage();
 }

use CentralBankRussian\ExchangeRate\CBRClient;
use CentralBankRussian\ExchangeRate\Exceptions\ExceptionIncorrectData;
use CentralBankRussian\ExchangeRate\Exceptions\ExceptionInvalidParameter;
use CentralBankRussian\ExchangeRate\ExchangeRate;

 $exchangeRate = new ExchangeRate(
         new CBRClient()
 );
 
 try {
 
     $currencyRate = $exchangeRate
          ->setDate(new DateTime('2020-07-12'))
          ->getCurrencyExchangeRates()
          ->getCurrencyRateBySymbolCode('AMD');
 
     var_dump($currencyRate);
 
 }
 catch (ExceptionIncorrectData | ExceptionInvalidParameter $e) {
      echo $e->getMessage();
 }

use CentralBankRussian\ExchangeRate\CBRClient;
use CentralBankRussian\ExchangeRate\Exceptions\ExceptionIncorrectData;
use CentralBankRussian\ExchangeRate\Exceptions\ExceptionInvalidParameter;
use CentralBankRussian\ExchangeRate\ExchangeRate;

 $exchangeRate = new ExchangeRate(
         new CBRClient()
 );
 
 try {
 
     $rateInRubles = $exchangeRate
          ->setDate(new DateTime('2020-09-30'))
          ->getRateInRubles('AMD');
 
     echo $rateInRubles;
 
 }
 catch (ExceptionIncorrectData | ExceptionInvalidParameter $e) {
      echo $e->getMessage();
 }

use CentralBankRussian\ExchangeRate\Converter;
use CentralBankRussian\ExchangeRate\CBRClient;
use CentralBankRussian\ExchangeRate\Exceptions\ExceptionIncorrectData;
use CentralBankRussian\ExchangeRate\Exceptions\ExceptionInvalidParameter;
use CentralBankRussian\ExchangeRate\ExchangeRate;

try {

    $exchangeRate = new ExchangeRate(
         new CBRClient()
     );

    $converter = new Converter($exchangeRate);

    $val = $converter
        ->setDate(new DateTime('2020-06-10'))
        ->convert(73224, 'USD', 'EUR');

    echo $val;

}
catch (ExceptionIncorrectData | ExceptionInvalidParameter $e) {
    echo $e->getMessage();
}

use CentralBankRussian\ExchangeRate\CBRClient;
use CentralBankRussian\ExchangeRate\Exceptions\ExceptionIncorrectData;
use CentralBankRussian\ExchangeRate\ReferenceData;

$referenceData = new ReferenceData(new CBRClient());

try {
    $currencyCollection = $referenceData->getCurrencyCodesDaily();
    var_dump($currencyCollection);
}
catch (ExceptionIncorrectData $e) {
    echo $e->getMessage();
}

use CentralBankRussian\ExchangeRate\CBRClient;
use CentralBankRussian\ExchangeRate\Exceptions\ExceptionIncorrectData;
use CentralBankRussian\ExchangeRate\ReferenceData;

$referenceData = new ReferenceData(new CBRClient());

try {
    $currencyCollection = $referenceData->getCurrencyCodesMonthly();
    var_dump($currencyCollection);
}
catch (ExceptionIncorrectData $e) {
    echo $e->getMessage();
}