Skip to content

Commit

Permalink
add some endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
BigXia committed Apr 21, 2020
1 parent 70d9a5e commit a9f1ea0
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 25 deletions.
4 changes: 2 additions & 2 deletions okex-php-sdk-api/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
如何使用?

提示:请确保 php 版本在7.2以上
环境要求:请确保 php 版本在7.2以上,并安装了 composer 命令。

第一步:安装依赖
第一步:进入到项目根目录,安装依赖

1.1 安装依赖composer包

Expand Down
62 changes: 48 additions & 14 deletions okex-php-sdk-api/rapiDemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use okv3\FuturesApi;
use okv3\MarginApi;
use okv3\OptionsApi;
use okv3\OthersAPI;
use okv3\SpotApi;
use okv3\SwapApi;
use Workerman\Connection\AsyncTcpConnection;
Expand All @@ -41,8 +42,12 @@
//$res = $obj -> getWithdrawalHistory();
// 查询单个币种的提币记录
//$res = $obj -> getCoinWithdrawalHistory($coin);
// 获取所有币种的充值记录
//$res = $obj -> getDepositHistory();
// 获取账户资产估值
//$res = $obj -> getAssetValuation();
// 获取账户资产估值
//$res = $obj -> getSubAccount("liuheng");
// 获取子账户余额信息
//$res = $obj -> get();
// 查询单个币种的充值记录
//$res = $obj -> getCoinDepositHistory($coin);
// 获取币种列表
Expand Down Expand Up @@ -71,25 +76,28 @@
// 获取订单信息
//$res = $obj -> getOrderInfo($instrumentId,"3271189018971137");
// 获取成交明细
$res = $obj -> getFills($instrumentId,"3230072570268672");
//$res = $obj -> getFills($instrumentId,"3230072570268672");
// 策略委托下单-止盈止损- mode为1是币币, mode为1是币币杠杆,
//$res = $obj -> takeAlgoOrderStop($instrumentId,"1","1", "1", "buy", "1","1");
// 委托策略撤单-止盈止损
//$res = $obj -> revokeAlgoOrders($instrumentId,["401671"], "1");
// 获取委托单列表-止盈止损
//$res = $obj -> getAlgoList($instrumentId, "1", '','401671','','','');
// 获取当前账户交易手续费费率
//$res = $obj -> getTradeFee();
// 获取币对信息
//$res = $obj -> getCoinInfo();
// 获取深度数据
//$res = $obj -> getDepth($instrumentId,1);
// 获取全部ticker信息
//$res = $obj -> getTicker();
// 获取某个ticker信息
//$res = $obj -> getSpecificTicker($instrumentId);
$res = $obj -> getSpecificTicker($instrumentId);
// 获取成交数据
//$res = $obj -> getDeal($instrumentId);
// 获取K线
//$res = $obj -> getKine($instrumentId,3600);
// 策略委托下单-止盈止损- mode为1是币币, mode为1是币币杠杆,
//$res = $obj -> takeAlgoOrderStop($instrumentId,"1","1", "1", "buy", "1","1");
// 委托策略撤单-止盈止损
//$res = $obj -> revokeAlgoOrders($instrumentId,["401671"], "1");
// 获取委托单列表-止盈止损
//$res = $obj -> getAlgoList($instrumentId, "1", '','401671','','','');


// 币币杠杆账户信息
$instrumentId = "EOS-USDT";
Expand Down Expand Up @@ -122,10 +130,15 @@
//$res = $obj -> getOrderInfo($instrumentId,"3292706588398592");
// 获取成交明细
//$res = $obj -> getFills($instrumentId,"3292706588398592");

// 获取杠杆倍数
//$res = $obj -> getLeverage($instrumentId);
// 获取杠杆倍数
//$res = $obj -> setLeverage($instrumentId, "10");
// 公共-获取标记价格
//$res = $obj -> getMarkPrice($instrumentId);

// 交割合约-Ticker
$instrumentId = "EOS-USD-191227";
$instrumentId = "EOS-USD-200626";
$coin = "EOS";
$obj = new FuturesApi(Config::$config);
// 合约持仓信息
Expand Down Expand Up @@ -188,10 +201,16 @@
// 获取委托单列表-止盈止损
//$res = $obj -> getAlgoList($instrumentId, "1", '',"3121188",'','','');

// 设置合约币种账户模式
//$res = $obj -> setMarginMode($coin, "crossed");
//市价全平
//$res = $obj -> closePosition($instrumentId, "long");
//撤销所有平仓挂单
//$res = $obj -> cancelAll($instrumentId, "long");

