PHPackages                             otherguy/php-currency-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. otherguy/php-currency-api

ActiveLibrary[API Development](/categories/api)

otherguy/php-currency-api
=========================

A PHP API Wrapper to offer a unified programming interface for popular Currency Rate APIs.

1.7(5y ago)2526.2k↓18.8%5MITPHPPHP &gt;=7.3CI failing

Since Jun 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/otherguy/php-currency-api)[ Packagist](https://packagist.org/packages/otherguy/php-currency-api)[ RSS](/packages/otherguy-php-currency-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (11)Used By (0)

💱 Wrapper for popular Currency Exchange Rate APIs
=================================================

[](#-wrapper-for-popular-currency-exchange-rate-apis)

*A PHP API Wrapper to offer a unified programming interface for popular Currency Rate APIs.*

[![Version](https://camo.githubusercontent.com/370132ffcf6a2805a3d999e7d3d1b3d1da6b7e97838f2a8931aab386544e4d2a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f746865726775792f7068702d63757272656e63792d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/otherguy/php-currency-api)[![Installs](https://camo.githubusercontent.com/5ec6fd507f3a116abd702ca42337fccdf989e76d2179bee6d68afc90a5e58925/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f746865726775792f7068702d63757272656e63792d6170693f636f6c6f723d626c7565266c6162656c3d696e7374616c6c73267374796c653d666c61742d737175617265)](https://packagist.org/packages/otherguy/php-currency-api)[![PHP version](https://camo.githubusercontent.com/85ef21809786df82a2b71b1a4aaac14dd1f3ad6a6ecd11f7981503aeb36854ba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6f746865726775792f7068702d63757272656e63792d6170693f7374796c653d666c61742d737175617265)](https://packagist.org/packages/otherguy/php-currency-api)[![Travis CI](https://camo.githubusercontent.com/26719af4d3dce8bc9d3f37dca9cca20147b27cd49cf5e9294e8e577ddbcfe11a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f6f746865726775792f7068702d63757272656e63792d6170692e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/otherguy/php-currency-api)[![Coverage](https://camo.githubusercontent.com/20564a01d9519d2403270f0ca6d06cd98ae6a4cdd8f82a298317347de65ebd23/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6f746865726775792f7068702d63757272656e63792d6170692e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/github/otherguy/php-currency-api?branch=master)[![Coverage](https://camo.githubusercontent.com/ddbde38ac042edb14c3dc0c9d072887edd467edfa99b4512e489fc4579ce1821/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f636f7665726167652d6c65747465722f6f746865726775792f7068702d63757272656e63792d6170692e7376673f7374796c653d666c61742d737175617265)](https://codeclimate.com/github/otherguy/php-currency-api)[![Maintainability](https://camo.githubusercontent.com/c95ec7975dfa8828bc2bdaec6a847533331db57c2e136d14dbdd786b5c04e306/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6d61696e7461696e6162696c6974792f6f746865726775792f7068702d63757272656e63792d6170692e7376673f7374796c653d666c61742d737175617265)](https://codeclimate.com/github/otherguy/php-currency-api)[![License](https://camo.githubusercontent.com/06e9c05daf99c92aa7967f5a4e2bf86d2c3049a3c0910983de7d70ceff1411b8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6f746865726775792f7068702d63757272656e63792d6170692e7376673f7374796c653d666c61742d73717561726526636f6c6f723d6f72616e6765)](LICENSE.md)

Dont worry about your favorite currency conversion service suddenly shutting down or switching plans on you. Switch away easily, without changing your code.

Inspiration 💅
-------------

[](#inspiration-)

I needed a currency conversion API for my travel website but could not find a good PHP package. The idea of the [`Rackbeat/php-currency-api`](https://github.com/Rackbeat/php-currency-api) package came closest but unfortunately it was just a stub and not implemented.

Features 🌈
----------

[](#features-)

- Support for [multiple different APIs](#supported-apis-) through the use of drivers
- A [fluent interface](#fluent-interface) to make retrieving exchange rates convenient and fast
- Consistent return interface that is independent of the driver being used
- [Calculations](#conversion-result) can be made based on the returned data

Supported APIs 🌐
----------------

[](#supported-apis-)

ServiceIdentifier[FixerIO](https://fixer.io)`fixerio`[CurrencyLayer](https://currencylayer.com)`currencylayer`[Open Exchange Rates](https://openexchangerates.org)`openexchangerates`[Exchange Rates API](https://exchangeratesapi.io)`exchangeratesapi`*If you want to see more services added, feel free to [open an issue](https://github.com/otherguy/php-currency-api/issues)!*

Prerequisites 📚
---------------

[](#prerequisites-)

- `PHP 8.x` or `PHP 7.3+` or higher (tested on both `7.3` and `7.4`)
- The [`composer`](https://getcomposer.org) dependency manager for PHP
- An account with one or more of the [API providers](#supported-apis-) listed above

Installation 🚀
--------------

[](#installation-)

Simply require the package using `composer` and you're good to go!

```
$ composer require otherguy/php-currency-api
```

Usage 🛠
-------

[](#usage-)

### Currency Symbol Helper

[](#currency-symbol-helper)

The [`Otherguy\Currency\Symbol`](src/Symbol.php) class provides constants for each supported currency.

> ！**Note:** You are not required to use `Otherguy\Currency\Symbol` to specify symbols. It's simply a convenience helper and does not need to be used. You can simply pass strings like `'USD', 'EUR', ...` to all methods.

```
// 'USD'
$symbol = Otherguy\Currency\Symbol::USD;
```

Use the `all()` method to retrieve an array of all currency symbols:

```
// [ 'AED', 'AFN', ... 'ZWL' ]
$symbols = Otherguy\Currency\Symbol::all();
```

The `names()` method returns an associative array with currency names instead:

```
// [ 'AED' => 'United Arab Emirates Dirham', 'AFN' => 'Afghan Afghani', ... ]
$symbols = Otherguy\Currency\Symbol::names();
```

To get the name of a single currency, use the `name()` method:

```
// 'United States Dollar'
$symbols = Otherguy\Currency\Symbol::name(Otherguy\Currency\Symbol::USD);
```

### Initialize API Instance

[](#initialize-api-instance)

```
$currency = Otherguy\Currency\DriverFactory::make('fixerio'); // driver identifier from supported drivers.
```

To get a list of supported drivers, use the `getDrivers()` method:

```
// [ 'mock', 'fixerio', 'currencylayer', ... ]
$drivers = Otherguy\Currency\DriverFactory::getDrivers()
```

### Set Access Key

[](#set-access-key)

Most API providers require you to sign up and use your issued access key to authenticate against their API. You can specify your access key like so:

```
$currency->accessKey('your-access-token-goes-here');
```

### Set Configuration Options

[](#set-configuration-options)

To set further configuration options, you can use the `config()` method. An example is [CurrencyLayer's JSON formatting option](https://currencylayer.com/documentation#format).

```
$currency->config('format', '1');
```

### Set Base Currency

[](#set-base-currency)

You can use either `from()` or `source()` to set the base currency. The methods are identical.

> ！**Note:** Each driver sets its own default base currency. [FixerIO](https://fixer.io) uses `EUR` as base currency while [CurrencyLayer](https://currencylayer.com) uses `USD`.

Most services only allow you to change the base currency in their paid plans. The driver will throw a `Otherguy\Currency\Exceptions\ApiException` if your current plan does not allow changing the base currency.

```
$currency->source(Otherguy\Currency\Symbol::USD);
$currency->from(Otherguy\Currency\Symbol::USD);
```

### Set Return Currencies

[](#set-return-currencies)

You can use either `to()` or `symbols()` to set the return currencies. The methods are identical. Pass a single currency or an array of currency symbols to either of these methods.

> ！**Note:** Pass an empty array to return all currency symbols supported by this driver. This is the default if you don't call the method at all.

```
$currency->to(Otherguy\Currency\Symbol::BTC);
$currency->symbols([Otherguy\Currency\Symbol::BTC, Otherguy\Currency\Symbol::EUR, Otherguy\Currency\Symbol::USD]);
```

### Latest Rates

[](#latest-rates)

This retrieves the most recent exchange rates and returns a [`ConversionResult`](#conversion-result) object.

```
$currency->get(); // Get latest rates for selected symbols, using set base currency
$currency->get('DKK');  // Get latest rates for selected symbols, using DKK as base currency
```

### Historical Rates

[](#historical-rates)

To retrieve historical exchange rates, use the `historical()` method. Note that you need to specify a date either as a method parameter or by using the `date()` methods. See [Fluent Interface](#fluent-interface) for more information.

```
$currency->date('2010-01-01')->historical();
$currency->historical('2018-07-01');
```

### Convert Amount

[](#convert-amount)

Use the `convert()` method to convert amounts between currencies.

> ！**Note:** Most API providers don't allow access to this method using your free account. You can still use the [Latest Rates](#latest-rates) or [Historical Rates](#historical-rates) endpoints and perform calculations or conversions on the [`ConversionResult`](#conversion-result) object.

```
$currency->convert(10.00, 'USD', 'THB'); // Convert 10 USD to THB
$currency->convert(122.50, 'NPR', 'EUR', '2019-01-01'); // Convert 122.50 NPR to EUR using the rates from January 1st, 2019
```

### Fluent Interface

[](#fluent-interface)

Most methods can be used with a *fluent interface*, allowing you to chain method calls for more readable code:

```
// Namespaces are omitted for readability!
DriverFactory::make('driver')->from(Symbol::USD)->to(Symbol::EUR)->get();
DriverFactory::make('driver')->from(Symbol::USD)->to(Symbol::NPR)->date('2013-03-02')->historical();
DriverFactory::make('driver')->from(Symbol::USD)->to(Symbol::NPR)->amount(12.10)->convert();
```

### Conversion Result

[](#conversion-result)

The [`get()`](#latest-rates) and [`historical()`](#historical-rates) endpoints return a [`ConversionResult`](src/Results/ConversionResult.php) object. This object allows you to perform calculations and conversions easily.

> ！**Note:** Even though free accounts of most providers do not allow you to change the base currency, you can still use the `ConversionResult` object to change the base currency later. This might not be as accurate as changing the base currency directly, though.

> ！**Note:** To convert between two currencies, you need to request both of them in your initial [`get()`](#latest-rates)or [`historical()`](#historical-rates) request. You can not convert between currencies that have not been fetched!

See the following code for some examples of what you can do with the `ConversionResult` object.

```
$result = DriverFactory::make('driver')->from(Symbol::USD)->to([Symbol::EUR, Symbol::GBP])->get();

// [ 'USD' => 1.00, 'EUR' => 0.89, 'GBP' => 0.79 ]
$result->all();

// 'USD'
$result->getBaseCurrency();

// '2019-06-11'
$result->getDate();

// 0.89
$result->rate(Symbol::EUR);

// CurrencyException("No conversion result for BTC!");
$result->rate(Symbol::BTC);

// 5.618
$result->convert(5.0, Symbol::EUR, Symbol::USD);

// [ 'USD' => 1.13, 'EUR' => 1.00, 'GBP' => 0.89 ]
$result->setBaseCurrency(Symbol::EUR)->all();

// 1.12
$result->setBaseCurrency(Symbol::GBP)->rate(Symbol::EUR);
```

Contributing 🚧
--------------

[](#contributing-)

[Pull Requests](https://github.com/otherguy/php-currency-api/pulls) are more than welcome! I'm striving for 100% test coverage for this repository so please make sure to add tests for your code.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~72 days

Recently: every ~161 days

Total

10

Last Release

1882d ago

Major Versions

0.2 → 1.02019-06-13

PHP version history (3 changes)0.1PHP &gt;=7.1

1.4PHP &gt;=7.1.3

1.7PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/11b15de3b9e91b8f506aad61f599f3e5fd8af644f7c57915d55aaa37d743cc3f?d=identicon)[winternight](/maintainers/winternight)

---

Top Contributors

[![otherguy](https://avatars.githubusercontent.com/u/6072721?v=4)](https://github.com/otherguy "otherguy (73 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (72 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (29 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (1 commits)")

---

Tags

api-wrappercomposer-packagecurrencycurrency-apicurrency-conversioncurrency-convertercurrency-converter-phpcurrency-exchangecurrency-exchange-ratescurrency-rate-apisexchange-rate-apiexchange-ratesexchange-rates-apifluent-interfacephp-libraryphp-packagephp73php74php8currencyexchange ratesApi Wrappercurrency-convertercurrency conversionphp8PHP Librarycomposer-packageExchange Rates APIphp74fluent-interfacecurrency-exchangephp73currency ratesphp-packagecurrency-exchange-ratescurrency-converter-phpcurrency-apicurrency-rate-apisexchange-rate-api

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/otherguy-php-currency-api/health.svg)

```
[![Health](https://phpackages.com/badges/otherguy-php-currency-api/health.svg)](https://phpackages.com/packages/otherguy-php-currency-api)
```

###  Alternatives

[fiveam-code/laravel-notion-api

Laravel Wrapper for the Notion API

435224.4k1](/packages/fiveam-code-laravel-notion-api)[ujjwal/currency-converter

Currency Converter Class with features of caching and identifying currency from country Code

49225.4k](/packages/ujjwal-currency-converter)[marcreichel/igdb-laravel

A Laravel wrapper for version 4 of the IGDB API (Apicalypse) including webhook handling

115146.6k1](/packages/marcreichel-igdb-laravel)[currency-cloud/client

A PHP library which implements the complete functionality of v2 of the The Currency Cloud API.

17327.2k](/packages/currency-cloud-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
