jimmerioles/bitcoin-currency-converter-php
Composer 安装命令:
composer require jimmerioles/bitcoin-currency-converter-php
包简介
A simple and lightweight bitcoin to currency converter and vice versa based on current exchange rates from your chosen provider: Coinbase, Coindesk, Bitpay and etc.
README 文档
README
This library helps developers that need to easily convert bitcoin to fiat currency(ISO 4217) or to another cryptocurrency and vice versa from your exchange rates provider of choice.
Available exchange rates providers are:
If you have any request for other exchange rates provider or other features that you would like for me to add see Contributing.
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)
PHP Versions Support
| Bitcoin Currency Converter | PHP 7.0 | PHP 7.1 | PHP 7.2 | PHP 7.3 | PHP 7.4 | PHP 8.0 | PHP 8.1 | PHP 8.2 | PHP 8.3 | PHP 8.4 |
|---|---|---|---|---|---|---|---|---|---|---|
| original-legacy-codebase | ✅ | ✅ | ||||||||
| 1.x | ✅ | ✅ | ✅ | ✅ | ✅ | |||||
| 2.x | ✅ | ✅ | ✅ | |||||||
| 3.x | ✅ | ✅ |
Install
Lets begin by installing the library by Composer:
$ composer require jimmerioles/bitcoin-currency-converter-php
Usage
You can then convert Bitcoin to any currency (ISO 4217 fiat or crypto) by:
use Jimmerioles\BitcoinCurrencyConverter\Converter; $convert = new Converter; // uses Coinbase as default provider echo $convert->toCurrency('USD', 0.5); // 2000.00 echo $convert->toCurrency('LTC', 0.5); // 10.12345678
or you can use the helper function for convenience:
// uses Coinbase as default provider echo to_currency('USD', 0.5); // 2000.00 echo to_currency('LTC', 0.5); // 10.12345678
You can also convert any currency (ISO 4217 fiat or crypto) to Bitcoin:
use Jimmerioles\BitcoinCurrencyConverter\Converter; $convert = new Converter; // uses Coinbase as default provider echo $convert->toBtc(100, 'USD'); // 0.12345678 echo $convert->toBtc(20, 'LTC'); // 1.12345678
and it also has its helper function for convenience:
// uses Coinbase as default provider echo to_btc(100, 'USD'); // 0.12345678 echo to_btc(20, 'LTC'); // 2.12345678
You can use different exchange rates from providers:
use Jimmerioles\BitcoinCurrencyConverter\Converter; use Jimmerioles\BitcoinCurrencyConverter\Provider\CoinbaseProvider; use Jimmerioles\BitcoinCurrencyConverter\Provider\CoindeskProvider; use Jimmerioles\BitcoinCurrencyConverter\Provider\BitpayProvider; $convert = new Converter(new CoinbaseProvider); $convert = new Converter(new CoindeskProvider); $convert = new Converter(new BitpayProvider);
or if you prefer to use the helper functions:
echo to_currency('USD', 0.5, new CoindeskProvider); // 2000.00 echo to_currency('LTC', 0.5, new BitpayProvider); // 10.12345678 echo to_btc(100, 'USD', new CoindeskProvider); // 0.12345678 echo to_btc(20, 'LTC', new BitpayProvider); // 2.12345678
You can specify cache expire time (ttl) on provider by:
new CoinbaseProvider($httpClient, $psr16CacheImplementation, 5); // cache expires in 5mins, defaults to 60mins
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ phpunit
Show full specs and features:
$ phpunit --testdox
Contributing
Open for suggestions and requests. Please request through issue or pull requests.
Security
If you discover any security related issues, please email jimwisleymerioles@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Want to show some ❤️?
| Let's find Satoshi Nakamoto! | or let's have a ☕ |
|---|---|
jimmerioles/bitcoin-currency-converter-php 适用场景与选型建议
jimmerioles/bitcoin-currency-converter-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.69k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2017 年 09 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「currency」 「converter」 「bitcoin」 「coinbase」 「cryptocurrency」 「bitpay」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jimmerioles/bitcoin-currency-converter-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jimmerioles/bitcoin-currency-converter-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jimmerioles/bitcoin-currency-converter-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tools to convert between .NET and PHP date formats
The BlockTrail PHP SDK, for integration of Bitcoin functionality through the BlockTrail API
Encode integer IDs using a preset or customized symbol set
Fixer.io data provider for Peso
TCMB Currenct Converter
Immutable PHP currency converter that's data-agnostic.
统计信息
- 总下载量: 2.69k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-09-04