openwse/swap

PHP的汇率库

维护者

详细信息

github.com/openwse/swap

源代码

4.3.1 2022-03-02 20:32 UTC

README

Build status Total Downloads Scrutinizer Version

Swap 允许您从各种服务(如 FixercurrencylayerexchangeratesapiAbstract)检索货币汇率,并可选择缓存结果。它集成到其他库中,如 moneyphp/money,并提供一个 Symfony Bundle 和一个 Laravel 包

赞助商

快速开始

$ 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])
    
    // Use the exchangeratesapi.io service as second fallback
    ->add('exchange_rates_api', ['access_key' => 'secret'])
     
    // Use the abstractapi.com service as third fallback
    ->add('abstract_api', ['api_key' => 'secret'])
->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'));

我们建议使用 支持我们项目的服务,提供每天最多 1,000 次请求的免费计划。

文档

当前分支的文档可以在 这里 找到。

服务

以下是当前实现的服务列表

此外,只要它们实现了 ExchangeRateService 接口,您就可以添加自己的服务。

集成

鸣谢

许可证

MIT 许可证 (MIT)。更多信息请参阅 LICENSE