oasin/bitcoin-converter
Composer 安装命令:
composer require oasin/bitcoin-converter
包简介
Convert Bitcoin to Fiat currency
README 文档
README
This library helps fintech developers to convert bitcoin to fiat currency or to another cryptocurrency and vice versa.
Available exchange rates providers are:
Features
It is simple, lightweight, extensible, framework agnostic and fast.
- You can convert Bitcoin to any currency (ISO 4217 fiat or another cryptocurrency)
- You can convert any currency (ISO 4217 fiat or another cryptocurrency) to Bitcoin
- It supports different exchange rates providers: Coinbase, Coindesk, Bitpay
- It has baked-in caching (PSR16 compliant, swappable with your own or your framework's)
Install
Lets begin by installing the library by Composer:
$ composer require mitmelon/bitcoin-converter:dev-main
Usage
You can then convert Bitcoin to any currency (ISO 4217 fiat or crypto) by:
use Oasin\BitcoinConverter\Converter; $convert = new Converter; // uses Coinbase as default provider echo $convert->toCurrency('USD', 0.5); echo $convert->toCurrency('LTC', 0.5);
You can also convert any currency (ISO 4217 fiat or crypto) to Bitcoin:
use Oasin\BitcoinConverter\Converter; $convert = new Converter; // uses Coinbase as default provider echo $convert->toBtc(100, 'USD'); echo $convert->toBtc(20, 'LTC');
and it also has its helper function for convenience:
// uses Coinbase as default provider echo to_btc(100, 'USD'); echo to_btc(20, 'LTC');
You can use different exchange rates from providers:
use Oasin\BitcoinConverter\Converter; use Oasin\BitcoinConverter\Provider\CoinbaseProvider; use Oasin\BitcoinConverter\Provider\CoindeskProvider; use Oasin\BitcoinConverter\Provider\BitpayProvider; $convert = new Converter(new CoinbaseProvider); $convert = new Converter(new CoindeskProvider); $convert = new Converter(new BitpayProvider);
You can specify cache expire time (ttl) on provider by:
new CoinbaseProvider($httpClient, $psr16CacheImplementation, 5); // cache expires in 5mins, defaults to 60mins
Contributing
Open for suggestions and requests. Please request through [issue][link-issue] or [pull requests][link-pull-request].
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-18