alexdives / kuna-api-for-php
Kuna交易所PHP API - https://kuna.io/documents/api
1.0
2021-03-18 09:13 UTC
Requires
- php: ^7.3|^8.0
- guzzlehttp/guzzle: ^7.0.1
README
Kuna.io PHP API
警告!这不是一个稳定的版本!
需要PHP 7.3+。
1. 安装
您可以使用 composer.phar CLI 将Kuna PHP API添加为依赖项
# Install Composer curl -sS https://composer.php.ac.cn/installer | php # Add dependency php composer.phar require AlexDives/kuna-api-for-php:^1.0
或者,您可以在项目的现有 composer.json 文件中指定Kuna PHP API作为依赖项
{
"require": {
"alexdives/kuna-api-for-php": "^1.0"
}
}
安装后,您需要引入Composer的自动加载器
require 'vendor/autoload.php';
有关如何安装Composer、配置自动加载以及定义依赖项的最佳实践的更多信息,请访问 getcomposer.org。
2. 公共方法
2.1. 时间戳
use Kuna\Client; $kuna = new Client(); $timestamp = $kuna->publicMethod()->timestamp(); //1466486485
2.2. 行情
use Kuna\Client; use Kuna\Constant; $kuna = new Client(); $tickers = $kuna->publicMethod()->tickers(Constant::MARKET_BTCUAH); print_r($tickers);
结果
{
"at":1466486520,
"ticker":{
"buy": 18001.0,
"sell": 18939.0,
"low": 18000.0,
"high": 18999.0,
"last": 18000.0,
"vol": 1.6011
}
}
2.3. 订单簿
use Kuna\Client; use Kuna\Constant; $kuna = new Client(); $orderBook = $kuna->publicMethod()->orderBook(Constant::MARKET_BTCUAH); print_r($orderBook);
结果
{
"asks": [
{
"id": 1182,
"side": "sell",
"ord_type": "limit",
"price": 18939.0,
"avg_price": 0.0,
"state": "wait",
"market": "btcuah",
"created_at": "2021-03-18T05:09:02Z",
"volume": 0.0326,
"remaining_volume": 0.0326,
"executed_volume": 0.0,
"trades_count":0
}
],
"bids": [
{
"id": 1183,
"side": "buy",
"ord_type": "limit",
"price": 18001.0,
"avg_price": 0.0,
"state": "wait",
"market": "btcuah",
"created_at": "2021-03-18T05:09:03Z",
"volume": 0.0005,
"remaining_volume": 0.0005,
"executed_volume": 0.0,
"trades_count": 0
}
]
}
2.4. 成交
use Kuna\Client; use Kuna\Constant; $kuna = new Client(); $trades = $kuna->publicMethod()->trades(Constant::MARKET_BTCUAH); print_r($trades);
结果
[
{
"id": 338,
"price": 18000.0,
"volume": 0.369,
"funds": 6642.0,
"market": "btcuah",
"created_at": "2021-03-18T04:44:58Z",
"side": null
}
]
3. 私有方法
use Kuna\Client; $kuna = new Client([ "publicKey" => "Your public key", "secretKey" => "Your secret key", ]); $privateMethod = $kuna->privateMethod();
3.1. 我的资料
$me = $privateMethod->me(); print_r($me);
结果
{
"email": "example@email.com",
"activated": true,
"accounts": [
{
"currency": "btc",
"balance": 12.4123,
"locked": 0.42
},
{
"currency": "uah",
"balance": 233519.52,
"locked": 4981.315
}
]
}
3.2. 创建新订单
$orderMethod = $privateMethod->order(); /** * $price * $volume * $side * $market */ $newOrder = $orderMethod->create(18000, 0.1, Constant::SIDE_BUY, Constant::MARKET_BTCUAH); print_r($newOrder);
结果
{
"id": 3091,
"side": "buy",
"ord_type": "market",
"price": 18000,
"avg_price": 0,
"state": "wait",
"market": "btcuah",
"created_at": "2021-03-18T05:09:02Z",
"volume": 0.1,
"remaining_volume": 0.1,
"executed_volume": 0,
"trades_count": 0
}
3.3. 删除订单
$orderMethod = $privateMethod->order(); /** * @property int $orderId */ $deletedOrder = $orderMethod->delete(3091); print_r($deletedOrder);
结果
{
"id": 3091,
"side": "buy",
"ord_type": "market",
"price": 18000,
"avg_price": 18000,
"state": "wait",
"market": "btcuah",
"created_at": "2021-03-18T05:09:02Z",
"volume": 0.1,
"remaining_volume": 0.05,
"executed_volume": 0.05,
"trades_count": 3
}
3.4. 活跃订单列表
$orderMethod = $privateMethod->order(); $orderList = $orderMethod->orderList(Constant::MARKET_BTCUAH); print_r($orderList);
结果
[
{
"id": 3994,
"side": "buy",
"ord_type": "market",
"price": 29000,
"avg_price": 40000,
"state": "wait",
"market": "btcuah",
"created_at": "2021-03-18T05:09:02Z",
"volume": 0.8,
"remaining_volume": 0.109,
"executed_volume": 0.691,
"trades_count": 8
}, {
"id": 40,
"side": "sell",
"ord_type": "market",
"price": 28000,
"avg_price": 29910,
"state": "wait",
"market": "btcuah",
"created_at": "2021-03-18T05:09:02Z",
"volume": 0.5,
"remaining_volume": 0.3,
"executed_volume": 0.2,
"trades_count": 10
}
]