Code Monkey home page Code Monkey logo

bitcoin-currency-converter-php's Introduction

Bitcoin Currency Converter

Latest Version on Packagist Software License Build Status Test Coverage Maintainability Total Downloads

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)

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 [email protected] 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 ☕
Donate Bitcoin Donate Ethereum

bitcoin-currency-converter-php's People

Contributors

jimmerioles avatar codejigsaw avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.