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

AbandonedArchivedLibrary[API Development](/categories/api)

ashallendesign/exchange-rates
=============================

A package for interacting with the exchangerate.host API

v1.0.0(4y ago)22413MITPHPPHP ^8.0

Since Nov 21Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ash-jc-allen/exchange-rates)[ Packagist](https://packagist.org/packages/ashallendesign/exchange-rates)[ Docs](https://github.com/ash-jc-allen/exchange-rates)[ GitHub Sponsors](https://github.com/ash-jc-allen)[ RSS](/packages/ashallendesign-exchange-rates/feed)WikiDiscussions master Synced today

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

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

[![Latest Version on Packagist](https://camo.githubusercontent.com/0a1ccd7968eaf3911bb2ff45d644cf46c87993879d2afdf96de831782c227770/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617368616c6c656e64657369676e2f65786368616e67652d72617465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashallendesign/exchange-rates)[![Build Status](https://camo.githubusercontent.com/27f7e346e77251e9a2c61bb76fe0a71ee482dd0c82d3c2b9a54d9003d39cc799/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6173682d6a632d616c6c656e2f65786368616e67652d72617465732f72756e2d74657374733f7374796c653d666c61742d737175617265)](https://github.com/ash-jc-allen/exchange-rates)[![Total Downloads](https://camo.githubusercontent.com/445a35b666a91843359b0f6cfd42826f512263d29b1ee53112c9d84555a74447/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617368616c6c656e64657369676e2f65786368616e67652d72617465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashallendesign/exchange-rates)[![PHP from Packagist](https://camo.githubusercontent.com/c413f03168ca232f221cbc4a6fcbb1707e6531931990a4e0c6b7303aa19ea8da/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f617368616c6c656e64657369676e2f65786368616e67652d72617465733f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashallendesign/exchange-rates)[![GitHub license](https://camo.githubusercontent.com/e6421159bea6b02ff109cf3cdc4a852e7d9d2d717eeff6b5812a669033154745/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6173682d6a632d616c6c656e2f65786368616e67652d72617465733f7374796c653d666c61742d737175617265)](https://github.com/ash-jc-allen/short-url/blob/master/LICENSE)

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

[](#table-of-contents)

- [Overview](#overview)
- [Installation](#installation)
- [Usage](#usage)
    - [Methods](#methods)
        - [Exchange Rate](#exchange-rate)
            - [Getting the Rate Between Two Currencies](#getting-the-rate-between-two-currencies)
            - [Getting the Rate Between More Than Two Currencies](#getting-the-rate-between-more-than-two-currencies)
        - [Exchange Rates Between Date Range](#exchange-rates-between-date-range)
            - [Getting the Rates Between Two Currencies](#getting-the-rates-between-two-currencies)
            - [Getting the Rates Between More Than Two Currencies](#getting-the-rates-between-more-than-two-currencies)
        - [Convert Currencies](#convert-currencies)
            - [Converting Between Two Currencies](#converting-between-two-currencies)
            - [Converting Between More Than Two Currencies](#converting-between-more-than-two-currencies)
        - [Convert Currencies Between Date Range](#convert-currencies-between-date-range)
            - [Converting Between Two Currencies in a Date Range](#converting-between-two-currencies-in-a-date-range)
            - [Converting Between More Than Two Currencies in a Date Range](#converting-between-more-than-two-currencies-in-a-date-range)
- [Testing](#testing)
- [Security](#security)
- [Contribution](#contribution)
- [Credits](#credits)
- [Changelog](#changelog)
- [Upgrading](#upgrading)
- [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 ashallendesign/exchange-rates
```

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

- PHP 8.0

Usage
-----

[](#usage)

### 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 = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

$exchangeRates->currencies();
```

#### Exchange Rate

[](#exchange-rate)

##### Getting the Rate Between Two Currencies

[](#getting-the-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:

```
$exchangeRates = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

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

// $result: '1.10086'
```

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

##### Getting the Rate Between More Than Two Currencies

[](#getting-the-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.

The example below shows how to get the exchange rates from 'GBP' to 'EUR' and 'USD' for today.

```
$exchangeRates = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

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

// $result: [
//     'EUR' => '1.10086',
//     'USD' => '1.25622'
// ];
```

#### Exchange Rates Between Date Range

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

##### Getting the Rates Between Two Currencies

[](#getting-the-rates-between-two-currencies)

To get the exchange rates between two currencies between a given date range, 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:

```
$exchangeRates = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

$result = $exchangeRates->exchangeRateBetweenDateRange(
    'GBP',
    'EUR',
    Carbon::now()->subWeek(),
    Carbon::now()
);

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

##### Getting the Rates Between More Than Two Currencies

[](#getting-the-rates-between-more-than-two-currencies)

To get the exchange rates for multiple currencies in one call, you can pass an array of currency codes strings as the second parameter to the `->exchangeRateBetweenDateRange()` method.

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

```
$exchangeRates = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

$result = $exchangeRates->exchangeRateBetweenDateRange(
    'GBP',
    ['EUR', 'USD'],
    Carbon::now()->subDays(3),
    Carbon::now(),
);

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

#### Convert Currencies

[](#convert-currencies)

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).

##### Converting Between Two Currencies

[](#converting-between-two-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.

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

```
$exchangeRates = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

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

// $result: '110.15884906'
```

Note: If a Carbon date object is passed as the third parameter, the exchange rate for that day will be used (if valid). If no date is passed, today's exchange rate will be used.

##### Converting Between More Than Two Currencies

[](#converting-between-more-than-two-currencies)

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.

The example below show how to convert £1 'GBP' to 'EUR' and 'USD' at today's exchange rate:

```
$exchangeRates = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

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

// $result: [
//     'EUR' => '110.15884906',
//     'USD' => '125.30569081'
// ];
```

#### Convert Currencies Between Date Range

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

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).

##### Converting Between Two Currencies in a Date Range

[](#converting-between-two-currencies-in-a-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.

The example below shows how to convert £1 'GBP' to 'EUR' using the exchange rates for the past 3 days:

```
$exchangeRates = new \AshAllenDesign\ExchangeRates\Classes\ExchangeRate();

$exchangeRates->convertBetweenDateRange(
    100,
    'GBP',
    'EUR',
    Carbon::now()->subDays(3),
    Carbon::now()
);

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

##### Converting Between More Than Two Currencies in a Date Range

[](#converting-between-more-than-two-currencies-in-a-date-range)

You can also use the `->convertBetweenDateRange()` method to convert a monetary value from one currency to multiple currencies using the exchange rates between a date range. To do this, you can pass an array of currency codes strings as the third parameter.

The example below show how to convert £1 'GBP' to 'EUR' and 'USD' at the past three days' exchange rates:

```
$exchangeRates = new ExchangeRate();
$result = $exchangeRates->exchangeRateBetweenDateRange('GBP', ['EUR', 'USD'], Carbon::now()->subDays(3), Carbon::now());

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

Testing
-------

[](#testing)

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

```
composer test
```

Security
--------

[](#security)

If you find any security related issues, please contact me directly at  to report it.

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 `master` branch.

Credits
-------

[](#credits)

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

Changelog
---------

[](#changelog)

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

Upgrading
---------

[](#upgrading)

Check the [UPGRADE](UPGRADE.md) guide to get more information on how to update this library to newer versions.

License
-------

[](#license)

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

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.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

Unknown

Total

1

Last Release

1630d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

phpexchange ratesashallendesign

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[ashallendesign/laravel-exchange-rates

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

485677.8k](/packages/ashallendesign-laravel-exchange-rates)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[mailchimp/transactional

458.9M16](/packages/mailchimp-transactional)[resend/resend-php

Resend PHP library.

564.7M21](/packages/resend-resend-php)[optiosteam/payconiq-client-php

Payconiq API client library for PHP developed by Optios.

1273.4k](/packages/optiosteam-payconiq-client-php)[jeffreyhyer/alpaca-trade-api-php

PHP SDK for the Alpaca trade API

285.0k](/packages/jeffreyhyer-alpaca-trade-api-php)

PHPackages © 2026

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