PHPackages                             cmbuckley/exchange-rates - 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. cmbuckley/exchange-rates

ActiveLibrary[API Development](/categories/api)

cmbuckley/exchange-rates
========================

A package for interacting with the exchangerate.host API

2.0.0(2y ago)01MITPHPPHP ^8.2

Since Nov 21Pushed 2y agoCompare

[ Source](https://github.com/cmbuckley/exchange-rates)[ Packagist](https://packagist.org/packages/cmbuckley/exchange-rates)[ Docs](https://github.com/cmbuckley/exchange-rates)[ GitHub Sponsors](https://github.com/ash-jc-allen)[ GitHub Sponsors](https://github.com/cmbuckley)[ RSS](/packages/cmbuckley-exchange-rates/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (5)Versions (4)Used By (0)

[![PHP Exchange Rates](/docs/logo.png)](/docs/logo.png)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4f1d8b577b7df759c3cda2b30cd6a37be123837edcc9db7fb1c3c7f708c76c28/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636d6275636b6c65792f65786368616e67652d72617465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cmbuckley/exchange-rates)[![Build Status](https://camo.githubusercontent.com/9e6cc8a5606c8f5662df0c7cdf5487ee7a43398627e7f482a354827e0ac714b6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636d6275636b6c65792f65786368616e67652d72617465732f63692d74657374732e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/cmbuckley/exchange-rates)[![Total Downloads](https://camo.githubusercontent.com/d19f2d642c323a886d665c11e3af472220f37b9e81a3b0d8bf00b449c019c2c4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636d6275636b6c65792f65786368616e67652d72617465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cmbuckley/exchange-rates)[![PHP from Packagist](https://camo.githubusercontent.com/bf4fd094b2bb50d0fe13fcb42543fd6eb19ded55796148caddf3d9e7d5a7292b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f636d6275636b6c65792f65786368616e67652d72617465733f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cmbuckley/exchange-rates)[![GitHub license](https://camo.githubusercontent.com/c551d62ff0b5e54aeb8e63943047f9dca5de52327e6f7b4e4fa562e20182a2a1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636d6275636b6c65792f65786368616e67652d72617465733f7374796c653d666c61742d737175617265)](https://github.com/cmbuckley/exchange-rates/blob/main/LICENSE.md)

Table of Contents
-----------------

[](#table-of-contents)

- [Overview](#overview)
- [Installation](#installation)
- [Usage](#usage)
    - [Setup](#setup)
    - [Methods](#methods)
        - [Available Currencies](#available-currencies)
        - [Exchange Rate Between Two Currencies](#exchange-rate-between-two-currencies)
        - [Exchange Rate Between More Than Two Currencies](#exchange-rate-between-more-than-two-currencies)
        - [Exchange Rates Between Date Range](#exchange-rates-between-date-range)
        - [Convert Currencies](#convert-currencies)
        - [Convert Currencies Between Date Range](#convert-currencies-between-date-range)
- [Testing](#testing)
- [Contribution](#contribution)
- [Credits](#credits)
- [Changelog](#changelog)
- [License](#license)

Overview
--------

[](#overview)

Exchange Rates is a simple PHP package used for interacting with the [exchangerate.host](https://exchangerate.host) API. You can use it to get the latest or historical exchange rates and convert monetary values between different currencies and cryptocurrencies.

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require cmbuckley/exchange-rates
```

The package has been developed and tested to work with the following minimum requirements:

- PHP 8.2

Usage
-----

[](#usage)

### Setup

[](#setup)

The [exchangerate.host](https://exchangerate.host) service requires an access key, which you can sign up and request for free. You need to add a payment card to get the key, but you won't be charged if you're on the free plan. You are resticted to 100 requests per month on the free plan.

Set the API key as follows:

```
use StarSquare\ExchangeRates\Classes\ExchangeRate;

$exchangeRates = new ExchangeRate();

$exchangeRates->setServiceOptions([
    'access_key' => '123abc',
]);
```

The API also does not support HTTPS on the free plan. If you are on a paid plan and want to use HTTPS, pass the `tls`service option:

```
$exchangeRates->setServiceOptions([
    'access_key' => '123abc',
    'tls'        => true,
]);
```

### Methods

[](#methods)

#### Available Currencies

[](#available-currencies)

To get the available currencies that are supported by the package, you can use the `currencies()` method like so:

```
$exchangeRates->currencies();
```

#### Exchange Rate Between Two Currencies

[](#exchange-rate-between-two-currencies)

To get the exchange for one currency to another, you can use the `exchangeRate()` method.

The example below shows how to get the exchange rate from GBP to EUR for today:

```
$result = $exchangeRates->exchangeRate('GBP', 'EUR');

// $result: '1.10086'
```

If a valid date is passed as the third parameter, the exchange rate for that day will be returned. If no date is passed, today's exchange rate will be used.

#### Exchange Rate Between More Than Two Currencies

[](#exchange-rate-between-more-than-two-currencies)

It is possible to get the exchange rates for multiple currencies in one call. This can be particularly useful if you are needing to get many exchange rates at once and do not want to make multiple API calls.

To do this, you can use `exchangeRate()` method and pass an array of currency code strings as the second parameter. This will return an array containing the exchange rates as strings:

```
$result = $exchangeRates->exchangeRate('GBP', ['EUR', 'USD']);

// $result: [
//     'GBPEUR' => '1.10086',
//     'GBPUSD' => '1.25622'
// ];
```

As above, you can pass a date as the third parameter to get the exchange rates for that day.

#### Exchange Rates Between Date Range

[](#exchange-rates-between-date-range)

To get the exchange rates between two currencies and a range of dates, you can use the `exchangeRateBetweenDateRange()` method.

The example below shows how to get the exchange rates from GBP to EUR for the past 3 days:

```
$result = $exchangeRates->exchangeRateBetweenDateRange(
    'GBP',
    'EUR',
    (new DateTime)->sub(new DateInterval('P3D')),
    new DateTime
);

// $result: [
//     '2020-07-07' => [
//         'GBPEUR' => '1.1092623405',
//     ],
//     '2020-07-08' => [
//         'GBPEUR' => '1.1120625424',
//     ],
//     '2020-07-09' => [
//         'GBPEUR' => '1.1153867604',
//     ],
// ];
```

As before, you can pass an array of currency codes as the second parameter:

```
$result = $exchangeRates->exchangeRateBetweenDateRange(
    'GBP',
    ['EUR', 'USD'],
    (new DateTime)->sub(new DateInterval('P3D')),
    new DateTime
);

// $result: [
//     '2020-07-07' => [
//         'GBPEUR' => '1.1092623405',
//         'GBPUSD' => '1.2523571825',
//      ],
//     '2020-07-08' => [
//         'GBPEUR' => '1.1120625424',
//         'GBPUSD' => '1.2550737853',
//      ],
//     '2020-07-09' => [
//         'GBPEUR' => '1.1153867604',
//         'GBPUSD' => '1.2650716636',
//      ],
// ];
```

#### Convert Currencies

[](#convert-currencies)

Similar to how you can get the exchange rate from one currency to another, you can also convert a monetary value from one currency to another. To do this you can use the `convert()` method.

When passing in the monetary value (first parameter) that is to be converted, it's important that you pass it in the lowest denomination of that currency. For example, £1 GBP would be passed in as 100 (as £1 = 100 pence).

The example below shows how to convert £1 to EUR at today's exchange rate:

```
$result = $exchangeRates->convert(100, 'GBP', 'EUR');

// $result: '110.15884906'
```

If a valid date is passed as the third parameter, the exchange rate for that day will be used. If no date is passed, today's exchange rate will be used.

You can also use the `convert()` method to convert a monetary value from one currency to multiple currencies. To do this, you can pass an array of currency codes strings as the third parameter:

```
$result = $exchangeRates->convert(
    100,
    'GBP',
    ['EUR', 'USD']
);

// $result: [
//     'GBPEUR' => '110.15884906',
//     'GBPUSD' => '125.30569081'
// ];
```

#### Convert Currencies Between Date Range

[](#convert-currencies-between-date-range)

Similar to getting the exchange rates between a date range, you can also get convert monetary values from one currency to another using the exchange rates. To do this you can use the `convertBetweenDateRange()` method:

```
$result = $exchangeRates->convertBetweenDateRange(
    100,
    'GBP',
    'EUR',
    (new DateTime)->sub(new DateInterval('P3D')),
    new DateTime
);

// $result: [
//     '2020-07-07' => [
//         'GBPEUR' => '110.92623405',
//      ],
//     '2020-07-08' => [
//         'GBPEUR' => '111.20625424',
//      ],
//     '2020-07-09' => [
//         'GBPEUR' => '111.53867604',
//      ],
// ];
```

You can also convert to multiple currencies:

```
$result = $exchangeRates->convertBetweenDateRange(
    100,
    'GBP',
    ['EUR', 'USD'],
    (new DateTime)->sub(new DateInterval('P3D')),
    new DateTime
);

// $result: [
//     '2020-07-07' => [
//         'GBPEUR' => '110.92623405',
//         'GBPUSD' => '125.23571825',
//      ],
//     '2020-07-08' => [
//         'GBPEUR' => '111.20625424',
//         'GBPUSD' => '125.50737853',
//      ],
//     '2020-07-09' => [
//         'GBPEUR' => '111.53867604',
//         'GBPUSD' => '126.50716636',
//      ],
// ];
```

Testing
-------

[](#testing)

To run the tests for the package, you can use the following command:

```
composer test
```

Contribution
------------

[](#contribution)

If you wish to make any changes or improvements to the package, feel free to make a pull request.

To contribute to this library, please use the following guidelines before submitting your pull request:

- Write tests for any new functions that are added. If you are updating existing code, make sure that the existing tests pass and write more if needed.
- Follow [PSR-12](https://www.php-fig.org/psr/psr-12/) coding standards.
- Make all pull requests to the `main` branch.

Credits
-------

[](#credits)

- [Chris Buckley](https://cmbuckley.co.uk)
- [Ash Allen](https://ashallendesign.co.uk)
- [Jess Pickup](https://jesspickup.co.uk) (Logo)
- [All Contributors](https://github.com/cmbuckley/exchange-rates/graphs/contributors)

Changelog
---------

[](#changelog)

Check the [CHANGELOG](CHANGELOG.md) to get more information about the latest changes.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 60.7% of commits — single point of failure

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 ~420 days

Total

3

Last Release

789d ago

Major Versions

v1.0.1 → 2.0.02024-03-11

PHP version history (2 changes)v1.0.0PHP ^8.0

2.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/e29fd3a5d8c52d1c03e23db521db10ac5689472aa7ff8913b2ca794dcb099ba6?d=identicon)[cmbuckley](/maintainers/cmbuckley)

---

Top Contributors

[![ash-jc-allen](https://avatars.githubusercontent.com/u/39652331?v=4)](https://github.com/ash-jc-allen "ash-jc-allen (17 commits)")[![cmbuckley](https://avatars.githubusercontent.com/u/80938?v=4)](https://github.com/cmbuckley "cmbuckley (10 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

exchange rateexchangerateexchangerate.host

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cmbuckley-exchange-rates/health.svg)

```
[![Health](https://phpackages.com/badges/cmbuckley-exchange-rates/health.svg)](https://phpackages.com/packages/cmbuckley-exchange-rates)
```

###  Alternatives

[ashallendesign/laravel-exchange-rates

A wrapper package for interacting with the exchangeratesapi.io API.

485677.8k](/packages/ashallendesign-laravel-exchange-rates)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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