Simple Curl based wrapper for Binance API for PHP scripts
Feaures
- API support for SPOT data/trading
- FAPI/DAPI support for futures data/trading
- Curl-only implementation
- automatic auth
Installation
Just download latest version of binance.php:
wget https://raw.githubusercontent.com/mrcrypster/binance-php/main/binance.php
Usage
First of all, include library and authenticate:
require_once 'binance.php';
binance::auth($your_key, $your_secret);
Use binance::call($method)
to call any method from API documentation
Get Binance status
# include and set key/secret
require_once 'binance.php';
binance::auth($your_key, $your_secret);
$status = binance::call('/sapi/v1/system/status');
echo 'Binance API status is: ' . $status['msg'];
Get withdrawal history
$deposits = binance::call('/sapi/v1/capital/withdraw/history');
foreach ( $deposits as $deposits ) {
print_r($deposits);
}
Get deposit history
$withdrawals = binance::call('/sapi/v1/capital/deposit/hisrec');
foreach ( $withdrawals as $withdraw ) {
echo $withdraw['amount'] . $withdraw['coin'] . "\n";
}
Place an order (POST method example)
Second argument accepts parameters to pass to the API request. Passing HTTP method as a third argument allows you to make POST/PUSH/DELETE requests:
$response = binance::call('/api/v3/order', [
'symbol' => 'BNBBTC',
'side' => 'BUY',
'type' => 'LIMIT',
'timeInForce' => 'GTC',
'quantity' => 10,
'price' => 0.1
], 'POST');
print_r($response);
Get order data
$response = binance::call('/api/v3/order', [
'symbol' => 'BNBBTC',
'origClientOrderId' => 1, # user-generated ID for needed order
]);
print_r($response);
Cancel (delete) an order (DELETE method example)
$response = binance::call('/api/v3/order', [
'symbol' => 'BNBBTC',
'origClientOrderId' => 1, # user-generated ID for needed order
], 'DELETE');
print_r($response);