baitercel/binance-api-php

Binance 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类及其使用示例。

安装

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

入门

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

获取一个代币的最新价格

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

获取所有持仓,包括估算的BTC价值

$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";

获取所有买价/卖价

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

下LIMIT订单

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

下MARKET订单

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

获取交易历史

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

获取市场深度

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

获取开放订单

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

获取订单状态

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

取消订单

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

获取所有账户订单;活跃、已取消或已填充。

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

获取一个代币的K线/蜡烛图数据

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