// 获取账户手续费费率
//$res = $obj -> getTradeFee();


// 永续合约
$instrumentId = "EOS-USD-SWAP";
Expand Down Expand Up @@ -260,8 +279,16 @@
//$res = $obj -> revokeAlgoOrders($instrumentId,["375065465116119040"], "1");
// 获取委托单列表-止盈止损
//$res = $obj -> getAlgoList($instrumentId, "1", '',"375065465116119040",'','','');

// 获取账户手续费费率
//$res = $obj -> getTradeFee();

//市价全平
//$res = $obj -> closePosition($instrumentId, "long");
//撤销所有平仓挂单
//$res = $obj -> cancelAll($instrumentId, "long");
// 指数
//$res = $obj->getHistoricalFundingRate($instrumentId);

// 期权
$instrumentId = "TBTC-USD-191213-7500-C";
Expand Down Expand Up @@ -306,7 +333,14 @@
// 公共-获取K线数据
//$res = $obj->getKline($instrumentId,"60");

// 指数
//$res = $obj->getHistoricalFundingRate($instrumentId);
// 其他接口
$instrumentId = "BTC-USD";
$obj = new OthersAPI(Config::$config);
//获取服务时间
//$res = $obj->getServerTime();
//公共-获取指数成分
//$res = $obj->getConstituents($instrumentId);

//$res = $obj->getStatus("0");

print_r($res);
24 changes: 24 additions & 0 deletions okex-php-sdk-api/src/AccountApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class AccountApi extends Utils
const ACCOUNT_CURRENCIES = '/api/account/v3/currencies/';
const ACCOUNT_WITHDRAWAL_FEE = '/api/account/v3/withdrawal/fee/';

const ACCOUNT_ASSET_VALUATION = '/api/account/v3/asset-valuation/';
const ACCOUNT_SUB_ACCOUNT = '/api/account/v3/sub-account/';



// 资金账户信息,多个币种
public function getWalletInfo()
{
Expand Down Expand Up @@ -134,4 +139,23 @@ public function getWithdrawalFee($currency='')
if ($currency) $params['currency'] = $currency;
return $this->request(self::ACCOUNT_WITHDRAWAL_FEE, $params, 'GET', true);
}

//
public function getAssetValuation($account_type='', $valuation_currency='')
{
$params = [];
if ($account_type) $params['account_type'] = $account_type;
if ($valuation_currency) $params['valuation_currency'] = $valuation_currency;
return $this->request(self::ACCOUNT_ASSET_VALUATION, $params, 'GET', true);
}

