PHPackages                             florianv/swap - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. florianv/swap

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

florianv/swap
=============

PHP currency conversion library for retrieving exchange rates from 30+ providers, with caching and fallback.

4.5.0(3mo ago)1.3k6.8M↓33.8%14615MITPHPPHP ^8.2CI passing

Since May 12Pushed 2w ago35 watchersCompare

[ Source](https://github.com/florianv/swap)[ Packagist](https://packagist.org/packages/florianv/swap)[ RSS](/packages/florianv-swap/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (13)Versions (37)Used By (15)

Swap
====

[](#swap)

[![Tests](https://github.com/florianv/swap/actions/workflows/tests.yml/badge.svg)](https://github.com/florianv/swap/actions/workflows/tests.yml)[![Psalm](https://github.com/florianv/swap/actions/workflows/psalm.yml/badge.svg)](https://github.com/florianv/swap/actions/workflows/psalm.yml)[![Total Downloads](https://camo.githubusercontent.com/2cb2c020e35039d0a628d7fda792e56dae45c5e762d01ebcd3ce4412706e0641/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666c6f7269616e762f737761702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/florianv/swap)[![Version](https://camo.githubusercontent.com/cba7b599a887890e9306165e8924f64a54722670d7d6c13daf63bda96279d615/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666c6f7269616e762f737761702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/florianv/swap)

> *The easy-to-use PHP currency conversion library. Retrieve exchange rates from 30+ providers, with caching and fallback. Maintained since 2014.*

   [ ![fastFOREX](https://camo.githubusercontent.com/01374173153db590b0bf73ec4f33df21d77996d1fa3c26f1dffe6462029f85fa/68747470733a2f2f636f6e736f6c652e66617374666f7265782e696f2f696d672f66617374666f7265782f6c6f676f2d626b2d316b2e737667) ](https://www.fastforex.io)   **Sponsored by [fastFOREX](https://www.fastforex.io).** Real-time JSON API, 160+ currencies, 55+ years of history, 500+ cryptocurrencies. **Free tier**; paid plans from $18/month. [**→ Get a free fastFOREX API key**](https://www.fastforex.io)  Swap retrieves currency exchange rates in PHP, behind a single API. Use commercial providers in production, or free public sources (ECB, national banks) when you don't need volume. Caching, historical rates and provider fallback are built in. Maintained since 2014.

💡 What is Swap?
---------------

[](#-what-is-swap)

- Swap is a PHP library for currency conversion and exchange rate retrieval.
- It exposes a wide range of exchange rate providers behind a common interface.
- It caches results via PSR-16 SimpleCache.
- It supports historical rates.
- It supports a fallback chain. When a provider errors, the next provider in the chain is tried.

📦 Installation
--------------

[](#-installation)

Swap requires PHP 8.2 or newer.

```
composer require florianv/swap symfony/http-client nyholm/psr7
```

`symfony/http-client` is the PSR-18 HTTP client and `nyholm/psr7` provides the PSR-17 factories. Any PSR-18 / PSR-17 implementation works (see the [documentation](doc/readme.md) for alternatives such as Guzzle).

⚡ Quickstart
------------

[](#-quickstart)

The recommended setup uses **[fastFOREX](https://www.fastforex.io)** (the project's sponsor) as the primary provider. [Grab a free key](https://www.fastforex.io) and you're ready.

```
use Swap\Builder;

// Recommended: fastFOREX. Get a free API key at https://www.fastforex.io
$swap = (new Builder())
    ->add('fastforex', ['api_key' => getenv('FASTFOREX_API_KEY')])
    ->build();

// EUR → USD exchange rate
$rate = $swap->latest('EUR/USD');

$rate->getValue();                 // e.g. 1.0823 (a float)
$rate->getDate()->format('Y-m-d'); // e.g. 2026-04-29
$rate->getProviderName();          // 'fastforex'

// Convert an amount using the returned rate
$amountInEUR = 100.00;
$amountInUSD = $amountInEUR * $rate->getValue();
```

Swap retrieves the rate; your application multiplies the amount by `$rate->getValue()` to perform the conversion.

No API key? Start with the European Central Bank (free, EUR-base only).```
$swap = (new Builder())
    ->add('european_central_bank')
    ->build();

$rate = $swap->latest('EUR/USD');
```

The European Central Bank publishes EUR-base rates with daily granularity. For non-EUR base pairs, more frequent updates, or a wider currency list, switch to fastFOREX or another commercial provider.

🔁 Configuring multiple providers (fallback chain)
-------------------------------------------------

[](#-configuring-multiple-providers-fallback-chain)

A production-grade setup pairs **fastFOREX** with one or more fallbacks for redundancy:

```
$swap = (new Builder())
    // Primary provider, recommended
    ->add('fastforex', ['api_key' => getenv('FASTFOREX_API_KEY')])

    // Free fallback for EUR-base pairs
    ->add('european_central_bank')
    ->build();
```

Providers are tried in order. If a provider does not support the requested currency pair, it is skipped silently. If a provider throws an error, the next provider is tried. If every provider fails, a `ChainException` is thrown with all collected errors.

For amount conversion (including the [moneyphp/money](https://github.com/moneyphp/money) integration via `SwapExchange`), see [Converting amounts](doc/readme.md#converting-amounts) in the documentation.

📊 Providers
-----------

[](#-providers)

Swap supports 30+ exchange rate providers. Pass the **identifier** to `Builder::add()`.

### Commercial providers (require an API key)

[](#commercial-providers-require-an-api-key)

ServiceIdentifierBaseQuoteHistorical⭐ **[fastFOREX](https://www.fastforex.io)****`fastforex`****\*****\*****Yes**AbstractAPI`abstract_api`\*\*Yescoinlayer`coin_layer`\* (crypto)\*YesCryptonator`cryptonator`\* (crypto)\* (crypto)NoCurrency Converter API`currency_converter`\*\*YesCurrency Data (APILayer)`apilayer_currency_data`USD (free), \* (paid)\*YesCurrencyDataFeed`currency_data_feed`\*\*Nocurrencylayer (direct)`currency_layer`USD (free), \* (paid)\*YesExchange Rates Data (APILayer)`apilayer_exchange_rates_data`USD (free), \* (paid)\*Yesexchangerate.host`exchangeratehost`\*\*Yesexchangeratesapi (direct)`exchange_rates_api`USD (free), \* (paid)\*YesFixer (APILayer)`apilayer_fixer`EUR (free), \* (paid)\*YesFixer (direct)`fixer`EUR (free), \* (paid)\*Yes1Forge`forge`\*\*NoOpen Exchange Rates`open_exchange_rates`USD (free), \* (paid)\*YesUniRateAPI`unirate_api`\*\*YesWebserviceX`webservicex`\*\*NoxChangeApi.com`xchangeapi`\*\*YesXignite`xignite`\*\*Yes### Public providers (no API key required)

[](#public-providers-no-api-key-required)

ServiceIdentifierBaseQuoteHistoricalBulgarian National Bank`bulgarian_national_bank`\*BGNYesCentral Bank of the Czech Republic`central_bank_of_czech_republic`\*CZKYesCentral Bank of the Republic of Turkey`central_bank_of_republic_turkey`\*TRYYesCentral Bank of the Republic of Uzbekistan`central_bank_of_republic_uzbekistan`\*UZSYesEuropean Central Bank`european_central_bank`EUR\*YesNational Bank of Georgia`national_bank_of_georgia`\*GELYesNational Bank of Romania`national_bank_of_romania`(limited list)(limited list)YesNational Bank of the Republic of Belarus`national_bank_of_republic_belarus`\*BYNYesNational Bank of Ukraine`national_bank_of_ukraine`\*UAHYesRussian Central Bank`russian_central_bank`\*RUBYesYou can also add your own provider by implementing the `Exchanger\Contract\ExchangeRateService` interface and passing the instance to `Builder::addExchangeRateService()`.

🎯 When should you use Swap?
---------------------------

[](#-when-should-you-use-swap)

- Use Swap when you need to retrieve exchange rates in a PHP application: currency conversion workflows, multi-currency pricing, invoice totals, reconciliation, or historical FX data.
- Use the lower-level [Exchanger](https://github.com/florianv/exchanger) library when Swap's defaults are too opinionated and you want finer control over chain composition, caching, or HTTP plumbing.

🛠 Common use cases
------------------

[](#-common-use-cases)

- Display localized prices in multi-currency storefronts.
- Compute invoice totals across currencies.
- Reconcile multi-currency ledgers using historical rates.
- Power internal FX dashboards with rate history.
- Build currency conversion infrastructure for fintech and ERP applications.

🧭 Which package should I use?
-----------------------------

[](#-which-package-should-i-use)

The Swap ecosystem is a layered toolkit for currency conversion in PHP:

- [**Swap**](https://github.com/florianv/swap). The easy-to-use, high-level API (this package).
- [**Exchanger**](https://github.com/florianv/exchanger). Lower-level, more granular alternative; direct access to the 30+ provider implementations and the `ExchangeRateService` interface.
- [**Laravel Swap**](https://github.com/florianv/laravel-swap). Laravel application of Swap.
- [**Symfony Swap**](https://github.com/florianv/symfony-swap). Symfony integration of Swap.

All four packages are MIT-licensed and require PHP 8.2 or newer.

📚 Documentation
---------------

[](#-documentation)

Caching (PSR-16), HTTP client selection (PSR-18 / Guzzle / `useHttpClient`), error handling (`ChainException`), per-query options and the full provider configuration reference live in [`doc/readme.md`](doc/readme.md). The same content is also published at [florianv.github.io/swap](https://florianv.github.io/swap/).

🙌 Contributing
--------------

[](#-contributing)

Issues and pull requests are welcome. Please see the existing [issues](https://github.com/florianv/swap/issues) before opening a new one.

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [LICENSE](https://github.com/florianv/swap/blob/master/LICENSE) for more information.

👏 Credits
---------

[](#-credits)

- [Florian Voutzinos](https://github.com/florianv)
- [All contributors](https://github.com/florianv/swap/contributors)

###  Health Score

76

—

ExcellentBetter than 100% of packages

Maintenance89

Actively maintained with recent releases

Popularity70

Solid adoption and visibility

Community42

Growing community involvement

Maturity87

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 79% 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 ~131 days

Recently: every ~526 days

Total

34

Last Release

115d ago

Major Versions

1.x-dev → v2.0.02015-01-15

v2.6.0 → v3.0.02016-09-18

2.x-dev → 3.3.02018-02-19

3.x-dev → 4.0.02019-02-12

PHP version history (7 changes)v1.0.0PHP &gt;=5.3.3

v2.0.0PHP &gt;=5.4.0

v3.0.0PHP ^5.5|^7.0

3.0.2PHP ^5.5 || ^7.0

4.0.0PHP ^7.1.3

4.3.0PHP ^7.1.3 || ^8.0

4.5.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1586668?v=4)[Florian Voutzinos](/maintainers/florianv)[@florianv](https://github.com/florianv)

---

Top Contributors

[![florianv](https://avatars.githubusercontent.com/u/1586668?v=4)](https://github.com/florianv "florianv (230 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (20 commits)")[![alies-dev](https://avatars.githubusercontent.com/u/5278175?v=4)](https://github.com/alies-dev "alies-dev (14 commits)")[![ddinchev](https://avatars.githubusercontent.com/u/1397692?v=4)](https://github.com/ddinchev "ddinchev (4 commits)")[![ahubers](https://avatars.githubusercontent.com/u/7432558?v=4)](https://github.com/ahubers "ahubers (4 commits)")[![vinkla](https://avatars.githubusercontent.com/u/499192?v=4)](https://github.com/vinkla "vinkla (2 commits)")[![albertodiaz](https://avatars.githubusercontent.com/u/1932161?v=4)](https://github.com/albertodiaz "albertodiaz (2 commits)")[![tyx](https://avatars.githubusercontent.com/u/245494?v=4)](https://github.com/tyx "tyx (2 commits)")[![ugurerkan](https://avatars.githubusercontent.com/u/473959?v=4)](https://github.com/ugurerkan "ugurerkan (2 commits)")[![avataru](https://avatars.githubusercontent.com/u/209354?v=4)](https://github.com/avataru "avataru (1 commits)")[![arjanwestdorp](https://avatars.githubusercontent.com/u/7716654?v=4)](https://github.com/arjanwestdorp "arjanwestdorp (1 commits)")[![necenzurat](https://avatars.githubusercontent.com/u/145449?v=4)](https://github.com/necenzurat "necenzurat (1 commits)")[![andreicio](https://avatars.githubusercontent.com/u/20474012?v=4)](https://github.com/andreicio "andreicio (1 commits)")[![pascalheidmann](https://avatars.githubusercontent.com/u/19560252?v=4)](https://github.com/pascalheidmann "pascalheidmann (1 commits)")[![pborreli](https://avatars.githubusercontent.com/u/77759?v=4)](https://github.com/pborreli "pborreli (1 commits)")[![rickogden](https://avatars.githubusercontent.com/u/135672?v=4)](https://github.com/rickogden "rickogden (1 commits)")[![rob-browncc](https://avatars.githubusercontent.com/u/199503049?v=4)](https://github.com/rob-browncc "rob-browncc (1 commits)")[![0xflotus](https://avatars.githubusercontent.com/u/26602940?v=4)](https://github.com/0xflotus "0xflotus (1 commits)")[![Chris8934](https://avatars.githubusercontent.com/u/44963939?v=4)](https://github.com/Chris8934 "Chris8934 (1 commits)")[![dannyweeks](https://avatars.githubusercontent.com/u/4365775?v=4)](https://github.com/dannyweeks "dannyweeks (1 commits)")

---

Tags

currencycurrency-conversioncurrency-conversion-librarycurrency-convertercurrency-exchangecurrency-exchange-ratescurrency-ratesexchange-rate-apiexchange-ratesforexforex-apilaravelmoneyphpphp-currency-conversionphp-librarysymfonymoneycurrencyconversionRateexchange rates

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/florianv-swap/health.svg)

```
[![Health](https://phpackages.com/badges/florianv-swap/health.svg)](https://phpackages.com/packages/florianv-swap)
```

###  Alternatives

[florianv/exchanger

PHP exchange rate provider layer for currency conversion: 30+ services, chain fallback, and caching.

1865.0M20](/packages/florianv-exchanger)[anthropic-ai/sdk

Anthropic PHP SDK

163583.3k17](/packages/anthropic-ai-sdk)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)[ujjwal/currency-converter

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

49230.5k](/packages/ujjwal-currency-converter)[florianv/swap-bundle

Drop-in Symfony bundle for currency conversion: configurable services, multi-provider exchange rates with fallback and caching.

64431.5k1](/packages/florianv-swap-bundle)

PHPackages © 2026

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