The HitBTC SDK for PHP enables PHP developers to use HitBTC rest trading API in their PHP code, and build robust applications and software.
- Get trading and main balances
- Place new order
- Cancel order
- Return list of orders and trades
- Transfers funds between main and trading accounts
- Returns the last created or create new one incoming cryptocurrency address that can be used to deposit cryptocurrency to your account.
- Withdraws money and creates an outgoing crypotocurrency transaction
- Returns a list of payment transactions
The recommended way to install hitbtc-php-sdk is through Composer.
# Install Composer
curl -sS https://getcomposer.org/installer | php
Next, update your project's composer.json file to include hitbtc-php-sdk:
{
"require": {
"hitbtc-com/hitbtc-php-sdk": "~1.0"
}
}
Go to https://hitbtc.com/settings and create your api keys
New order:
$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:
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:
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:
try {
$address = $client->getPaymentAddress('BTC');
} catch (\Hitbtc\Exception\InvalidRequestException $e) {
echo $e;
} catch (\Exception $e) {
echo $e;
}
Transfers funds between main and trading accounts:
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.
hitbtc-php-sdk is licensed under the MIT License