PHP code example of farzai / bitkub

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

    

farzai / bitkub example snippets


$bitkub = \Farzai\Bitkub\ClientBuilder::create()
    ->setCredentials('YOUR_API_KEY', 'YOUR_SECRET_KEY')
    ->build();

// Basic usage
$market = $bitkub->market(); // Just call the market endpoint

// Get balances
$response = $market->balances();

// (Optional) You may call the `throw()` method to ensure that the response is successful
$response->throw();

// Get response data
$myBTC = $response->json('result.BTC.available');

echo "My BTC balance: {$myBTC}";


$websocket = new \Farzai\Bitkub\WebSocket\Endpoints\MarketEndpoint(
    new \Farzai\Bitkub\WebSocketClient(
        \Farzai\Bitkub\ClientBuilder::create()
            ->setCredentials('YOUR_API_KEY', 'YOUR_SECRET_KEY')
            ->build(),
    ),
);

$websocket->listen('trade.thb_ada', function (\Farzai\Bitkub\WebSocket\Message $message) {
    // Do something
    echo $message->sym.PHP_EOL;
});

// Or you can use multiple symbols like this
$websocket->listen(['trade.thb_ada', 'trade.thb_btc', function (\Farzai\Bitkub\WebSocket\Message $message) {
    // Do something
    echo $message->sym.PHP_EOL;
});

$websocket->run();

$market = $bitkub->market();

# Next, We will use this instance for the following examples below.
# ...

$market->symbols();

$market->ticker(
    // string: The symbol.
    'THB_BTC'
);

$market->trades([
    // string: The symbol.
    'sym' => 'THB_BTC',

    // integer: Limit the number of results.
    'lmt' => 10,
]);

$market->bids([
    // string: The symbol.
    'sym' => 'THB_BTC',

    // integer: Limit the number of results.
    'lmt' => 10,
]);

$market->asks([
    // string: The symbol.
    'sym' => 'THB_BTC',

    // integer: Limit the number of results.
    'lmt' => 10,
]);

$market->books([
    // string: The symbol.
    'sym' => 'THB_BTC',

    // integer: Limit the number of results.
    'lmt' => 10,
]);

$market->wallet();

$market->placeBid([
    // string: The symbol.
    'sym' => 'THB_BTC',

    // float: Amount you want to spend with no trailing zero (e.g. 1000.00 is invalid, 1000 is ok)
    'amt' => 1000,

    // float: Rate you want for the order with no trailing zero (e.g. 1000.00 is invalid, 1000 is ok)
    'rat' => 1000000,

    // string: Order type: limit or market (for market order, please specify rat as 0)
    'typ' => 'limit',

    // string: (Optional) your id for reference
    'client_id' => 'your_id',
]);

$market->placeAsk([
    // string: The symbol.
    'sym' => 'THB_BTC',

    // float: Amount you want to spend with no trailing zero (e.g. 1000.00 is invalid, 1000 is ok)
    'amt' => 1000,

    // float: Rate you want for the order with no trailing zero (e.g. 1000.00 is invalid, 1000 is ok)
    'rat' => 1000000,

    // string: Order type: limit or market (for market order, please specify rat as 0)
    'typ' => 'limit',

    // string: (Optional) your id for reference
    'client_id' => 'your_id',
]);

$market->cancelOrder([
    // string: The symbol.
    'sym' => 'THB_BTC',

    // integer: The order ID.
    'id' => 123456,

    // string: The side of the order.
    'sd' => 'buy',

    // string: The hash of the order.
    'hash' => 'your_hash',
]);

$market->balances();

$market->openOrders(
    // string: The symbol.
    'THB_BTC'
);

$market->myOrderHistory([
    // string: The symbol.
    'sym' => 'THB_BTC',

    // integer: The page number.
    'p' => 1,

    // integer: Limit the number of results.
    'lmt' => 10,

    // integer: The start timestamp.
    'start' => 1614556800,

    // integer: The end timestamp.
    'end' => 1614643199,
]);

$market->myOrderInfo([
    // string: The symbol.
    'sym' => 'THB_BTC',

    // integer: The order ID.
    'id' => 123456,

    // string: The side of the order.
    'sd' => 'buy',

    // string: The hash of the order.
    'hash' => 'your_hash',
]);

$crypto = $bitkub->crypto();

# Next, We will use this instance for the following examples below.
# ...

$crypto->addresses([
    // integer: The page number.
    'p' => 1,

    // integer: Limit the number of results.
    'lmt' => 10,
]);

$crypto->withdrawal([
    // string: Currency for withdrawal (e.g. BTC, ETH)
    'cur' => 'BTC',
    
    // float: Amount you want to withdraw
    'amt' => 0.001,

    // string: Address to which you want to withdraw
    'adr' => 'your_address',

    // string: (Optional) Memo or destination tag to which you want to withdraw
    'mem' => 'your_memo',

    // string: Cryptocurrency network to withdraw
    'net' => 'BTC',
]);

$crypto->internalWithdrawal([
    // string: Currency for withdrawal (e.g. BTC, ETH)
    'cur' => 'BTC',

    // float: Amount you want to withdraw
    'amt' => 0.001,

    // string: Address to which you want to withdraw
    'adr' => 'your_address',

    // string: (Optional) Memo or destination tag to which you want to withdraw
    'mem' => 'your_memo',
]);

$crypto->depositHistory([
    // integer: The page number.
    'p' => 1,

    // integer: Limit the number of results.
    'lmt' => 10,
]);

$crypto->withdrawalHistory([
    // integer: The page number.
    'p' => 1,

    // integer: Limit the number of results.
    'lmt' => 10,
]);

$crypto->generateAddress(
    // string Symbol (e.g. THB_BTC, THB_ETH, etc.)
    'THB_BTC'
);

$system = $bitkub->system();

# Next, We will use this instance for the following examples below.
# ...

$system->status();

$system->serverTimestamp();

$user = $bitkub->user();

# Next, We will use this instance for the following examples below.
# ...

$user->tradingCredits();

$user->limits();