PHP code example of buttercoin / buttercoin-sdk

1. Go to this page and download the library: Download buttercoin/buttercoin-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

buttercoin / buttercoin-sdk example snippets



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
]);

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

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

$client->getKey();

$client->getOrderBook();

$client->getTradeHistory();

$client->getTicker();

$client->getKey($timestamp);

$client->getBalances($timestamp);

$client->getDepositAddress($timestamp);

// 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);

// 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 an array with the following params
$order = [
  "instrument" => "BTC_USD",
  "side" => "buy",
  "orderType" => "limit",
  "price" => "700.00"
  "quantity" => "5"
];

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

// create deposit
$trxnObj = [
  "method" => "wire",
  "currency" => "USD",
  "amount" => "5002"
];

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

// create withdrawal
$trxnObj = [
  "method" => "check",
  "currency" => "USD",
  "amount" => "900.23"
];

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

// send bitcoins to an address
$trxnObj = [
  "currency" => "BTC",
  "amount" => "100.231231",
  "destination" => "<bitcoin_address>"
];

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

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

$client->cancelTransaction($trxnId, $timestamp);
sh
$ php composer.phar