baitercel/binance-api-php

Binance API Class and examples of how to use the API.

dev-master 2017-11-03 04:03 UTC

This package is not auto-updated.

Last update: 2022-10-22 06:53:57 UTC


README

Binance API Class and examples of how to use the API.

Install

composer require baitercel/binance-api-php dev-master

Getting started

<?php
require 'BinanceClass.php';
$api = new Binance("API_Key","Secret");

Get latest price of a symbol

$ticker = $api->prices();
print_r($ticker); // List prices of all symbols
echo "Price of BNB: {$ticker['BNBBTC']} BTC.\n";

Get all of your positions, including estimated BTC value

$balances = $api->balances($ticker);
print_r($balances);
echo "BTC owned: ".$balances['BTC']['available']."\n";
echo "ETH owned: ".$balances['ETH']['available']."\n";
echo "Estimated Value: ".$api->btc_value." BTC\n";

Get all bid/ask prices

$bookPrices = $api->bookPrices();
print_r($bookPrices);

Place a LIMIT order

$quantity = 1;
$price = 0.0005;
$order = $api->buy("BNBBTC", $quantity, $price);
$quantity = 1;
$price = 0.0006;
$order = $api->sell("BNBBTC", $quantity, $price);

Place a MARKET order

$order = $api->buy("BNBBTC", $quantity, 0, "MARKET");
$order = $api->sell("BNBBTC", $quantity, 0, "MARKET");

Get Trade History

$trades = $api->trades("BNBBTC");
print_r($trades);

Get Market Depth

$depth = $api->depth("ETHBTC");
print_r($depth);

Get Open Orders

$openorders = $api->openOrders("BNBBTC");
print_r($openorders);

Get Order Status

$orderid = "7610385";
$orderstatus = $api->orderStatus("ETHBTC", $orderid);
print_r($orderstatus);

Cancel an Order

$response = $api->cancel("ETHBTC", $orderid);
print_r($response);

Get all account orders; active, canceled, or filled.

$orders = $api->orders("BNBBTC");
print_r($orders);

Get Kline/candlestick data for a symbol

//Periods: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M
$ticks = $api->candlesticks("BNBBTC", "5m");
print_r($ticks);