oasin / bitcoin-converter
Convert Bitcoin to Fiat currency
dev-main
2024-03-18 12:19 UTC
Requires
- illuminate/cache: ^10
- illuminate/support: ^10
This package is auto-updated.
Last update: 2024-11-18 13:46:38 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 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.