Swap - A PHP exchange rates library

Swap is a PHP library helping you to retrieve exchange rates for currency pairs from different providers such as Google and Yahoo finance, the European Central Bank and more. Additionally, you can setup a chain of providers in order to prevent downtimes from the main one, and cache fetched rates in your favorite storage.

Installation

To install the latest version with Composer, issue the following command

$ composer require florianv/swap

Usage

<?php

// Create an HTTP adapter provided by the egeloen/ivory-http-adapter library
$httpAdapter = new \Ivory\HttpAdapter\FileGetContentsHttpAdapter();

// Create the Yahoo Finance provider
$yahooProvider = new \Swap\Provider\YahooFinanceProvider($httpAdapter);

// Create Swap with the provider
$swap = new \Swap\Swap($yahooProvider);

// Retrieve the latest exchange rate
$rate = $swap->quote('EUR/USD');

// 1.187220
echo $rate;

// 1.187220
echo $rate->getValue();

// 15-01-11 21:30:00
echo $rate->getDate()->format('Y-m-d H:i:s');

This example only shows the basic features of the library and you are invited to check the complete documentation to know about all its functionalities.

Contributing

Contributions are welcomed and appreciated. Feel free to create an issue or send a pull request on the Github repository (https://github.com/florianv/swap).

Note that we use Symfony's policy in terms of code standards and conventions.

comments powered by Disqus