PHP code example of houseofapis / currencyapi

1. Go to this page and download the library: Download houseofapis/currencyapi 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/ */

    

houseofapis / currencyapi example snippets


use HouseOfApis\CurrencyApi\CurrencyApi;


$currencyApi = new \CurrencyApi\CurrencyApi('API_KEY');

$result = $currencyApi->rates();

$result = $currencyApi
    ->setBase('USD')
    ->setOutput('JSON')
    ->setLimit('BTC,EUR,GBP')
    ->rates();

$result = $currencyApi->currencies();

$result = $currencyApi
    ->setOutput('XML')
    ->currencies();

$result = $currencyApi
    ->setAmount(100)
    ->setFrom('BTC')
    ->setTo('GBP')
    ->convert();

$result = $currencyApi->setDate('2019-01-01')->historical();

$result = $currencyApi
    ->setDate('2019-01-01')
    ->setBase('GBP')
    ->setLimit('USD')
    ->setOutput('JSON')
    ->historical();

$result = $currencyApi->setStartDate('2019-01-01')->setEndDate('2019-01-05')->historical();

$result = $currencyApi
    ->setStartDate('2019-01-01')
    ->setEndDate('2019-01-05')
    ->setBase('GBP')
    ->setLimit('USD,BTC')
    ->setOutput('XML')
    ->timeframe();