dev-master
9999999-devHitBTC SDK for PHP
MIT
The Requires
by HitBTC
Wallogit.com
2017 © Pedro Peláez
HitBTC SDK for PHP
The HitBTC SDK for PHP enables PHP developers to use HitBTC rest trading API in their PHP code, and build robust applications and software., (*1)
The recommended way to install hitbtc-php-sdk is through Composer., (*2)
# Install Composer curl -sS https://getcomposer.org/installer | php
Next, update your project's composer.json file to include hitbtc-php-sdk:, (*3)
{
"require": {
"hitbtc-com/hitbtc-php-sdk": "~1.0"
}
}
Go to https://hitbtc.com/settings and create your api keys, (*4)
New order:, (*5)
$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
}
Cancel order:, (*6)
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
}
Get trading balance:, (*7)
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
Get incoming cryptocurrency address that can be used to deposit cryptocurrency to your account:, (*8)
try {
$address = $client->getPaymentAddress('BTC');
} catch (\Hitbtc\Exception\InvalidRequestException $e) {
echo $e;
} catch (\Exception $e) {
echo $e;
}
Transfers funds between main and trading accounts:, (*9)
try {
$tnxId = $client->transferToMain('BTC', 1.5);
} catch (\Hitbtc\Exception\InvalidRequestException $e) {
echo $e;
} catch (\Exception $e) {
echo $e;
}
See the https://hitbtc.com/api for more detail., (*10)
hitbtc-php-sdk is licensed under the MIT License, (*11)
HitBTC SDK for PHP
MIT