PHP Classes

OpenExchangeRates: Convert currency amount with Openexchangerates API

Recommend this page to a friend!
  Info   View files Documentation   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-10 (2 months ago) RSS 2.0 feedNot enough user ratingsTotal: 213 This week: 1All time: 8,328 This week: 560Up
Version License PHP version Categories
openexchangerates 0.7.2MIT/X Consortium ...5.3PHP 5, Web services, Finances
Description 

Author

This class can convert currency amounts with the Openexchangerates.org API.

It can send HTTP requests to the Openexchangerates.org API Web server to get the exchange rates between different currencies.

The retrieved information is cached to avoid the overhead of retrieving it repeatedly.

The class can perform several operations with the retrieved information like returning the latest rates, historical data, time series, list of all currencies, convert amounts between two currencies, etc..

The class can perform all OpenExchangeRates operations available either in the paid or free plans.

Picture of Jasenko Rakovic
  Performance   Level  
Name: Jasenko Rakovic <contact>
Classes: 2 packages by
Country: Bosnia and Herzegovina Bosnia and Herzegovina
Age: 35
All time rank: 31135 in Bosnia and Herzegovina Bosnia and Herzegovina
Week rank: 416 Up1 in Bosnia and Herzegovina Bosnia and Herzegovina Up
Innovation award
Innovation award
Nominee: 1x

Documentation

Open Exchange Rates PHP Wrapper

A PHP wrapper for Openexchangerates.org API with extended features for non advanced options plan.

Features

  • Return all available currencies
  • Return latest exchange rates using default base currency USD or custom currency
  • Return historical exchange rates using default base currency USD or custom currency
  • Return dates range exchange rates using default base currency USD or custom currency
  • return single rate
  • Change base currency
  • Convert between currencies
  • Cache exchange rates using Memcache, APC or File cache
  • Set currencies that will be returned in resulting exchange rates

Usage

<?php

use Dzasa\OpenExchangeRates\OpenExchangeRates;
use Dzasa\OpenExchangeRates\Cache;

$config = array(
    'api_key' => 'your_api_key', // required
    'protocol' => 'https', // optional [http|https]
    'client' => 'curl',  // optional [curl|file_get_contents]
    'base' => 'EUR' // optional
);

// using File cache
$cache = new Cache("file", array('cache_dir'=>'/path_to_cache_dir/'));
$exchangeRates = new OpenExchangeRates($config, $cache);

// or using APC
$cache = new Cache("apc");
$exchangeRates = new OpenExchangeRates($config, $cache);

// or using Memcache
$cache = new Cache("memcache", array('host'=>'localhost', 'port'=> 11211));
$exchangeRates = new OpenExchangeRates($config, $cache);

// or not using cache
$exchangeRates = new OpenExchangeRates($config);

// get all currencies
$currencies = $exchangeRates->getAllCurrencies();

// change base currency
$exchangeRates->setBaseCurrency("BAM");

// set currencies
$exchangeRates->setSymbols("BAM,EUR,USD");

// get latest currencies
$latestRates = $exchangeRates->getLatestRates();

// get exchange rates for 01.01.2014, input can be any valid strtotime input for past
$historicalRates = $exchangeRates->getHistorical("2014-01-01");

// get exchange rates for date range, input can be any valid strtotime() input
$timeSeries = $exchangeRates->getTimeSeries("last Friday", "today");

// convert from EUR to BAM with 3 decimals
$convert = $exchangeRates->convert("EUR", "BAM", 10, 3);

// get rate for EUR currency
$singleRate = $exchangeRates->getRate("EUR");

// get base currency
$baseCurrency = $exchangeRates->getBaseCurrency();

// get API license
$license = $exchangeRates->getLicense();

// get API Disclaimer
$disclaimer = $exchangeRates->getDisclaimer();

About

Requirements

  • Works with PHP 5.3 or above.

Submitting bugs and feature requests

Bugs and feature request are tracked on [GitHub]

Version

0.7.2

Author

Jasenko Rakovic - naucnik@gmail.com

License

Licensed under the MIT License - see the LICENSE file for details

[GitHub]:https://github.com/dzasa/php-open-exchange-rates/issues


  Files folder image Files  
File Role Description
Files folder imagesrc (2 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file Cache.php Class Class source
  Plain text file OpenExchangeRates.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:213
This week:1
All time:8,328
This week:560Up