PHP code example of hitbtc-com / hitbtc-php-sdk

1. Go to this page and download the library: Download hitbtc-com/hitbtc-php-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/ */

    

hitbtc-com / hitbtc-php-sdk example snippets


$client = new \Hitbtc\ProtectedClient('API key', 'API secret', $demo = false);

$newOrder = new \Hitbtc\Model\NewOrder();
$newOrder->setSide($newOrder::SIDE_SELL);
$newOrder->setSymbol('BTCUSD');
$newOrder->setTimeInForce($newOrder::TIME_IN_FORCE_GTC);
$newOrder->setType($newOrder::TYPE_LIMIT);
$newOrder->setQuantity(10);
$newOrder->setPrice(800);

try {
    $order = $client->newOrder($newOrder);
    var_dump($order->getOrderId());
    var_dump($order->getStatus()); // new
} catch (\Hitbtc\Exception\RejectException $e) {
    echo $e; // if creating order will rejected
} catch (\Hitbtc\Exception\InvalidRequestException $e) {
    echo $e->getMessage(); // error in request
} catch (\Exception $e) {
    echo $e->getMessage(); // other error like network issue
}

try {
    $order = $client->cancelOrder($order);
    var_dump($order->getStatus()); // canceled
} catch (\Hitbtc\Exception\RejectException $e) {
    echo $e; // if creating order will rejected
} catch (\Hitbtc\Exception\InvalidRequestException $e) {
    echo $e->getMessage(); // error in request
} catch (\Exception $e) {
    echo $e->getMessage(); // other error like network issue
}

try {
    foreach ($client->getBalanceTrading() as $balance) {
        echo $balance->getCurrency() . ' ' . $balance->getAvailable() . ' reserved:' . $balance->getReserved() . "\n";
    }
} catch (\Hitbtc\Exception\InvalidRequestException $e) {
    echo $e;
} catch (\Exception $e) {
    echo $e;
}
//BTC 18.314848971 reserved:0.7004
//DOGE 1122543 reserved:0

try {
    $address = $client->getPaymentAddress('BTC');
} catch (\Hitbtc\Exception\InvalidRequestException $e) {
    echo $e;
} catch (\Exception $e) {
    echo $e;
}

try {
    $tnxId = $client->transferToMain('BTC', 1.5);
} catch (\Hitbtc\Exception\InvalidRequestException $e) {
    echo $e;
} catch (\Exception $e) {
    echo $e;
}
bash
# Install Composer
curl -sS https://getcomposer.org/installer | php