:currency_exchange: Currency exchange rates library

Overview

Swap

Build status Total Downloads Scrutinizer Version

Swap allows you to retrieve currency exchange rates from various services such as Fixer or currencylayer and optionally cache the results. It is integrated to other libraries like moneyphp/money and provides a Symfony Bundle and a Laravel Package.

Sponsors

Fixer is a simple and lightweight API for foreign exchange rates that supports up to 170 world currencies.
currencylayer provides reliable exchange rates and currency conversions for your business up to 168 world currencies.

QuickStart

$ composer require php-http/curl-client nyholm/psr7 php-http/message florianv/swap
use Swap\Builder;

// Build Swap
$swap = (new Builder())

    // Use the Fixer.io service as first level provider
    ->add('fixer', ['access_key' => 'your-access-key'])
     
    // Use the currencylayer.com service as first fallback
    ->add('currency_layer', ['access_key' => 'secret', 'enterprise' => false])
     
->build();
    
// Get the latest EUR/USD rate
$rate = $swap->latest('EUR/USD');

// 1.129
$rate->getValue();

// 2016-08-26
$rate->getDate()->format('Y-m-d');

// Get the EUR/USD rate 15 days ago
$rate = $swap->historical('EUR/USD', (new \DateTime())->modify('-15 days'));

We recommend to use the services that support our project, providing a free plan up to 1,000 requests per day.

Documentation

The documentation for the current branch can be found here.

Services

Here is the list of the currently implemented services:

Service Base Currency Quote Currency Historical
Fixer EUR (free, no SSL), * (paid) * Yes
currencylayer USD (free), * (paid) * Yes
exchangeratesapi USD (free), * (paid) * Yes
Abstract * * No
coinlayer * Crypto (Limited standard currencies) * Crypto (Limited standard currencies) Yes
European Central Bank EUR * Yes
National Bank of Romania RON, AED, AUD, BGN, BRL, CAD, CHF, CNY, CZK, DKK, EGP, EUR, GBP, HRK, HUF, INR, JPY, KRW, MDL, MXN, NOK, NZD, PLN, RSD, RUB, SEK, TRY, UAH, USD, XAU, XDR, ZAR RON, AED, AUD, BGN, BRL, CAD, CHF, CNY, CZK, DKK, EGP, EUR, GBP, HRK, HUF, INR, JPY, KRW, MDL, MXN, NOK, NZD, PLN, RSD, RUB, SEK, TRY, UAH, USD, XAU, XDR, ZAR Yes
Central Bank of the Republic of Turkey * TRY Yes
Central Bank of the Czech Republic * CZK Yes
Central Bank of Russia * RUB Yes
Bulgarian National Bank * BGN Yes
WebserviceX * * No
1Forge * (free but limited or paid) * (free but limited or paid) No
Cryptonator * Crypto (Limited standard currencies) * Crypto (Limited standard currencies) No
CurrencyDataFeed * (free but limited or paid) * (free but limited or paid) No
Open Exchange Rates USD (free), * (paid) * Yes
Xignite * * Yes
Currency Converter API * * Yes (free but limited or paid)
xChangeApi.com * * Yes
fastFOREX.io USD (free), * (paid) * No
Array * * Yes

Additionally, you can add your own services as long as they implement the ExchangeRateService interface.

Integrations

Credits

License

The MIT License (MIT). Please see LICENSE for more information.

