2017 © Pedro Peláez
 

library buttercoin-sdk

A PHP library for connecting to the Buttercoin API

image

buttercoin/buttercoin-sdk

A PHP library for connecting to the Buttercoin API

  • Wednesday, October 22, 2014
  • by kevin-buttercoin
  • Repository
  • 1 Watchers
  • 1 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 1 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Buttercoin PHP SDK Library

Easy integration with the Buttercoin Trading Platform through our API., (*1)

Installation with Composer

$ php composer.phar require buttercoin/buttercoin-sdk:~0.0.6

Usage

For composer documentation, please refer to getcomposer.org., (*2)

This client was built using Guzzle, a PHP HTTP client & framework for building RESTful web service clients., (*3)

When you first create a new ButtercoinClient instance you can pass publicKey, privateKey, and environment as configuration settings. These are optional and can be later specified through Setter methods., (*4)

For authenticated API Resources, the publicKey and secretKey are required and can also be passed to the factory method in the configuration array. The environment configuration setting defaults to 'production'., (*5)

For a list of required and available parameters for the different API Endpoints, please consult the Buttercoin API Reference Docs., (*6)

Configuring the Client

The factory method accepts an array of configuration settings for the Buttercoin Webservice Client., (*7)

Setting Property Name Description
Public Key publicKey Your Buttercoin API Public Key
Secret Key secretKey Your Buttercoin API Secret Key
Environment environment Your development environment (default: 'production', set to 'sandbox' to test with testnet bitcoins)
API Version version The API Version. Currently used to version the API URL and Service Description
Example
require 'vendor/autoload.php';
use Buttercoin\Client\ButtercoinClient;
date_default_timezone_set('UTC'); // for $timestamp

$client = ButtercoinClient::factory([
    'publicKey' => '<public_key>',
    'secretKey' => '<secret_key>',
    'environment' => 'sandbox' // leave this blank for production
]);

Configuration can be updated to reuse the same Client:

You can reconfigure the Buttercoin Client configuration options through available getters and setters. You can get and set the following options: publicKey, secretKey, environment, & version, (*8)

Example
$client->getSecretKey();
$client->setSecretKey('<new_secret_key>');

Tips, (*9)

A note on the timestamp param sent to all client methods: This param must always be increasing, and within 5 minutes of Buttercoin server times (GMT). This is to prevent replay attacks on your data., (*10)

Before every call, get a new timestamp. (You need only set the timezone once), (*11)

date_default_timezone_set('UTC'); // Do this only once
$timestamp = round(microtime(true) * 1000);
$client->getKey($timestamp);

Additionally, for convenience, if you don't include the timestamp parameter, it will default to the current timestamp., (*12)

$client->getKey();

WARNING, (*13)

For Query and Post Params, there is a limitation from the Guzzle library that you always add the params to your array in the order they are displayed in tables below. If you don't do this, the HMAC-SHA256 signature will not be correct and you will get a 401 request error., (*14)

Get Data

Unauthenticated

Get Order Book
Return an array of current orders in the Buttercoin order book, (*15)

$client->getOrderBook();

Get Trade History
Return an array of the last 100 trades, (*16)

$client->getTradeHistory();

Get Ticker
Return the current bid, ask, and last sell prices on the Buttercoin platform, (*17)

$client->getTicker();
Authenticated

Key Permissions
Returns array of permissions associated with this key, (*18)

$client->getKey($timestamp);

Balances
Returns array of balances for this account, (*19)

$client->getBalances($timestamp);

Deposit Address
Returns bitcoin address string to deposit your funds into the Buttercoin platform, (*20)

$client->getDepositAddress($timestamp);

Get Orders
Returns array of arrays containing information about buy and sell orders, (*21)

Valid params include (must be added to array in this order):, (*22)

Name Param Description
Status status enum: ['opened', 'partial-filled', 'filled', 'canceled']
Side side enum: ['buy', 'sell']
Order Type orderType enum: ['market', 'limit']
Date Min dateMin format: ISO-8601, e.g. '2014-05-06T13:15:30Z'
Date Max dateMax format: ISO-8601, e.g. '2014-05-06T13:15:30Z'
// query for multiple orders
$orderParams = [ "status" => "canceled", "side" => "sell" ];

$client->getOrders($orderParams, $timestamp);

// single order by id
$orderId = '<order_id>';

$client->getOrderById($orderId, $timestamp);

// single order by url
$url = 'https://api.buttercoin.com/v1/orders/{order_id}';

$client->getOrderByUrl($url, $timestamp);

Get Transaction
Returns array of arrays containing information about deposit and withdraw action, (*23)

Valid params include (must be added to array in this order):, (*24)

