PHP code example of iamirnet / xtcom

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

    

iamirnet / xtcom example snippets



// config by specifying api key and secret
$api = new \iAmirNet\XT\Client("<api key>","<secret>");

//Call this before running any functions
print_r($api->marketConfig(/* optional */"btc_usdt"));

//Call this before running any functions
print_r($api->kline("btc_usdt",/* Kline type is optional */ "1min",/* Since is optional */  0));

//Call this before running any functions
print_r($api->bookTicker("btc_usdt"));

//Call this before running any functions
print_r($api->bookPrices());

//Call this before running any functions
print_r($api->depth("btc_usdt"));

//Call this before running any functions
print_r($api->trades("btc_usdt"));

//Call this before running any functions
print_r($api->getServerTime());

//Call this before running any functions
print_r($api->balances());

//Call this before running any functions
print_r($api->account());

//Call this before running any functions
$accountId = 2;
print_r($api->specificAccount($accountId));

//Call this before running any functions
$quantity = 1;
$price = 0.0005;
print_r($api->buy("btc_usdt", $quantity, $price, "LIMIT"));

//Call this before running any functions
$quantity = 1;
$price = 0.0006;
print_r($api->sell("btc_usdt", $quantity, $price, "LIMIT"));

//Call this before running any functions
$data = [
    [
        "price" => 10000.123,
        "amount" => 0.1,
        "type" => 1    // 1, buy, 0 sell
    ],
    [
        "price" => 10000.123,
        "amount" => 0.1,
        "type" => 0    // 1, buy, 0 sell
    ],
];
print_r($api->bulkOrders("btc_usdt", $data));

//Call this before running any functions
$orderId = 156387346384491;
print_r($api->cancel("btc_usdt", $orderId));

//Call this before running any functions
$data = [];
$data[] = 157154392122493;
$data[] = 157154392122494;
$data[] = 157154392122495;
$data[] = 157154392122496;
$data[] = 157154392122497;
print_r($api->bulkOrdersCancel("btc_usdt", $data));

//Call this before running any functions
$orderId = 156387346384491;
print_r($api->orderInfo("btc_usdt", $orderId));

$openorders = $api->openOrders("btc_usdt",/* page is optional */ 1,/* pageSize is optional */  10);
print_r($openorders);

//Call this before running any functions
$data = [];
$data[] = 157154392122493;
$data[] = 157154392122494;
$data[] = 157154392122495;
$data[] = 157154392122496;
$data[] = 157154392122497;
print_r($api->bulkOrdersInfo("btc_usdt", $data));

$mytrades = $api->myTrades("btc_usdt",
        /* limit is optional */ 200,
        /* Start Time is optional */  1626428273000,
        /* End Time is optional */  1626428873020,
        /* From ID is optional */  6821734611983271937);
print_r($mytrades);

sudo apt-get install curl php-curl
curl -s http://getcomposer.org/installer | php
php composer.phar install

php composer.phar