Comments
  • Use Httplug

    Use Httplug

    As discussed in #18

    This will break BC with the new constructor signatures. I have chosen to put the $httpClient and $messageAdapter as the two last parameters because they are optional.

    opened by Nyholm 22
  • Suggestion for how to use with Money

    Suggestion for how to use with Money

    My Money representation of choice is https://github.com/mathiasverraes/money/. Do you have an idea how I could bring this library together with Swap?

    I tried to find a way which uses swap's interfaces, but I couldn't find any without interface breaks.

    opened by sagikazarmark 14
  • Generic HTTP Adapter library

    Generic HTTP Adapter library

    Hi there,

    Currently I am working on a generic HTTP Client adapter library utilizing the upcoming PSR for HTTP Messages. I am reaching out for libraries I know whether there is interest for it or not. It collects the best pratices from competitors, and also based on a generic implementation instead of based on needs.

    It is unclear where it will be published, but when it gets ready I will be more than happy to open a PR and integrate it into your package.

    Are you interested?

    opened by sagikazarmark 8
  • New Swap

    New Swap

    I decided to move core features to an independent library (https://github.com/florianv/exchanger) and Swap is now acting as an "easy" wrapper around Exchanger.

    Fixes https://github.com/florianv/swap/issues/51 https://github.com/florianv/swap/issues/21 https://github.com/florianv/swap/issues/19

    opened by florianv 6
  • PHP warning on GoogleFinanceProvider

    PHP warning on GoogleFinanceProvider

    Finding this error in our logs:

    ERROR - 2016-03-06 00:40:01 --> Severity: Warning  --> DOMDocument::loadHTML(): Unexpected end tag : div in Entity, line: 369 /var/app/current/vendor/florianv/swap/src/Provider/GoogleFinanceProvider.php 36
    

    I'll take a look and submit a pull request if I can find the issue, must be some parsing discrepancy.

    opened by ahubers 5
  • Introducing HTTPlug

    Introducing HTTPlug

    Hey there,

    Not sure you heard, but ivory http adapter is going to be deprecated in favor of HTTPlug. There are many advantages in it over ivory. It is basically an HTTP abstraction layer (like ivory) and provides adapters (like ivory). A key difference is that it is an abstraction for CLIENTS, not adapters. So if one day a client decides to implement HTTPlug, the adapter can be deprecated.

    We are also planning to submit it as a proposal for an HTTP Client PSR.

    Would you be interested in a PR replacing ivory with httplug? Although it is not stable yet (RC1 currently) we plan to release a stable next week.

    enhancement 
    opened by sagikazarmark 5
  • [RFC] Consider using Money library

    [RFC] Consider using Money library

    Hi.

    First of all, thanks for this great library.

    I just wanted to suggest something, what do you think about using https://github.com/mathiasverraes/money?

    It provides CurrencyPair for example.

    question 
    opened by umpirsky 5
  • PHP 8 and PHPUnit 9 support

    PHP 8 and PHPUnit 9 support

    Upgraded to PHPUnit 9.4; used $this->expectException() instead of annotations, fixed inherited method declarations.

    Tested with PHP versions: 7.1.33, 7.2.34, 7.3.24, 7.4.12, 8.0.0RC5.

    Fixes #135

    opened by peterdevpl 4
  • Are cryptocurrencies supported by this library?

    Are cryptocurrencies supported by this library?

    Hello,

    I was wondering if criptocurrencies (DASH, ETH, VTC, XBC, XBT,BTC,XLM,XMR,XRP,ZEC as defined by standard ISO 4217) was supported, i.e:

    $example = ( new Builder() )->add('fixer')->build(); $rate = $example->latest( 'BTC/EUR');

    Actually it seems not working (btw they are actually showed in Yahoo Finance). Where could I find list of currencies OK with Swap?

    opened by salvatorecapolupo 4
  • [WIP] Refactoring

    [WIP] Refactoring

    TODO:

    • [x] finish to implement historical rates where possible
    • [x] improve CentralBankOfRepublicTurkeyProvider
    • [x] see about renaming classes / method with better names
    • [ ] review caching using exchange query signatures
    • [x] review exceptions
    opened by florianv 4
  • `Swap\Builder` could just be static

    `Swap\Builder` could just be static

    There is no actual need for making Swap\Builder an instantiable class:

    • $currencyConverter = Swap\Builder::fromYahooFinance();
    • $currencyConverter = Swap\Builder::fromGoogleFinance();

    These are perfectly fine. If multiple providers are required, then just allow constructor injection in the converter itself, which also plays better with other libraries willing to integrate Swap.

    opened by Ocramius 4
Releases(4.3.0)
Owner
Florian Voutzinos
Senior Full-Stack Web Developer. Freelance. ZCE. Creator of Swap.
Florian Voutzinos
Value Object that represents a monetary value (using a currency's smallest unit).

This project has been abandoned. It was only ever intended to be used as an example for PHPUnit features etc. and not for usage in production. I am so

Sebastian Bergmann 735 Dec 30, 2022
A framework agnostic, multi-gateway payment processing library for PHP 5.6+

Omnipay An easy to use, consistent payment processing library for PHP Omnipay is a payment processing library for PHP. It has been designed based on i

The League of Extraordinary Packages 5.7k Jan 4, 2023
PHP 7+ Payment processing library. It offers everything you need to work with payments: Credit card & offsite purchasing, subscriptions, payouts etc. - provided by Forma-Pro

Supporting Payum Payum is an MIT-licensed open source project with its ongoing development made possible entirely by the support of community and our

Payum 1.7k Jan 5, 2023
PHP payment library to easily integrate Baltic banklinks (supports old and new iPizza protocol), E-commerce gateaway (Estcard, Nets Estonia), Liisi Payment Link and Pocopay.

PHP Payment library PHP payment library to easily integrate Baltic banklinks, E-commerce gateaway (Estcard, Nets Estonia), Liizi Payment Link and Poco

Rene Korss 34 Apr 27, 2022
Standardized wrapper for popular currency rate APIs. Currently supports FixerIO, CurrencyLayer, Open Exchange Rates and Exchange Rates API.

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

Alexander Graf 24 Nov 21, 2022
:currency_exchange: Currency exchange rates library

Swap Swap allows you to retrieve currency exchange rates from various services such as Fixer or currencylayer and optionally cache the results. It is

Florian Voutzinos 1.3k Dec 24, 2022
ExchangeRatesAPI - Currency Exchange Rates API SDK

ExchangeRatesAPI - Currency Exchange Rates API SDK This is an unofficial wrapper for the awesome, free ExchangeRatesAPI, which provides exchange rate

Ben Major 33 Jun 28, 2022
Check Exchange Rates for any currency in Laravel.

Exchange Check exchange rates for any currency in Laravel If your app supports multi-currency, you'll no doubt need to check exchange rates. There are

Worksome 94 Oct 9, 2022
Simple Symfony currency exchange demo application (CLI)

Symfony currency exchange demo Keynotes Using a small Symfony installation as possible Using SQLite database for simplicity but with price of some cav

Vladimir Martsul 9 Oct 21, 2022
World Currency list in PHP constants and in array (Currency::USD)

World Currency list in PHP constants and in array (Currency::USD) If you need to work with currencies in the code and describe each time "USD", "EUR"

Krepysh 4 Jun 27, 2022
The Laravel eCommerce DHL Shipping module module calculates the shipping rates based on DHL API for product shipping.

Introduction DHL Shipping Add-on provides DHL Shipping methods for shipping the product. It packs in lots of demanding features that allows your busin

Bagisto 1 May 31, 2022
A php library for coinex exchange apis .

Coinex API PHP Coinex digital coin exchange API for PHP Requirements PHP>=7.1 CURL PHP module Install composer require roozbeh/coinex_php Acquire acce

Roozbeh Baabakaan 3 Nov 12, 2022
Sending Email via Microsoft Exchange Web Services made Easy!

Send Mail via Exchange Web Services! Sending Email via Microsoft Exchange Web Services (EWS) made easy! Installation Install via Composer composer req

Raju Rayhan 19 Jul 19, 2022
Cryptocurrency exchange script Codono supports Auto detection of deposits, Each user is assigned with Unique deposit per coin

#Cryptocurrency exchange script Codono supports Auto detection of deposits, Each user is assigned with Unique deposit per coin. Deposits are detected

null 9 Dec 26, 2022
This document provides the details related to Remittance API. This APIs is used to initiate payment request from Mobile client/others exchange house.

City Bank Remittance API This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. Installation You c

MD ARIFUL HAQUE 2 Oct 2, 2022
Library download currency rate and save in database, It's designed to be extended by any available data source.

Library download currency rate and save in database, It's designed to be extended by any available data source.

Flexmind. Krzysztof Bielecki 2 Oct 6, 2021
A money and currency library for PHP

Brick\Money A money and currency library for PHP. Introduction Working with financial data is a serious matter, and small rounding mistakes in an appl

Brick 1.3k Jan 5, 2023
Value Object that represents a monetary value (using a currency's smallest unit).

This project has been abandoned. It was only ever intended to be used as an example for PHPUnit features etc. and not for usage in production. I am so

Sebastian Bergmann 735 Dec 30, 2022
AstraPay allows Algerian Stores to pay in CryptoCurrency or in Algerian Currency AstraToken

Accept payments in Bitcoin, AstraTokens, Bitcoin Cash, Litecoin, Ethereum, Monero and IOTA directly to your crypto wallet, without any sign-ups or lengthy processes. All you need is to provide your crypto address.

AstraSilicon 12 Apr 15, 2021
All in one monitoring for NKN.org Crypto currency Miners!

nWatch - All in one NKN Crypto currency Miner & wallets monitoring NKN network is based on miners cheap and easy to deploy (from VPS to Raspberry Pi)

null 14 Dec 24, 2022