mitmelon / bitcoin-converter
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.
dev-main
2022-03-12 17:33 UTC
Requires
- php: >=8.0
- guzzlehttp/guzzle: ^7.4
- illuminate/cache: ^8.80
- illuminate/filesystem: ^8.80
This package is auto-updated.
Last update: 2025-03-13 16:31:53 UTC
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 Watermelon\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 Watermelon\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 Watermelon\BitcoinConverter\Converter; use Watermelon\BitcoinConverter\Provider\CoinbaseProvider; use Watermelon\BitcoinConverter\Provider\CoindeskProvider; use Watermelon\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.