PHP code example of bitmartexchange / bitmart-php-sdk-api
1. Go to this page and download the library: Download bitmartexchange/bitmart-php-sdk-api 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/ */
bitmartexchange / bitmart-php-sdk-api example snippets
composer
use BitMart\Lib\CloudConfig;
use BitMart\Spot\APISpot;
=> 5,
]));
// Get a list of all cryptocurrencies on the platform
$response = $APISpot->getCurrencies()['response'];
echo json_encode($response);
// Querying aggregated tickers of a particular trading pair
$response = $APISpot->getV3Ticker("BTC_USDT")['response'];
echo json_encode($response);
use BitMart\Lib\CloudConfig;
use BitMart\Spot\APISpot;
"<your_api_key>",
'secretKey' => "<your_secret_key>",
'memo' => "<your_memo>",
]));
$response = $APISpot->postSubmitOrder(
'BTC_USDT',
'buy',
'limit',
[
'size' => '0.1',
'price' => '8800',
'client_order_id' => 'test20000000005'
]
)['response'];
echo json_encode($response);
$response = $APISpot->postSubmitOrder(
'BTC_USDT',
'buy',
'market',
[
'size' => '0.1',
'notional' => '8800',
'client_order_id' => 'test20000000006'
]
)['response'];
echo json_encode($response);
use BitMart\Websocket\Spot\WsSpotPrv;
sSpotPrv([
'accessKey' => "<your_api_key>",
'secretKey' => "<your_secret_key>",
'memo' => "<your_memo>",
'callback' => function ($data) {
echo "-------------------------" . PHP_EOL;
print_r($data);
},
]);
// Login
$ws->login();
// Subscribe Private Channels
$ws->send('{"op": "subscribe", "args": ["spot/user/balance:BALANCE_UPDATE"]}');
$ws->send('{"op": "subscribe", "args": ["spot/user/order:BTC_USDT"]}');
use BitMart\Websocket\Spot\WsSpotPub;
sSpotPub([
'callback' => function ($data) {
echo "-------------------------".PHP_EOL;
print_r($data);
},
'pong' => function ($data) {
echo "-------------------------".$data.PHP_EOL;
}
]);
// Subscribe Public Channels
$ws->send('{"op": "subscribe", "args": ["spot/ticker:BTC_USDT"]}');
$ws->send('{"op": "subscribe", "args": ["spot/kline1m:BTC_USDT"]}');
$ws->send('{"op": "subscribe", "args": ["spot/depth5:BTC_USDT"]}');
$ws->send('{"op": "subscribe", "args": ["spot/trade:BTC_USDT"]}');
use BitMart\Futures\APIContractMarket;
use BitMart\Lib\CloudConfig;
=> 5,
]));
$response = $APIContract->getContractDetails("BTCUSDT")['response'];
echo json_encode($response);
use BitMart\Futures\APIContractTrading;
use BitMart\Lib\CloudConfig;
"<your_api_key>",
'secretKey' => "<your_secret_key>",
'memo' => "<your_memo>",
]));
$response = $APIContract->submitOrder(
'BTCUSDT',
1,
[
'client_order_id' => "test3000000001",
'type' => "limit",
'leverage' => "1",
'open_type' => "isolated",
'mode' => 1,
'price' => "10",
'size' => 1,
]
)['response'];
echo json_encode($response);
use BitMart\Websocket\Futures\WsContractPrv;
r_api_key>",
'secretKey' => "<your_secret_key>",
'memo' => "<your_memo>",
'callback' => function ($data) {
echo "-------------------------".PHP_EOL;
print_r($data);
},
'pong' => function ($data) {
echo "-------------------------".$data.PHP_EOL;
}
]);
// Login
$ws->login();
// Subscribe Private Channels
$ws->send('{
"action": "subscribe",
"args":["futures/asset:USDT", "futures/asset:BTC", "futures/asset:ETH"]
}');
use BitMart\Websocket\Futures\WsContractPub;
on ($data) {
echo "-------------------------".PHP_EOL;
print_r($data);
},
'pong' => function ($data) {
echo "-------------------------".$data.PHP_EOL;
}
]);
// Subscribe Public Channels
$ws->send('{"action":"subscribe","args":["futures/ticker"]}');
$ws->send('{"action":"subscribe","args":["futures/depth20:BTCUSDT"]}');
$ws->send('{"action":"subscribe","args":["futures/trade:BTCUSDT"]}');
$ws->send('{"action":"subscribe","args":["futures/klineBin1m:BTCUSDT"]}');
$APISpot = new APISpot(new CloudConfig(
[
'accessKey' => "your_api_key",
'secretKey' => "your_secret_key",
'memo' => "your_memo",
]
));
$APISpot = new APISpot(new CloudConfig(
[
'timeoutSecond' => 5
]
));
$APISpot = new APISpot(new CloudConfig(
[
'xdebug' => true
]
));
$APISpot = new APISpot(new CloudConfig(
[
'url' => 'https://api-cloud.bitmart.com'
]
));
$APISpot = new APISpot(new CloudConfig([
'customHeaders' => array(
"Your-Custom-Header1" => "value1",
"Your-Custom-Header2" => "value2",
),
]));
$response = $APISpot->getV3Ticker("BTC_USDT");
echo $response['limit']['Remaining'];
echo $response['limit']['Limit'];
echo $response['limit']['Reset'];
echo $response['limit']['Mode'];