PHP code example of forexapi / client

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

    

forexapi / client example snippets


use ForexAPI\Client\Client;

$client = new Client('your-api-key');

use \ForexAPI\Client\ForexAPIClientBuilder;

$builder = (new ForexAPIClientBuilder())
    ->withApiKey('your-api-key')
    ->withBaseUri('https://forexapi.eu/api/')
    ->withHttpAdapter($yourCustomHttpAdapter)
    ->build()
;

use \ForexAPI\Client\ForexAPIClientBuilder;

$builder = (new ForexAPIClientBuilder())
    ->withApiKey('your-api-key')
    ->withPsr18Client($yourCustomPsr18Client)
    ->withPsr17RequestFactory($yourCustomPsr17RequestFactory)
    ->build()
;

$quote = $client->getLiveQuote('USD', 'PLN');

echo $quote->getBase(); // USD
echo $quote->getCounter(); // PLN
echo $quote->getBid(); // Bid price
echo $quote->getAsk(); // Ask price
echo $quote->getMid(); // Mid price
echo $quote->getTimestamp(); // Timestamp

$exchangeRate = $client->getExchangeRate('USD', 'PLN');

echo $exchangeRate->getFrom(); // USD
echo $exchangeRate->getTo(); // PLN
echo $exchangeRate->getRate(); // Exchange rate
echo $exchangeRate->getTimestamp(); // Timestamp

$exchangeRate = $client->getExchangeRates('USD', ['PLN', 'EUR', 'GBP']);

$conversion = $client->convert('USD', 'PLN', 100.0);

echo $conversion->getFrom(); // USD
echo $conversion->getTo(); // PLN
echo $conversion->getAmount(); // 100.0
echo $conversion->getResult(); // Converted amount in PLN
echo $conversion->getTimestamp(); // Timestamp

$conversions = $client->convertMany('USD', ['PLN', 'EUR', 'GBP'], 100.0);