Bitreserve is a next generation money service business that shields you from bitcoin volatility by enabling you to hold bitcoin as the money you use every day.
The Bitreserve SDK for PHP provides an easy way for developers to integrate PHP applications with the Bitreserve API.
Grab the latest version of the library:
$ git clone https://github.com/seegno/bitreserve-sdk-php.git
Install composer:
$ curl -s https://getcomposer.org/installer | php
Install the library dependencies:
$ php composer.phar install
Require the autoloader file generated by composer:
require 'vendor/autoload.php';
Require the library package as a dependency:
{
"require": {
"seegno/bitreserve-sdk-php": "2.0.*"
}
}
In order to learn more about the Bitreserve API, please check out the developer website.
First, create a Personal Access Token (PAT) using the command described below.
$ php lib/Bitreserve/console.php tokens:create
Then, create a new instance of the Client
class with token. Take a look at the following examples and explore more on the examples directory.
require_once 'vendor/autoload.php';
use Bitreserve\BitreserveClient as Client;
// Initialize the client.
$client = new Client('AUTHORIZATION_TOKEN');
// Get the current user.
$user = $client->getUser();
require_once 'vendor/autoload.php';
use Bitreserve\BitreserveClient as Client;
// Initialize the client.
$client = new Client('AUTHORIZATION_TOKEN');
// Get the current user.
$user = $client->getUser();
// Get user balances for all currencies.
$balances = $user->getBalances();
You could get user total balance:
// Get user total balance.
$balance = $user->getTotalBalance();
The above produces the output shown below:
Array
(
[amount] => 3.14
[currency] => BTC
)
require_once 'vendor/autoload.php';
use Bitreserve\BitreserveClient as Client;
// Initialize the client.
$client = new Client('AUTHORIZATION_TOKEN');
// Get the current user.
$user = $client->getUser();
// Get current user cards.
$cards = $user->getCards();
require_once 'vendor/autoload.php';
use Bitreserve\BitreserveClient as Client;
// Initialize the client.
$client = new Client('AUTHORIZATION_TOKEN');
// Get the current user.
$user = $client->getUser();
// Create a new 'BTC' card.
$card = $user->createCard('My new card', 'BTC');
The above produces the output shown below:
Bitreserve\Model\Card Object
(
[id:protected] => ade869d8-7913-4f67-bb4d-72719f0a2be0
[address:protected] => Array
(
[bitcoin] => 1GpBtJXXa1NdG94cYPGZTc3DfRY2P7EwzH
)
[addresses:protected] => Array
(
[0] => Array
(
[id] => 1GpBtJXXa1NdG94cYPGZTc3DfRY2P7EwzH
[network] => bitcoin
)
)
[available:protected] => 0.00
[balance:protected] => 0.00
[currency:protected] => BTC
[label:protected] => My new card
[lastTransactionAt:protected] =>
[transactions:protected] =>
[settings] => Array
(
[position] => 10
)
)
require_once 'vendor/autoload.php';
use Bitreserve\BitreserveClient as Client;
// Initialize the client. In this case, we don't need an
// AUTHORIZATION_TOKEN because the Ticker endpoint is public.
$client = new Client();
// Get tickers.
$tickers = $client->getTicker();
Or you could get a ticker for a specific currency:
// Get tickers for BTC.
$tickers = $client->getTickerByCurrency('BTC');
The above produces the output shown below:
Array
(
[0] => Bitreserve\Model\Ticker Object
(
[ask:protected] => 1
[bid:protected] => 1
[currency:protected] => BTC
[pair:protected] => BTCBTC
)
[1] => Bitreserve\Model\Ticker Object
(
[ask:protected] => 234.89
[bid:protected] => 234.8
[currency:protected] => USD
[pair:protected] => BTCUSD
)
)
require_once 'vendor/autoload.php';
use Bitreserve\BitreserveClient as Client;
// Initialize the client.
$client = new Client('AUTHORIZATION_TOKEN');
// Get the current user.
$user = $client->getUser();
// Get a specific card by id.
$card = $user->getCardsById('ade869d8-7913-4f67-bb4d-72719f0a2be0');
// Create a new transaction.
$transaction = $card->createTransaction('foo@bar.com', '2.0', 'BTC');
// Commit the transaction.
$transaction->commit();
The above produces the output shown below:
Bitreserve\Model\Transaction Object
(
[id:protected] => a97bb994-6e24-4a89-b653-e0a6d0bcf634
[createdAt:protected] => 2015-01-30T11:46:11.439Z
[denomination:protected] => Array
(
[pair] => BTCBTC
[rate] => 1
[amount] => 2.0
[currency] => BTC
)
[destination:protected] => <snip>
[message:protected] =>
[origin:protected] => <snip>
[params:protected] => <snip>
[refundedById:protected] =>
[status:protected] => completed
[type] => transfer
)
require_once 'vendor/autoload.php';
use \Bitreserve\BitreserveClient as Client;
// Initialize the client. In this case, we don't need an
// AUTHORIZATION_TOKEN because the Ticker endpoint is public.
$client = new Client();
// Get all public transactions.
$pager = $client->getReserve()->getTransactions();
// Get next page of transactions.
$transactions = $pager->getNext();
Or you could get a specific public transaction:
// Get one public transaction.
$transaction = $client->getReserve()->getTransactionById('a97bb994-6e24-4a89-b653-e0a6d0bcf634');
require_once 'vendor/autoload.php';
use \Bitreserve\BitreserveClient as Client;
// Initialize the client. In this case, we don't need an
// AUTHORIZATION_TOKEN because the Ticker endpoint is public.
$client = new Client();
// Get the reserve summary of all the obligations and assets within it.
$statistics = $client->getReserve()->getStatistics();
Some endpoints will return a paginator. Here is some examples on how you can handle it.
// Get public transactions.
$pager = $client->getReserve()->getTransactions();
// Check whether the paginator has a valid next page.
while($pager->hasNext()) {
// Get next page with results.
$transactions = $pager->getNext();
// Do something...
}
Found a bug or want to suggest something? Take a look first on the current and closed issues. If it is something new, please submit an issue.
It will be awesome if you can help us evolve bitreserve-sdk-php
. Want to help?
- Fork it.
php composer.phar install
.- Hack away.
- Run the tests:
phpunit
. - Create a Pull Request.