//
public function getSubAccount($sub_account)
{
$params = [];
if ($sub_account) $params['sub-account'] = $sub_account;
return $this->request(self::ACCOUNT_SUB_ACCOUNT, $params, 'GET', true);
}


}
10 changes: 10 additions & 0 deletions okex-php-sdk-api/src/FuturesApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class FuturesApi extends Utils {
const FUTURE_CLOSE_POSITION = '/api/futures/v3/close_position';
const FUTURE_CANCEL_ALL = '/api/futures/v3/cancel_all';

const FUTURE_TRADE_FEE = '/api/futures/v3/trade_fee';



// 获取合约账户所有的持仓信息
public function getPosition()
{
Expand Down Expand Up @@ -361,4 +365,10 @@ public function cancelAll($instrument_id,$direction)

return $this->request(self::FUTURE_CANCEL_ALL, $params, 'POST');
}

//
public function getTradeFee()
{
return $this->request(self::FUTURE_TRADE_FEE, '', 'GET', true);
}
}
34 changes: 34 additions & 0 deletions okex-php-sdk-api/src/MarginApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class MarginApi extends Utils {
const MARGIN_ORDER_INFO = '/api/margin/v3/orders/';
const MARGIN_FILLS = '/api/margin/v3/fills';

const MARGIN_LEVERAGE = '/api/margin/v3/accounts/';
// const MARGIN_SET_LEVERAGE = '/api/margin/v3/accounts/';
const MARGIN_MARK_PRICE = '/api/margin/v3/instruments/';



// 币币账户信息
public function getAccountInfo()
{
Expand Down Expand Up @@ -175,4 +181,32 @@ public function getFills($instrument_id, $order_id, $afters='', $before='', $lim

return $this->request(self::MARGIN_FILLS, $params, 'GET', true);
}

//
public function getLeverage($instrument_id)
{
return $this->request(self::MARGIN_LEVERAGE.$instrument_id.'/leverage', '', 'GET');
}

//
public function setLeverage($instrument_id,$leverage)
{
$params = [
'leverage' => $leverage,
];

return $this->request(self::MARGIN_LEVERAGE.$instrument_id.'/leverage', $params, 'POST');
}

//
public function getMarkPrice($instrument_id)
{
$params = [
'instrument_id' => $instrument_id,
];

return $this->request(self::MARGIN_MARK_PRICE.$instrument_id.'/mark_price', $params, 'GET', true);
}


}
40 changes: 40 additions & 0 deletions okex-php-sdk-api/src/OthersAPI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Created by PhpStorm.
* User: hengliu
* Date: 2020/4/21
* Time: 11:20 PM
*/

namespace okv3;

class OthersAPI extends Utils
{

#
const SERVER_TIME = '/api/general/v3/time';
const CONSTITUENTS = '/api/index/v3/';
const STATUS = '/api/system/v3/status';

//
public function getServerTime()
{
return $this->request(self::SERVER_TIME,'','GET');
}

//
public function getConstituents($instrument_id)
{
return $this->request(self::CONSTITUENTS . $instrument_id . '/constituents',[],'GET');
}

//
public function getStatus($status)
{
$params = [];

if ("status") $params['status'] = $status;

return $this->request(self::STATUS,$params,'GET');
}
}
9 changes: 9 additions & 0 deletions okex-php-sdk-api/src/SpotApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class SpotApi extends Utils {
const SPOT_CANCEL_BATCH_ALGOS = '/api/spot/v3/cancel_batch_algos/';
const SPOT_ALGO_LIST = '/api/spot/v3/algo';


const SPOT_TRADE_FEE = '/api/spot/v3/trade_fee/';

// 币币账户信息
public function getAccountInfo()
{
Expand Down Expand Up @@ -236,4 +239,10 @@ public function getAlgoList($instrument_id, $order_type, $status='', $algo_id=''

return $this->request(self::SPOT_ALGO_LIST, $params, 'GET', true);
}

//
public function getTradeFee()
{
return $this->request(self::SPOT_TRADE_FEE, '', 'GET', true);
}
}
27 changes: 25 additions & 2 deletions okex-php-sdk-api/src/SwapApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class SwapApi extends Utils {
const SWAP_ALGO_LIST = '/api/swap/v3/order_algo';
const SWAP_TRADE_FEE = '/api/swap/v3/trade_fee';

const SWAP_CLOSE_POSITION = '/api/swap/v3/close_position';
const SWAP_CANCEL_ALL = '/api/swap/v3/cancel_all';


// 获取合约账户所有的持仓信息
public function getPosition()
Expand Down Expand Up @@ -292,7 +295,7 @@ public function getMarkPrice($instrument_id)
return $this->request(self::SWAP_MARK_PRICE.$instrument_id.'/mark_price', [], 'GET');
}

// 公共-获取合约标记价格
//
public function getHistoricalFundingRate($instrument_id)
{
return $this->request(self::SWAP_HISTORICAL_FUNDING_RATE.$instrument_id.'/historical_funding_rate', [], 'GET');
Expand Down Expand Up @@ -341,11 +344,31 @@ public function getAlgoList($instrument_id, $order_type, $status='', $algo_id, $
return $this->request(self::SWAP_ALGO_LIST."/$instrument_id", $params, 'GET', true);
}

// 获取委托单列表
//
public function getTradeFee()
{
return $this->request(self::SWAP_TRADE_FEE, '', 'GET', true);
}

// 市价全平
public function closePosition($instrument_id,$direction)
{
$params = [
'instrument_id'=> $instrument_id,
'direction' => $direction,
];

return $this->request(self::SWAP_CLOSE_POSITION, $params, 'POST');
}

// 撤销所有平仓挂单
public function cancelAll($instrument_id,$direction)
{
$params = [
'instrument_id'=> $instrument_id,
'direction' => $direction,
];

return $this->request(self::SWAP_CANCEL_ALL, $params, 'POST');
}
}
2 changes: 2 additions & 0 deletions okex-php-sdk-api/src/Websocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function subscribe($callback, $sub_str="swap/ticker:BTC-USD-SWAP") {
print_r($ntime." $data\n");
// print_r($ntime." $i $data\n");
$con->send($data);
// $con->send($data);

};

Expand Down Expand Up @@ -134,6 +135,7 @@ function subscribe($callback, $sub_str="swap/ticker:BTC-USD-SWAP") {
print_r($ntime . " $data\n");

$con->send($data);
// $con->send($data);
}
};

Expand Down
Loading

0 comments on commit a9f1ea0

Please sign in to comment.