Name Param Description
Status status enum: ['pending', 'processing', 'funded', 'canceled', 'failed']
Transaction Type transactionType enum: ['deposit', 'withdrawal']
Date Min dateMin format: ISO-8601, e.g. '2014-05-06T13:15:30Z'
Date Max dateMax format: ISO-8601, e.g. '2014-05-06T13:15:30Z'
// query for multiple transactions
$trxnParams = [ "status" => "funded", "transactionType" => "deposit" ];

$client->getTransactions($trxnParams, $timestamp);

$trxnId = '53a22ce164f23e7301a4fee5';

$client->getTransactionById($trxnId, $timestamp);

// single transaction by url
$url = 'https://api.buttercoin.com/v1/transactions/{transaction_id}';

$client->getTransactionByUrl($url, $timestamp);

Create New Actions

Create Order, (*25)

Valid order params include:, (*26)

Name Param Description
Instrument instrument enum: ['BTC_USD, USD_BTC']
Side side enum: ['buy', 'sell'], required true
Order Type orderType enum: ['limit', 'market'], required true
Price price string, required false
Quantity quantity string, required false
// create an array with the following params
$order = [
  "instrument" => "BTC_USD",
  "side" => "buy",
  "orderType" => "limit",
  "price" => "700.00"
  "quantity" => "5"
];

$client->createOrder($order, $timestamp);

Create Transaction, (*27)

Please contact Buttercoin support before creating a USD deposit using the API, (*28)

Deposit transaction params include:, (*29)

Name Param Description
Method method enum: ['wire'], required true
Currency currency enum: ['USD'], required true
Amount amount string, required true
// create deposit
$trxnObj = [
  "method" => "wire",
  "currency" => "USD",
  "amount" => "5002"
];

$client->createDeposit($trxnObj, $timestamp);

Withdrawal transaction params include:, (*30)

Name Param Description
Method method enum: ['check'], required true
Currency currency enum: ['USD'], required true
Amount amount string, required true
// create withdrawal
$trxnObj = [
  "method" => "check",
  "currency" => "USD",
  "amount" => "900.23"
];

$client->createWithdrawal($trxnObj, $timestamp);

Send bitcoin transaction params include:, (*31)

Name Param Description
Currency currency ['USD'], required true
Amount amount string, required true
Destination destination address to which to send currency string, required true
// send bitcoins to an address
$trxnObj = [
  "currency" => "BTC",
  "amount" => "100.231231",
  "destination" => "<bitcoin_address>"
];

$client->sendCrypto($trxnObj, $timestamp);

Cancel Actions

All successful cancel calls to the API return a response status of 204 with a human readable success message, (*32)

Cancel Order
Cancel a pending buy or sell order, (*33)

$client->cancelOrder($orderId, $timestamp);

Cancel Transaction
Cancel a pending deposit or withdraw action, (*34)

$client->cancelTransaction($trxnId, $timestamp);

Further Reading

Buttercoin - Website
Buttercoin API Docs, (*35)

Contributing

This is an open source project and we love involvement from the community! Hit us up with pull requests and issues., (*36)

The aim is to take your great ideas and make everyone's experience using Buttercoin even more powerful. The more contributions the better!, (*37)

Release History

0.0.6

  • added trade history endpoint

0.0.5

  • changed test env to sandbox

0.0.3

  • changed withdraw endpoint from /withdrawal to /withdraw

0.0.2

  • Made timestamp an optional field, defaults to current timestamp
  • Fixed errors in README file

0.0.1

  • First release.

License

Licensed under the MIT license., (*38)

The Versions

22/10 2014

dev-master

9999999-dev http://www.buttercoin.com

A PHP library for connecting to the Buttercoin API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Kevin Adams

bitcoin trading cryptocurrency btc buttercoin

08/10 2014

0.0.6

0.0.6.0 http://www.buttercoin.com

A PHP library for connecting to the Buttercoin API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Kevin Adams

bitcoin trading cryptocurrency btc buttercoin

31/08 2014

0.0.5

0.0.5.0 http://www.buttercoin.com

A PHP library for connecting to the Buttercoin API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Kevin Adams

bitcoin trading cryptocurrency btc buttercoin

10/08 2014

0.0.4

0.0.4.0 http://www.buttercoin.com

A PHP library for connecting to the Buttercoin API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Kevin Adams

bitcoin trading cryptocurrency btc buttercoin

10/08 2014

0.0.3

0.0.3.0 http://www.buttercoin.com

A PHP library for connecting to the Buttercoin API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Kevin Adams

bitcoin trading cryptocurrency btc buttercoin

18/07 2014

0.0.2

0.0.2.0 http://www.buttercoin.com

A PHP library for connecting to the Buttercoin API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Kevin Adams

bitcoin trading cryptocurrency btc buttercoin

16/07 2014

0.0.1

0.0.1.0 http://www.buttercoin.com

A PHP library for connecting to the Buttercoin API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Kevin Adams

bitcoin trading cryptocurrency btc buttercoin