From 5b1abb5b3556a7d542339f8cc89a32f647210635 Mon Sep 17 00:00:00 2001 From: lzsen Date: Tue, 1 Aug 2023 19:06:53 +0800 Subject: [PATCH] Modify interface version control --- src/Api/Delivery/Market.php | 221 ++++++++++++---------- src/Api/Delivery/Trade.php | 124 ++++++------ src/Api/Delivery/User.php | 142 +++++++------- src/Api/Futures/Market.php | 221 ++++++++++++---------- src/Api/Futures/Trade.php | 115 +++++++----- src/Api/Futures/User.php | 180 ++++++++++-------- src/Api/Spot/System.php | 176 +++++++++-------- src/Api/Spot/Trade.php | 169 +++++++++-------- src/Api/Spot/User.php | 363 +++++++++++++++++++----------------- src/Api/Version.php | 13 ++ 10 files changed, 950 insertions(+), 774 deletions(-) create mode 100644 src/Api/Version.php diff --git a/src/Api/Delivery/Market.php b/src/Api/Delivery/Market.php index 188d16d..f493130 100644 --- a/src/Api/Delivery/Market.php +++ b/src/Api/Delivery/Market.php @@ -5,253 +5,278 @@ namespace Lin\Binance\Api\Delivery; +use Lin\Binance\Api\Version; use Lin\Binance\Request; class Market extends Request { //Default Dont required HMAC SHA256 - protected $signature=false; + protected $signature = false; //Default seting - protected $version='v1'; +// protected $version = 'v1'; /** *GET /dapi/v1/ping * */ - public function getPing(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/ping'; - $this->data=$data; + public function getPing(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/ping'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/time * */ - public function getTime(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/time'; - $this->data=$data; + public function getTime(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/time'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/exchangeInfo * */ - public function getExchangeInfo(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/exchangeInfo'; - $this->data=$data; + public function getExchangeInfo(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/exchangeInfo'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/depth * */ - public function getDepth(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/depth'; - $this->data=$data; + public function getDepth(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/depth'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/trades * */ - public function getTrades(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/trades'; - $this->data=$data; + public function getTrades(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/trades'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/historicalTrades * */ - public function getHistoricalTrades(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/historicalTrades'; - $this->data=$data; + public function getHistoricalTrades(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/historicalTrades'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/aggTrades * */ - public function getAggTrades(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/aggTrades'; - $this->data=$data; + public function getAggTrades(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/aggTrades'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/premiumIndex * */ - public function getPremiumIndex(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/premiumIndex'; - $this->data=$data; + public function getPremiumIndex(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/premiumIndex'; + $this->data = $data; return $this->exec(); } /** * GET /dapi/v1/fundingRate * */ - public function getFundingRate(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/fundingRate'; - $this->data=$data; + public function getFundingRate(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/fundingRate'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/klines * */ - public function getKlines(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/klines'; - $this->data=$data; + public function getKlines(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/klines'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/continuousKlines * */ - public function getContinuousKlines(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/continuousKlines'; - $this->data=$data; + public function getContinuousKlines(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/continuousKlines'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/indexPriceKlines * */ - public function getIndexPriceKlines(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/indexPriceKlines'; - $this->data=$data; + public function getIndexPriceKlines(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/indexPriceKlines'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/markPriceKlines * */ - public function getMarkPriceKlines(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/markPriceKlines'; - $this->data=$data; + public function getMarkPriceKlines(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/markPriceKlines'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/ticker/24hr * */ - public function get24hr(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/ticker/24hr'; - $this->data=$data; + public function get24hr(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/ticker/24hr'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/ticker/price * */ - public function getTickerPrice(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/ticker/price'; - $this->data=$data; + public function getTickerPrice(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/ticker/price'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/ticker/bookTicker * */ - public function getTickerBookTicker(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/ticker/bookTicker'; - $this->data=$data; + public function getTickerBookTicker(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/ticker/bookTicker'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/allForceOrders * */ - public function getAllForceOrders(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/allForceOrders'; - $this->data=$data; + public function getAllForceOrders(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/allForceOrders'; + $this->data = $data; return $this->exec(); } /** *GET /dapi/v1/openInterest * */ - public function getOpenInterest(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/openInterest'; - $this->data=$data; + public function getOpenInterest(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/openInterest'; + $this->data = $data; return $this->exec(); } /** *GET /futures/data/openInterestHist * */ - public function getOpenInterestHist(array $data=[]){ - $this->type='GET'; - $this->path='/futures/data/openInterestHist'; - $this->data=$data; + public function getOpenInterestHist(array $data = []) + { + $this->type = 'GET'; + $this->path = '/futures/data/openInterestHist'; + $this->data = $data; return $this->exec(); } /** *GET /futures/data/topLongShortAccountRatio * */ - public function getTopLongShortAccountRatio(array $data=[]){ - $this->type='GET'; - $this->path='/futures/data/topLongShortAccountRatio'; - $this->data=$data; + public function getTopLongShortAccountRatio(array $data = []) + { + $this->type = 'GET'; + $this->path = '/futures/data/topLongShortAccountRatio'; + $this->data = $data; return $this->exec(); } /** *GET /futures/data/topLongShortPositionRatio * */ - public function getTopLongShortPositionRatio(array $data=[]){ - $this->type='GET'; - $this->path='/futures/data/topLongShortPositionRatio'; - $this->data=$data; + public function getTopLongShortPositionRatio(array $data = []) + { + $this->type = 'GET'; + $this->path = '/futures/data/topLongShortPositionRatio'; + $this->data = $data; return $this->exec(); } /** *GET /futures/data/globalLongShortAccountRatio * */ - public function getGlobalLongShortAccountRatio(array $data=[]){ - $this->type='GET'; - $this->path='/futures/data/globalLongShortAccountRatio'; - $this->data=$data; + public function getGlobalLongShortAccountRatio(array $data = []) + { + $this->type = 'GET'; + $this->path = '/futures/data/globalLongShortAccountRatio'; + $this->data = $data; return $this->exec(); } /** *GET /futures/data/takerBuySellVol * */ - public function getTakerBuySellVol(array $data=[]){ - $this->type='GET'; - $this->path='/futures/data/takerBuySellVol'; - $this->data=$data; + public function getTakerBuySellVol(array $data = []) + { + $this->type = 'GET'; + $this->path = '/futures/data/takerBuySellVol'; + $this->data = $data; return $this->exec(); } /** *GET /futures/data/basis * */ - public function getBasis(array $data=[]){ - $this->type='GET'; - $this->path='/futures/data/basis'; - $this->data=$data; + public function getBasis(array $data = []) + { + $this->type = 'GET'; + $this->path = '/futures/data/basis'; + $this->data = $data; return $this->exec(); } } diff --git a/src/Api/Delivery/Trade.php b/src/Api/Delivery/Trade.php index 950925d..bf04660 100644 --- a/src/Api/Delivery/Trade.php +++ b/src/Api/Delivery/Trade.php @@ -5,150 +5,164 @@ namespace Lin\Binance\Api\Delivery; +use Lin\Binance\Api\Version; use Lin\Binance\Request; class Trade extends Request { //Default required HMAC SHA256 - protected $signature=true; + protected $signature = true; //Default seting - protected $version='v1'; +// protected $version = 'v1'; function __construct(array $data) { parent::__construct($data); - $this->data['timestamp']=time().'000'; + $this->data['timestamp'] = time() . '000'; } /* *GET /dapi/v1/positionSide/dual (HMAC SHA256) */ - public function getPositionSideDual(array $data=[]){ - $this->type='get'; - $this->path='/dapi/'.$this->version.'/positionSide/dual'; - $this->data=array_merge($this->data,$data); + public function getPositionSideDual(array $data = [], string $version = Version::V1) + { + $this->type = 'get'; + $this->path = '/dapi/' . $version . '/positionSide/dual'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *POST /dapi/v1/order (HMAC SHA256) */ - public function postOrder(array $data=[]){ - $this->type='POST'; - $this->path='/dapi/'.$this->version.'/order'; - $this->data=array_merge($this->data,$data); + public function postOrder(array $data = [], string $version = Version::V1) + { + $this->type = 'POST'; + $this->path = '/dapi/' . $version . '/order'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *POST /dapi/v1/order/test (HMAC SHA256) */ - public function postOrderTest(array $data=[]){ - $this->type='POST'; - $this->path='/dapi/'.$this->version.'/order/test'; - $this->data=array_merge($this->data,$data); + public function postOrderTest(array $data = [], string $version = Version::V1) + { + $this->type = 'POST'; + $this->path = '/dapi/' . $version . '/order/test'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *POST /dapi/v1/batchOrders (HMAC SHA256) */ - public function postBatchOrders(array $data=[]){ - $this->type='POST'; - $this->path='/dapi/'.$this->version.'/batchOrders'; - $this->data=array_merge($this->data,$data); + public function postBatchOrders(array $data = [], string $version = Version::V1) + { + $this->type = 'POST'; + $this->path = '/dapi/' . $version . '/batchOrders'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *DELETE /dapi/v1/order (HMAC SHA256) */ - public function deleteOrder(array $data=[]){ - $this->type='DELETE'; - $this->path='/dapi/'.$this->version.'/order'; - $this->data=array_merge($this->data,$data); + public function deleteOrder(array $data = [], string $version = Version::V1) + { + $this->type = 'DELETE'; + $this->path = '/dapi/' . $version . '/order'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *DELETE /dapi/v1/allOpenOrders (HMAC SHA256) */ - public function deleteAllOpenOrders(array $data=[]){ - $this->type='DELETE'; - $this->path='/dapi/'.$this->version.'/allOpenOrders'; - $this->data=array_merge($this->data,$data); + public function deleteAllOpenOrders(array $data = [], string $version = Version::V1) + { + $this->type = 'DELETE'; + $this->path = '/dapi/' . $version . '/allOpenOrders'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *DELETE /dapi/v1/batchOrders (HMAC SHA256) */ - public function deleteBatchOrders(array $data=[]){ - $this->type='DELETE'; - $this->path='/dapi/'.$this->version.'/batchOrders'; - $this->data=array_merge($this->data,$data); + public function deleteBatchOrders(array $data = [], string $version = Version::V1) + { + $this->type = 'DELETE'; + $this->path = '/dapi/' . $version . '/batchOrders'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *POST /dapi/v1/countdownCancelAll (HMAC SHA256) */ - public function postCountdownCancelAll(array $data=[]){ - $this->type='POST'; - $this->path='/dapi/'.$this->version.'/countdownCancelAll'; - $this->data=array_merge($this->data,$data); + public function postCountdownCancelAll(array $data = [], string $version = Version::V1) + { + $this->type = 'POST'; + $this->path = '/dapi/' . $version . '/countdownCancelAll'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *POST /dapi/v1/leverage (HMAC SHA256) */ - public function postLeverage(array $data=[]){ - $this->type='get'; - $this->path='/dapi/'.$this->version.'/leverage'; - $this->data=array_merge($this->data,$data); + public function postLeverage(array $data = [], string $version = Version::V1) + { + $this->type = 'get'; + $this->path = '/dapi/' . $version . '/leverage'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *POST /dapi/v1/marginType (HMAC SHA256) */ - public function getMarginType(array $data=[]){ - $this->type='POST'; - $this->path='/dapi/'.$this->version.'/marginType'; - $this->data=array_merge($this->data,$data); + public function getMarginType(array $data = [], string $version = Version::V1) + { + $this->type = 'POST'; + $this->path = '/dapi/' . $version . '/marginType'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *POST /dapi/v1/positionMargin (HMAC SHA256) */ - public function postPositionMargin(array $data=[]){ - $this->type='POST'; - $this->path='/dapi/'.$this->version.'/positionMargin'; - $this->data=array_merge($this->data,$data); + public function postPositionMargin(array $data = [], string $version = Version::V1) + { + $this->type = 'POST'; + $this->path = '/dapi/' . $version . '/positionMargin'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *GET /dapi/v1/positionMargin/history (HMAC SHA256) */ - public function getPositionMarginHistory(array $data=[]){ - $this->type='get'; - $this->path='/dapi/'.$this->version.'/positionMargin/history'; - $this->data=array_merge($this->data,$data); + public function getPositionMarginHistory(array $data = [], string $version = Version::V1) + { + $this->type = 'get'; + $this->path = '/dapi/' . $version . '/positionMargin/history'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *GET /dapi/v1/positionRisk (HMAC SHA256) */ - public function getPositionRisk(array $data=[]){ - $this->type='get'; - $this->path='/dapi/'.$this->version.'/positionRisk'; - $this->data=array_merge($this->data,$data); + public function getPositionRisk(array $data = [], string $version = Version::V1) + { + $this->type = 'get'; + $this->path = '/dapi/' . $version . '/positionRisk'; + $this->data = array_merge($this->data, $data); return $this->exec(); } } diff --git a/src/Api/Delivery/User.php b/src/Api/Delivery/User.php index eb37a94..1580fcf 100644 --- a/src/Api/Delivery/User.php +++ b/src/Api/Delivery/User.php @@ -5,140 +5,153 @@ namespace Lin\Binance\Api\Delivery; +use Lin\Binance\Api\Version; use Lin\Binance\Request; class User extends Request { //Default required HMAC SHA256 - protected $signature=true; + protected $signature = true; //Default setting - protected $version='v1'; +// protected $version = 'v1'; function __construct(array $data) { parent::__construct($data); - $this->data['timestamp']=time().'000'; + $this->data['timestamp'] = time() . '000'; } /** *POST /dapi/v1/positionSide/dual (HMAC SHA256) USER_DATA * */ - public function postPositionSideDual(array $data=[]){ - $this->type='POST'; - $this->path='/dapi/'.$this->version.'/positionSide/dual'; - $this->data=array_merge($this->data,$data); + public function postPositionSideDual(array $data = [], string $version = Version::V1) + { + $this->type = 'POST'; + $this->path = '/dapi/' . $version . '/positionSide/dual'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /dapi/v1/order (HMAC SHA256) USER_DATA * */ - public function getOrder(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/order'; - $this->data=array_merge($this->data,$data); + public function getOrder(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/order'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /dapi/v1/openOrder (HMAC SHA256) USER_DATA * */ - public function getOpenOrder(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/openOrder'; - $this->data=array_merge($this->data,$data); + public function getOpenOrder(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/openOrder'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /dapi/v1/openOrders (HMAC SHA256) USER_DATA * */ - public function getOpenOrders(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/openOrders'; - $this->data=array_merge($this->data,$data); + public function getOpenOrders(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/openOrders'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /dapi/v1/allOrders (HMAC SHA256) USER_DATA * */ - public function getAllOrders(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/allOrders'; - $this->data=array_merge($this->data,$data); + public function getAllOrders(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/allOrders'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /dapi/v1/balance (HMAC SHA256) USER_DATA * */ - public function getBalance(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/balance'; - $this->data=array_merge($this->data,$data); + public function getBalance(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/balance'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /dapi/v1/account (HMAC SHA256) USER_DATA * */ - public function getAccount(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/account'; - $this->data=array_merge($this->data,$data); + public function getAccount(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/account'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /dapi/v1/userTrades (HMAC SHA256) USER_DATA * */ - public function getUserTrades(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/userTrades'; - $this->data=array_merge($this->data,$data); + public function getUserTrades(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/userTrades'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /dapi/v1/income (HMAC SHA256) USER_DATA * */ - public function getIncome(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/income'; - $this->data=array_merge($this->data,$data); + public function getIncome(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/income'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /dapi/v1/leverageBracket USER_DATA * */ - public function getLeverageBracket(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/leverageBracket'; - $this->data=array_merge($this->data,$data); + public function getLeverageBracket(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/leverageBracket'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /dapi/v1/forceOrders USER_DATA * */ - public function getForceOrders(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/forceOrders'; - $this->data=array_merge($this->data,$data); + public function getForceOrders(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/forceOrders'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /dapi/v1/adlQuantile USER_DATA * */ - public function getAdlQuantile(array $data=[]){ - $this->type='GET'; - $this->path='/dapi/'.$this->version.'/adlQuantile'; - $this->data=array_merge($this->data,$data); + public function getAdlQuantile(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/dapi/' . $version . '/adlQuantile'; + $this->data = array_merge($this->data, $data); return $this->exec(); } @@ -146,30 +159,33 @@ public function getAdlQuantile(array $data=[]){ /** * POST /dapi/v1/listenKey */ - public function postListenKey(array $data=[]){ - $this->type='POST'; - $this->path='/dapi/'.$this->version.'/listenKey'; - $this->data=$data; + public function postListenKey(array $data = [], string $version = Version::V1) + { + $this->type = 'POST'; + $this->path = '/dapi/' . $version . '/listenKey'; + $this->data = $data; return $this->exec(); } /** *PUT /dapi/v1/listenKey */ - public function putListenKey(array $data=[]){ - $this->type='PUT'; - $this->path='/dapi/'.$this->version.'/listenKey'; - $this->data=$data; + public function putListenKey(array $data = [], string $version = Version::V1) + { + $this->type = 'PUT'; + $this->path = '/dapi/' . $version . '/listenKey'; + $this->data = $data; return $this->exec(); } /** *DELETE /dapi/v1/listenKey */ - public function deleteListenKey(array $data=[]){ - $this->type='DELETE'; - $this->path='/dapi/'.$this->version.'/listenKey'; - $this->data=$data; + public function deleteListenKey(array $data = [], string $version = Version::V1) + { + $this->type = 'DELETE'; + $this->path = '/dapi/' . $version . '/listenKey'; + $this->data = $data; return $this->exec(); } } diff --git a/src/Api/Futures/Market.php b/src/Api/Futures/Market.php index 3ba633c..cabfe0c 100644 --- a/src/Api/Futures/Market.php +++ b/src/Api/Futures/Market.php @@ -5,253 +5,278 @@ namespace Lin\Binance\Api\Futures; +use Lin\Binance\Api\Version; use Lin\Binance\Request; class Market extends Request { //Default Dont required HMAC SHA256 - protected $signature=false; + protected $signature = false; //Default seting - protected $version='v1'; +// protected $version = 'v1'; /** *GET /fapi/v1/ping * */ - public function getPing(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/ping'; - $this->data=$data; + public function getPing(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/ping'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/time * */ - public function getTime(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/time'; - $this->data=$data; + public function getTime(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/time'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/exchangeInfo * */ - public function getExchangeInfo(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/exchangeInfo'; - $this->data=$data; + public function getExchangeInfo(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/exchangeInfo'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/depth * */ - public function getDepth(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/depth'; - $this->data=$data; + public function getDepth(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/depth'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/trades * */ - public function getTrades(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/trades'; - $this->data=$data; + public function getTrades(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/trades'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/historicalTrades * */ - public function getHistoricalTrades(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/historicalTrades'; - $this->data=$data; + public function getHistoricalTrades(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/historicalTrades'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/aggTrades * */ - public function getAggTrades(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/aggTrades'; - $this->data=$data; + public function getAggTrades(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/aggTrades'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/premiumIndex * */ - public function getPremiumIndex(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/premiumIndex'; - $this->data=$data; + public function getPremiumIndex(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/premiumIndex'; + $this->data = $data; return $this->exec(); } /** * GET /fapi/v1/fundingRate * */ - public function getFundingRate(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/fundingRate'; - $this->data=$data; + public function getFundingRate(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/fundingRate'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/klines * */ - public function getKlines(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/klines'; - $this->data=$data; + public function getKlines(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/klines'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/continuousKlines * */ - public function getContinuousKlines(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/continuousKlines'; - $this->data=$data; + public function getContinuousKlines(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/continuousKlines'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/indexPriceKlines * */ - public function getIndexPriceKlines(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/indexPriceKlines'; - $this->data=$data; + public function getIndexPriceKlines(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/indexPriceKlines'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/markPriceKlines * */ - public function getMarkPriceKlines(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/markPriceKlines'; - $this->data=$data; + public function getMarkPriceKlines(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/markPriceKlines'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/ticker/24hr * */ - public function get24hr(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/ticker/24hr'; - $this->data=$data; + public function get24hr(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/ticker/24hr'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/ticker/price * */ - public function getTickerPrice(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/ticker/price'; - $this->data=$data; + public function getTickerPrice(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/ticker/price'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/ticker/bookTicker * */ - public function getTickerBookTicker(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/ticker/bookTicker'; - $this->data=$data; + public function getTickerBookTicker(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/ticker/bookTicker'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/openInterest * */ - public function getOpenInterest(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/openInterest'; - $this->data=$data; + public function getOpenInterest(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/openInterest'; + $this->data = $data; return $this->exec(); } /** *GET /futures/data/openInterestHist * */ - public function getOpenInterestHist(array $data=[]){ - $this->type='GET'; - $this->path='/futures/data/openInterestHist'; - $this->data=$data; + public function getOpenInterestHist(array $data = []) + { + $this->type = 'GET'; + $this->path = '/futures/data/openInterestHist'; + $this->data = $data; return $this->exec(); } /** *GET /futures/data/topLongShortAccountRatio * */ - public function getTopLongShortAccountRatio(array $data=[]){ - $this->type='GET'; - $this->path='/futures/data/topLongShortAccountRatio'; - $this->data=$data; + public function getTopLongShortAccountRatio(array $data = []) + { + $this->type = 'GET'; + $this->path = '/futures/data/topLongShortAccountRatio'; + $this->data = $data; return $this->exec(); } /** *GET /futures/data/topLongShortPositionRatio * */ - public function getTopLongShortPositionRatio(array $data=[]){ - $this->type='GET'; - $this->path='/futures/data/topLongShortPositionRatio'; - $this->data=$data; + public function getTopLongShortPositionRatio(array $data = []) + { + $this->type = 'GET'; + $this->path = '/futures/data/topLongShortPositionRatio'; + $this->data = $data; return $this->exec(); } /** *GET /futures/data/globalLongShortAccountRatio * */ - public function getGlobalLongShortAccountRatio(array $data=[]){ - $this->type='GET'; - $this->path='/futures/data/globalLongShortAccountRatio'; - $this->data=$data; + public function getGlobalLongShortAccountRatio(array $data = []) + { + $this->type = 'GET'; + $this->path = '/futures/data/globalLongShortAccountRatio'; + $this->data = $data; return $this->exec(); } /** * GET /futures/data/takerlongshortRatio * */ - public function getTakerlongshortRatio(array $data=[]){ - $this->type='GET'; - $this->path='/futures/data/takerlongshortRatio'; - $this->data=$data; + public function getTakerlongshortRatio(array $data = []) + { + $this->type = 'GET'; + $this->path = '/futures/data/takerlongshortRatio'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/lvtKlines * */ - public function getLvtKlines(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/lvtKlines'; - $this->data=$data; + public function getLvtKlines(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/lvtKlines'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/indexInfo * */ - public function getIndexInfo(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/indexInfo'; - $this->data=$data; + public function getIndexInfo(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/indexInfo'; + $this->data = $data; return $this->exec(); } } diff --git a/src/Api/Futures/Trade.php b/src/Api/Futures/Trade.php index 7ef78bf..9d69d95 100644 --- a/src/Api/Futures/Trade.php +++ b/src/Api/Futures/Trade.php @@ -5,140 +5,153 @@ namespace Lin\Binance\Api\Futures; +use Lin\Binance\Api\Version; use Lin\Binance\Request; class Trade extends Request { //Default required HMAC SHA256 - protected $signature=true; + protected $signature = true; //Default seting - protected $version='v1'; +// protected $version = 'v1'; function __construct(array $data) { parent::__construct($data); - $this->data['timestamp']=time().'000'; + $this->data['timestamp'] = time() . '000'; } /* *GET /fapi/v1/positionSide/dual (HMAC SHA256) */ - public function getPositionSideDual(array $data=[]){ - $this->type='get'; - $this->path='/fapi/'.$this->version.'/positionSide/dual'; - $this->data=array_merge($this->data,$data); + public function getPositionSideDual(array $data = [], string $version = Version::V1) + { + $this->type = 'get'; + $this->path = '/fapi/' . $version . '/positionSide/dual'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* * GET /fapi/v1/multiAssetsMargin (HMAC SHA256) */ - public function getMultiAssetsMargin(array $data=[]){ - $this->type='get'; - $this->path='/fapi/'.$this->version.'/multiAssetsMargin'; - $this->data=array_merge($this->data,$data); + public function getMultiAssetsMargin(array $data = [], string $version = Version::V1) + { + $this->type = 'get'; + $this->path = '/fapi/' . $version . '/multiAssetsMargin'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *POST /fapi/v1/order (HMAC SHA256) */ - public function postOrder(array $data=[]){ - $this->type='POST'; - $this->path='/fapi/'.$this->version.'/order'; - $this->data=array_merge($this->data,$data); + public function postOrder(array $data = [], string $version = Version::V1) + { + $this->type = 'POST'; + $this->path = '/fapi/' . $version . '/order'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *POST /fapi/v1/batchOrders (HMAC SHA256) */ - public function postBatchOrders(array $data=[]){ - $this->type='POST'; - $this->path='/fapi/'.$this->version.'/batchOrders'; - $this->data=array_merge($this->data,$data); + public function postBatchOrders(array $data = [], string $version = Version::V1) + { + $this->type = 'POST'; + $this->path = '/fapi/' . $version . '/batchOrders'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *DELETE /fapi/v1/order (HMAC SHA256) */ - public function deleteOrder(array $data=[]){ - $this->type='DELETE'; - $this->path='/fapi/'.$this->version.'/order'; - $this->data=array_merge($this->data,$data); + public function deleteOrder(array $data = [], string $version = Version::V1) + { + $this->type = 'DELETE'; + $this->path = '/fapi/' . $version . '/order'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *DELETE /fapi/v1/allOpenOrders (HMAC SHA256) */ - public function deleteAllOpenOrders(array $data=[]){ - $this->type='DELETE'; - $this->path='/fapi/'.$this->version.'/allOpenOrders'; - $this->data=array_merge($this->data,$data); + public function deleteAllOpenOrders(array $data = [], string $version = Version::V1) + { + $this->type = 'DELETE'; + $this->path = '/fapi/' . $version . '/allOpenOrders'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *DELETE /fapi/v1/batchOrders (HMAC SHA256) */ - public function deleteBatchOrders(array $data=[]){ - $this->type='DELETE'; - $this->path='/fapi/'.$this->version.'/batchOrders'; - $this->data=array_merge($this->data,$data); + public function deleteBatchOrders(array $data = [], string $version = Version::V1) + { + $this->type = 'DELETE'; + $this->path = '/fapi/' . $version . '/batchOrders'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *POST /fapi/v1/countdownCancelAll (HMAC SHA256) */ - public function postCountdownCancelAll(array $data=[]){ - $this->type='POST'; - $this->path='/fapi/'.$this->version.'/countdownCancelAll'; - $this->data=array_merge($this->data,$data); + public function postCountdownCancelAll(array $data = [], string $version = Version::V1) + { + $this->type = 'POST'; + $this->path = '/fapi/' . $version . '/countdownCancelAll'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *POST /fapi/v1/leverage (HMAC SHA256) */ - public function postLeverage(array $data=[]){ - $this->type='post'; - $this->path='/fapi/'.$this->version.'/leverage'; - $this->data=array_merge($this->data,$data); + public function postLeverage(array $data = [], string $version = Version::V1) + { + $this->type = 'post'; + $this->path = '/fapi/' . $version . '/leverage'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *POST /fapi/v1/marginType (HMAC SHA256) */ - public function getMarginType(array $data=[]){ - $this->type='POST'; - $this->path='/fapi/'.$this->version.'/marginType'; - $this->data=array_merge($this->data,$data); + public function getMarginType(array $data = [], string $version = Version::V1) + { + $this->type = 'POST'; + $this->path = '/fapi/' . $version . '/marginType'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *POST /fapi/v1/positionMargin (HMAC SHA256) */ - public function postPositionMargin(array $data=[]){ - $this->type='POST'; - $this->path='/fapi/'.$this->version.'/positionMargin'; - $this->data=array_merge($this->data,$data); + public function postPositionMargin(array $data = [], string $version = Version::V1) + { + $this->type = 'POST'; + $this->path = '/fapi/' . $version . '/positionMargin'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /* *GET /fapi/v1/positionMargin/history (HMAC SHA256) */ - public function getPositionMarginHistory(array $data=[]){ - $this->type='get'; - $this->path='/fapi/'.$this->version.'/positionMargin/history'; - $this->data=array_merge($this->data,$data); + public function getPositionMarginHistory(array $data = [], string $version = Version::V1) + { + $this->type = 'get'; + $this->path = '/fapi/' . $version . '/positionMargin/history'; + $this->data = array_merge($this->data, $data); return $this->exec(); } } diff --git a/src/Api/Futures/User.php b/src/Api/Futures/User.php index ae7e1a8..6b95274 100644 --- a/src/Api/Futures/User.php +++ b/src/Api/Futures/User.php @@ -5,210 +5,230 @@ namespace Lin\Binance\Api\Futures; +use Lin\Binance\Api\Version; use Lin\Binance\Request; class User extends Request { //Default required HMAC SHA256 - protected $signature=true; + protected $signature = true; //Default seting - protected $version='v1'; +// protected $version = 'v1'; function __construct(array $data) { parent::__construct($data); - $this->data['timestamp']=time().'000'; + $this->data['timestamp'] = time() . '000'; } /** *POST /fapi/v1/positionSide/dual (HMAC SHA256) USER_DATA * */ - public function postPositionSideDual(array $data=[]){ - $this->type='POST'; - $this->path='/fapi/'.$this->version.'/positionSide/dual'; - $this->data=array_merge($this->data,$data); + public function postPositionSideDual(array $data = [], string $version = Version::V1) + { + $this->type = 'POST'; + $this->path = '/fapi/' . $version . '/positionSide/dual'; + $this->data = array_merge($this->data, $data); return $this->exec(); } - + /** *GET /fapi/v1/positionSide/dual (HMAC SHA256) USER_DATA * */ - public function getPositionSideDual(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/positionSide/dual'; - $this->data=array_merge($this->data,$data); + public function getPositionSideDual(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/positionSide/dual'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /fapi/v1/order (HMAC SHA256) USER_DATA * */ - public function getOrder(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/order'; - $this->data=array_merge($this->data,$data); + public function getOrder(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/order'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /fapi/v1/openOrder (HMAC SHA256) USER_DATA * */ - public function getOpenOrder(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/openOrder'; - $this->data=array_merge($this->data,$data); + public function getOpenOrder(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/openOrder'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /fapi/v1/openOrders (HMAC SHA256) USER_DATA * */ - public function getOpenOrders(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/openOrders'; - $this->data=array_merge($this->data,$data); + public function getOpenOrders(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/openOrders'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /fapi/v1/allOrders (HMAC SHA256) USER_DATA * */ - public function getAllOrders(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/allOrders'; - $this->data=array_merge($this->data,$data); + public function getAllOrders(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/allOrders'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /fapi/v2/balance (HMAC SHA256) USER_DATA * */ - public function getBalance(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/balance'; - $this->data=array_merge($this->data,$data); + public function getBalance(array $data = [], string $version = Version::V2) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/balance'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /fapi/v2/account (HMAC SHA256) USER_DATA * */ - public function getAccount(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/account'; - $this->data=array_merge($this->data,$data); + public function getAccount(array $data = [], string $version = Version::V2) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/account'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /fapi/v2/positionRisk (HMAC SHA256) USER_DATA **/ - public function getPositionRisk(array $data=[]){ - $this->type='get'; - $this->path='/fapi/'.$this->version.'/positionRisk'; - $this->data=array_merge($this->data,$data); + public function getPositionRisk(array $data = [], string $version = Version::V2) + { + $this->type = 'get'; + $this->path = '/fapi/' . $version . '/positionRisk'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /fapi/v1/userTrades (HMAC SHA256) USER_DATA * */ - public function getUserTrades(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/userTrades'; - $this->data=array_merge($this->data,$data); + public function getUserTrades(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/userTrades'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /fapi/v1/income (HMAC SHA256) USER_DATA * */ - public function getIncome(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/income'; - $this->data=array_merge($this->data,$data); + public function getIncome(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/income'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /fapi/v1/leverageBracket USER_DATA * */ - public function getLeverageBracket(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/leverageBracket'; - $this->data=array_merge($this->data,$data); + public function getLeverageBracket(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/leverageBracket'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /fapi/v1/forceOrders USER_DATA * */ - public function getForceOrders(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/forceOrders'; - $this->data=array_merge($this->data,$data); + public function getForceOrders(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/forceOrders'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** *GET /fapi/v1/adlQuantile USER_DATA * */ - public function getAdlQuantile(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/adlQuantile'; - $this->data=array_merge($this->data,$data); + public function getAdlQuantile(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/adlQuantile'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** * GET /fapi/v1/commissionRate (HMAC SHA256) * */ - public function getCommissionRate(array $data=[]){ - $this->type='GET'; - $this->path='/fapi/'.$this->version.'/commissionRate'; - $this->data=array_merge($this->data,$data); + public function getCommissionRate(array $data = [], string $version = Version::V1) + { + $this->type = 'GET'; + $this->path = '/fapi/' . $version . '/commissionRate'; + $this->data = array_merge($this->data, $data); return $this->exec(); } /** * POST /fapi/v1/listenKey */ - public function postListenKey(array $data=[]){ - $this->type='POST'; - $this->path='/fapi/'.$this->version.'/listenKey'; - $this->data=$data; + public function postListenKey(array $data = [], string $version = Version::V1) + { + $this->type = 'POST'; + $this->path = '/fapi/' . $version . '/listenKey'; + $this->data = $data; return $this->exec(); } /** *PUT /fapi/v1/listenKey */ - public function putListenKey(array $data=[]){ - $this->type='PUT'; - $this->path='/fapi/'.$this->version.'/listenKey'; - $this->data=$data; + public function putListenKey(array $data = [], string $version = Version::V1) + { + $this->type = 'PUT'; + $this->path = '/fapi/' . $version . '/listenKey'; + $this->data = $data; return $this->exec(); } /** *DELETE /fapi/v1/listenKey */ - public function deleteListenKey(array $data=[]){ - $this->type='DELETE'; - $this->path='/fapi/'.$this->version.'/listenKey'; - $this->data=$data; + public function deleteListenKey(array $data = [], string $version = Version::V1) + { + $this->type = 'DELETE'; + $this->path = '/fapi/' . $version . '/listenKey'; + $this->data = $data; return $this->exec(); } /** *GET /fapi/v1/apiTradingStatus */ - public function getApiTradingStatus(array $data=[]){ - $this->type='get'; - $this->path='/fapi/'.$this->version.'/apiTradingStatus'; - $this->data=$data; + public function getApiTradingStatus(array $data = [], string $version = Version::V1) + { + $this->type = 'get'; + $this->path = '/fapi/' . $version . '/apiTradingStatus'; + $this->data = $data; return $this->exec(); } } diff --git a/src/Api/Spot/System.php b/src/Api/Spot/System.php index 4242058..7f29239 100644 --- a/src/Api/Spot/System.php +++ b/src/Api/Spot/System.php @@ -5,170 +5,184 @@ namespace Lin\Binance\Api\Spot; +use Lin\Binance\Api\Version; use Lin\Binance\Request; class System extends Request { //Default Dont required HMAC SHA256 - protected $signature=false; + protected $signature = false; //Default seting - protected $version='v3'; +// protected $version = 'v3'; /** * 测试服务器连通性 PING - GET /api/v3/ping + * GET /api/v3/ping * */ - public function getPing(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/ping'; - $this->data=$data; + public function getPing(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/ping'; + $this->data = $data; return $this->exec(); } /** *获取服务器时间 - GET /api/v3/time + * GET /api/v3/time * */ - public function getTime(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/time'; - $this->data=$data; + public function getTime(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/time'; + $this->data = $data; return $this->exec(); } /** *交易规范信息 - GET /api/v3/exchangeInfo + * GET /api/v3/exchangeInfo * */ - public function getExchangeInfo(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/exchangeInfo'; - $this->data=$data; + public function getExchangeInfo(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/exchangeInfo'; + $this->data = $data; return $this->exec(); } /** *深度信息 - GET /api/v3/depth - - symbol STRING YES - limit INT NO 默认 100; 最大 1000. 可选值:[5, 10, 20, 50, 100, 500, 1000] + * GET /api/v3/depth + * + * symbol STRING YES + * limit INT NO 默认 100; 最大 1000. 可选值:[5, 10, 20, 50, 100, 500, 1000] * */ - public function getDepth(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/depth'; - $this->data=$data; + public function getDepth(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/depth'; + $this->data = $data; return $this->exec(); } /** *近期成交 - GET /api/v3/trades - - symbol STRING YES - limit INT NO Default 500; max 1000. + * GET /api/v3/trades + * + * symbol STRING YES + * limit INT NO Default 500; max 1000. * */ - public function getTrades(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/trades'; - $this->data=$data; + public function getTrades(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/trades'; + $this->data = $data; return $this->exec(); } /** *查询历史成交(MARKET_DATA) - GET /api/v3/historicalTrades + * GET /api/v3/historicalTrades * */ - public function getHistoricalTrades(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/historicalTrades'; - $this->data=$data; + public function getHistoricalTrades(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/historicalTrades'; + $this->data = $data; return $this->exec(); } /** *近期成交(归集) - GET /api/v3/aggTrades - - symbol STRING YES - fromId LONG NO 从包含fromID的成交开始返回结果 - startTime LONG NO 从该时刻之后的成交记录开始返回结果 - endTime LONG NO 返回该时刻为止的成交记录 - limit INT NO 默认 500; 最大 1000. + * GET /api/v3/aggTrades + * + * symbol STRING YES + * fromId LONG NO 从包含fromID的成交开始返回结果 + * startTime LONG NO 从该时刻之后的成交记录开始返回结果 + * endTime LONG NO 返回该时刻为止的成交记录 + * limit INT NO 默认 500; 最大 1000. * */ - public function getAggTrades(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/aggTrades'; - $this->data=$data; + public function getAggTrades(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/aggTrades'; + $this->data = $data; return $this->exec(); } /** *K线数据 - GET /api/v3/klines + * GET /api/v3/klines * */ - public function getKlines(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/klines'; - $this->data=$data; + public function getKlines(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/klines'; + $this->data = $data; return $this->exec(); } /** *当前平均价格 - GET /api/v3/avgPrice - Name Type Mandatory Description - symbol STRING YES + * GET /api/v3/avgPrice + * Name Type Mandatory Description + * symbol STRING YES * */ - public function getAvgPrice(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/avgPrice'; - $this->data=$data; + public function getAvgPrice(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/avgPrice'; + $this->data = $data; return $this->exec(); } /** *系统状态 (System) - GET /sapi/v3/system/status + * GET /sapi/v3/system/status * */ - public function getSystemStatus(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/system/status'; - $this->data=$data; + public function getSystemStatus(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/system/status'; + $this->data = $data; return $this->exec(); } /** *24hr价格变动情况 - GET /api/v3/ticker/24hr + * GET /api/v3/ticker/24hr * */ - public function get24hr(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/ticker/24hr'; - $this->data=$data; + public function get24hr(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/ticker/24hr'; + $this->data = $data; return $this->exec(); } /** * 最新价格接口 - GET /api/v3/ticker/price + * GET /api/v3/ticker/price * */ - public function getTickerPrice(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/ticker/price'; - $this->data=$data; + public function getTickerPrice(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/ticker/price'; + $this->data = $data; return $this->exec(); } /** *最优挂单接口 - GET /api/v3/ticker/bookTicker + * GET /api/v3/ticker/bookTicker * */ - public function getTickerBookTicker(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/ticker/bookTicker'; - $this->data=$data; + public function getTickerBookTicker(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/ticker/bookTicker'; + $this->data = $data; return $this->exec(); } } diff --git a/src/Api/Spot/Trade.php b/src/Api/Spot/Trade.php index 0424b55..84ea235 100644 --- a/src/Api/Spot/Trade.php +++ b/src/Api/Spot/Trade.php @@ -5,140 +5,147 @@ namespace Lin\Binance\Api\Spot; +use Lin\Binance\Api\Version; use Lin\Binance\Request; class Trade extends Request { //Default required HMAC SHA256 - protected $signature=true; + protected $signature = true; //Default seting - protected $version='v3'; +// protected $version='v3'; /** * 下单 (TRADE) - POST /api/v3/order (HMAC SHA256) - - Name Type Mandatory Description - symbol STRING YES - side ENUM YES - type ENUM YES - timeInForce ENUM NO - quantity DECIMAL YES - price DECIMAL NO - newClientOrderId STRING NO 用户自定义的orderid,如空缺系统会自动赋值 - stopPrice DECIMAL NO 仅 STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, TAKE_PROFIT_LIMIT 需要此参数 - icebergQty DECIMAL NO 仅有限价单(包括条件限价单与限价做事单)可以使用该参数,含义为创建冰山订单并指定冰山订单的尺寸 - newOrderRespType ENUM NO 指定响应类型 ACK, RESULT, or FULL; MARKET 与 LIMIT 订单默认为FULL, 其他默认为ACK. - recvWindow LONG NO - timestamp LONG YES - - - 根据 order type的不同,某些参数强制要求,具体如下: - Type 强制要求的参数 - LIMIT timeInForce, quantity, price - MARKET quantity - STOP_LOSS quantity, stopPrice - STOP_LOSS_LIMIT timeInForce, quantity, price, stopPrice - TAKE_PROFIT quantity, stopPrice - TAKE_PROFIT_LIMIT timeInForce, quantity, price, stopPrice - LIMIT_MAKER quantity, price - + * POST /api/v3/order (HMAC SHA256) + * + * Name Type Mandatory Description + * symbol STRING YES + * side ENUM YES + * type ENUM YES + * timeInForce ENUM NO + * quantity DECIMAL YES + * price DECIMAL NO + * newClientOrderId STRING NO 用户自定义的orderid,如空缺系统会自动赋值 + * stopPrice DECIMAL NO 仅 STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, TAKE_PROFIT_LIMIT 需要此参数 + * icebergQty DECIMAL NO 仅有限价单(包括条件限价单与限价做事单)可以使用该参数,含义为创建冰山订单并指定冰山订单的尺寸 + * newOrderRespType ENUM NO 指定响应类型 ACK, RESULT, or FULL; MARKET 与 LIMIT 订单默认为FULL, 其他默认为ACK. + * recvWindow LONG NO + * timestamp LONG YES + * + * + * 根据 order type的不同,某些参数强制要求,具体如下: + * Type 强制要求的参数 + * LIMIT timeInForce, quantity, price + * MARKET quantity + * STOP_LOSS quantity, stopPrice + * STOP_LOSS_LIMIT timeInForce, quantity, price, stopPrice + * TAKE_PROFIT quantity, stopPrice + * TAKE_PROFIT_LIMIT timeInForce, quantity, price, stopPrice + * LIMIT_MAKER quantity, price * */ - public function postOrder(array $data){ - $this->type='POST'; - $this->path='/api/'.$this->version.'/order'; - - $data['timestamp']=time().'000'; - $data['newOrderRespType']=$data['newOrderRespType'] ?? 'ACK'; - - switch (strtoupper($data['type'])){ - case 'LIMIT':{ - $data['timeInForce']=$data['timeInForce'] ?? 'GTC'; + public function postOrder(array $data, string $version = Version::V3) + { + $this->type = 'POST'; + $this->path = '/api/' . $version . '/order'; + + $data['timestamp'] = time() . '000'; + $data['newOrderRespType'] = $data['newOrderRespType'] ?? 'ACK'; + + switch (strtoupper($data['type'])) { + case 'LIMIT': + { + $data['timeInForce'] = $data['timeInForce'] ?? 'GTC'; break; } } - $this->data=$data; + $this->data = $data; return $this->exec(); } /** * 测试下单接口 (TRADE) - POST /api/v3/order/test (HMAC SHA256) + * POST /api/v3/order/test (HMAC SHA256) * */ - public function postOrderTest(array $data){ - $this->type='POST'; - $this->path='/api/'.$this->version.'/order/test'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function postOrderTest(array $data, string $version = Version::V3) + { + $this->type = 'POST'; + $this->path = '/api/' . $version . '/order/test'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } /** *撤销订单 (TRADE) - DELETE /api/v3/order (HMAC SHA256) - - symbol STRING YES - orderId LONG NO - origClientOrderId STRING NO - newClientOrderId STRING NO 用户自定义的本次撤销操作的ID(注意不是被撤销的订单的自定义ID)。如无指定会自动赋值。 - recvWindow LONG NO - timestamp LONG YES + * DELETE /api/v3/order (HMAC SHA256) + * + * symbol STRING YES + * orderId LONG NO + * origClientOrderId STRING NO + * newClientOrderId STRING NO 用户自定义的本次撤销操作的ID(注意不是被撤销的订单的自定义ID)。如无指定会自动赋值。 + * recvWindow LONG NO + * timestamp LONG YES * */ - public function deleteOrder(array $data){ - $this->type='DELETE'; - $this->path='/api/'.$this->version.'/order'; + public function deleteOrder(array $data, string $version = Version::V3) + { + $this->type = 'DELETE'; + $this->path = '/api/' . $version . '/order'; - $data['timestamp']=time().'000'; + $data['timestamp'] = time() . '000'; - $this->data=$data; + $this->data = $data; return $this->exec(); } /** *撤销订单 (TRADE) - DELETE /api/v3/openOrders (HMAC SHA256) - - symbol STRING YES - recvWindow LONG NO - timestamp LONG YES + * DELETE /api/v3/openOrders (HMAC SHA256) + * + * symbol STRING YES + * recvWindow LONG NO + * timestamp LONG YES * */ - public function deleteAllOrders(array $data){ - $this->type='DELETE'; - $this->path='/api/'.$this->version.'/openOrders'; + public function deleteAllOrders(array $data, string $version = Version::V3) + { + $this->type = 'DELETE'; + $this->path = '/api/' . $version . '/openOrders'; - $data['timestamp']=time().'000'; + $data['timestamp'] = time() . '000'; - $this->data=$data; + $this->data = $data; return $this->exec(); } /** * New OCO (TRADE) - POST /api/v3/order/oco (HMAC SHA256) + * POST /api/v3/order/oco (HMAC SHA256) * */ - public function postOrderOco(array $data=[]){ - $this->type='POST'; - $this->path='/api/'.$this->version.'/order/oco'; + public function postOrderOco(array $data = [], string $version = Version::V3) + { + $this->type = 'POST'; + $this->path = '/api/' . $version . '/order/oco'; - $data['timestamp']=time().'000'; + $data['timestamp'] = time() . '000'; - $this->data=$data; + $this->data = $data; return $this->exec(); } /** * Cancel OCO (TRADE) - DELETE /api/v3/orderList (HMAC SHA256) Cancel an entire Order List. + * DELETE /api/v3/orderList (HMAC SHA256) Cancel an entire Order List. * */ - public function deleteOrderList(array $data=[]){ - $this->type='DELETE'; - $this->path='/api/'.$this->version.'/orderList'; + public function deleteOrderList(array $data = [], string $version = Version::V3) + { + $this->type = 'DELETE'; + $this->path = '/api/' . $version . '/orderList'; - $data['timestamp']=time().'000'; + $data['timestamp'] = time() . '000'; - $this->data=$data; + $this->data = $data; return $this->exec(); } diff --git a/src/Api/Spot/User.php b/src/Api/Spot/User.php index 8d3246e..c858e3b 100644 --- a/src/Api/Spot/User.php +++ b/src/Api/Spot/User.php @@ -5,101 +5,107 @@ namespace Lin\Binance\Api\Spot; +use Lin\Binance\Api\Version; use Lin\Binance\Request; class User extends Request { //Default required HMAC SHA256 - protected $signature=true; + protected $signature = true; //Default seting - protected $version='v3'; +// protected $version = 'v3'; /** * 查看账户当前挂单 (USER_DATA) - GET /api/v3/openOrders (HMAC SHA256) + * GET /api/v3/openOrders (HMAC SHA256) * */ - public function getOpenOrders(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/openOrders'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function getOpenOrders(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/openOrders'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } /** *查询所有订单(包括历史订单) (USER_DATA) - GET /api/v3/allOrders (HMAC SHA256) - - Name Type Mandatory Description - symbol STRING YES - orderId LONG NO 只返回此orderID之后的订单,缺省返回最近的订单 - startTime LONG NO - endTime LONG NO - limit INT NO Default 500; max 1000. - recvWindow LONG NO - timestamp LONG YES + * GET /api/v3/allOrders (HMAC SHA256) + * + * Name Type Mandatory Description + * symbol STRING YES + * orderId LONG NO 只返回此orderID之后的订单,缺省返回最近的订单 + * startTime LONG NO + * endTime LONG NO + * limit INT NO Default 500; max 1000. + * recvWindow LONG NO + * timestamp LONG YES * */ - public function getAllOrders(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/allOrders'; + public function getAllOrders(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/allOrders'; - $data['timestamp']=time().'000'; - $data['limit']=$data['limit'] ?? 1000; + $data['timestamp'] = time() . '000'; + $data['limit'] = $data['limit'] ?? 1000; - $this->data=$data; + $this->data = $data; return $this->exec(); } /** *查询订单 (USER_DATA) - GET /api/v3/order (HMAC SHA256) - - Name Type Mandatory Description - symbol STRING YES - orderId LONG NO - origClientOrderId STRING NO - recvWindow LONG NO - timestamp LONG YES + * GET /api/v3/order (HMAC SHA256) + * + * Name Type Mandatory Description + * symbol STRING YES + * orderId LONG NO + * origClientOrderId STRING NO + * recvWindow LONG NO + * timestamp LONG YES * */ - public function getOrder(array $data){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/order'; + public function getOrder(array $data, string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/order'; - $data['timestamp']=time().'000'; + $data['timestamp'] = time() . '000'; - $this->data=$data; + $this->data = $data; return $this->exec(); } /** *账户信息 (USER_DATA) - GET /api/v3/account (HMAC SHA256) - - Name Type Mandatory Description - recvWindow LONG NO - timestamp LONG YES + * GET /api/v3/account (HMAC SHA256) + * + * Name Type Mandatory Description + * recvWindow LONG NO + * timestamp LONG YES * */ - public function getAccount(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/account'; + public function getAccount(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/account'; - $data['timestamp']=time().'000'; + $data['timestamp'] = time() . '000'; - $this->data=$data; + $this->data = $data; return $this->exec(); } /** *账户成交历史 (USER_DATA) - GET /api/v3/myTrades (HMAC SHA256) + * GET /api/v3/myTrades (HMAC SHA256) * */ - public function getMyTrades(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/myTrades'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function getMyTrades(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/myTrades'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } @@ -108,47 +114,51 @@ public function getMyTrades(array $data=[]){ *充值历史 (USER_DATA) * GET /sapi/v1/capital/deposit/hisrec * */ - public function getCapitalDepositHisrec(array $data=[]){ - $this->type='GET'; - $this->path='/sapi/'.$this->version.'/capital/deposit/hisrec'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function getCapitalDepositHisrec(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/sapi/' . $version . '/capital/deposit/hisrec'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } /** *提现历史 (USER_DATA) - GET /sapi/v1/capital/withdraw/history + * GET /sapi/v1/capital/withdraw/history * */ - public function getCapitalWithdrawHistory(array $data=[]){ - $this->type='GET'; - $this->path='/sapi/'.$this->version.'/capital/withdraw/history'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function getCapitalWithdrawHistory(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/sapi/' . $version . '/capital/withdraw/history'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } - + /** * 提币 (USER_DATA) * POST /sapi/v1/capital/withdraw/apply (HMAC SHA256) */ - public function postCapitalWithdraw(array $data=[]) { + public function postCapitalWithdraw(array $data = [], string $version = Version::V3) + { $this->type = 'POST'; - $this->path='/sapi/v1/capital/withdraw/apply'; - $data['timestamp']=time().'000'; - $this->data=$data; + $this->path = '/sapi/v1/capital/withdraw/apply'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } /** *获取充值地址(USER_DATA) - GET /sapi/v1/capital/deposit/address + * GET /sapi/v1/capital/deposit/address * */ - public function getCapitalDepositAddress(array $data=[]){ - $this->type='GET'; - $this->path='/sapi/'.$this->version.'/capital/deposit/address'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function getCapitalDepositAddress(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/sapi/' . $version . '/capital/deposit/address'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } @@ -157,12 +167,13 @@ public function getCapitalDepositAddress(array $data=[]){ *账户状态 (USER_DATA) * GET /sapi/v1/account/status * */ - public function getAccountStatus(array $data=[]){ - $this->signature=false; - $this->type='GET'; - $this->path='/sapi/'.$this->version.'/account/status'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function getAccountStatus(array $data = [], string $version = Version::V3) + { + $this->signature = false; + $this->type = 'GET'; + $this->path = '/sapi/' . $version . '/account/status'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } @@ -170,103 +181,113 @@ public function getAccountStatus(array $data=[]){ *小额资产转换历史 (USER_DATA) * GET /sapi/v1/asset/dribblet * */ - public function getAssetDribblet(array $data=[]){ - $this->type='GET'; - $this->path='/sapi/'.$this->version.'/asset/dribblet'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function getAssetDribblet(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/sapi/' . $version . '/asset/dribblet'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } /** *交易手续费率查询 (USER_DATA) - GET /sapi/v1/asset/tradeFee + * GET /sapi/v1/asset/tradeFee * */ - public function getTradeFee(array $data=[]){ - $this->type='GET'; - $this->path='/sapi/'.$this->version.'/asset/tradeFee'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function getTradeFee(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/sapi/' . $version . '/asset/tradeFee'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } /** *上架资产详情 (USER_DATA) - GET /sapi/v1/asset/assetDetail + * GET /sapi/v1/asset/assetDetail * */ - public function getAssetDetail(array $data=[]){ - $this->type='GET'; - $this->path='/sapi/'.$this->version.'/asset/assetDetail'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function getAssetDetail(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/sapi/' . $version . '/asset/assetDetail'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } /** * POST /sapi/v1/asset/transfer (HMAC SHA256) * */ - public function getAssetTransfer(array $data=[]){ - $this->type='POST'; - $this->path='/sapi/'.$this->version.'/asset/transfer'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function getAssetTransfer(array $data = [], string $version = Version::V3) + { + $this->type = 'POST'; + $this->path = '/sapi/' . $version . '/asset/transfer'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } /** * POST /sapi/v1/asset/get-funding-asset (HMAC SHA256) * */ - public function postAssetGetFundingAsset(array $data=[]){ - $this->type='POST'; - $this->path='/sapi/'.$this->version.'/asset/get-funding-asset'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function postAssetGetFundingAsset(array $data = [], string $version = Version::V3) + { + $this->type = 'POST'; + $this->path = '/sapi/' . $version . '/asset/get-funding-asset'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } /** * GET /sapi/v1/account/apiRestrictions (HMAC SHA256) * */ - public function getAccountApiRestrictions(array $data=[]){ - $this->type='GET'; - $this->path='/sapi/'.$this->version.'/account/apiRestrictions'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function getAccountApiRestrictions(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/sapi/' . $version . '/account/apiRestrictions'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } //Websocket Account Pull + /** * POST /api/v3/userDataStream */ - public function postUserDataStream(array $data=[]){ - $this->type='POST'; - $this->path='/api/'.$this->version.'/userDataStream'; - $this->data=$data; + public function postUserDataStream(array $data = [], string $version = Version::V3) + { + $this->type = 'POST'; + $this->path = '/api/' . $version . '/userDataStream'; + $this->data = $data; return $this->exec(); } /** *PUT /api/v3/userDataStream */ - public function putUserDataStream(array $data=[]){ - $this->type='PUT'; - $this->path='/api/'.$this->version.'/userDataStream'; - $this->data=$data; - $this->signature=false; + public function putUserDataStream(array $data = [], string $version = Version::V3) + { + $this->type = 'PUT'; + $this->path = '/api/' . $version . '/userDataStream'; + $this->data = $data; + $this->signature = false; return $this->exec(); } /** *DELETE /api/v3/userDataStream */ - public function deleteUserDataStream(array $data=[]){ - $this->type='DELETE'; - $this->path='/api/'.$this->version.'/userDataStream'; - $this->data=$data; - $this->signature=false; + public function deleteUserDataStream(array $data = [], string $version = Version::V3) + { + $this->type = 'DELETE'; + $this->path = '/api/' . $version . '/userDataStream'; + $this->data = $data; + $this->signature = false; return $this->exec(); } @@ -274,30 +295,33 @@ public function deleteUserDataStream(array $data=[]){ /** * POST /sapi/v1/userDataStream */ - public function postUserDataStreamSapi(array $data=[]){ - $this->type='POST'; - $this->path='/api/'.$this->version.'/userDataStream'; - $this->data=$data; + public function postUserDataStreamSapi(array $data = [], string $version = Version::V3) + { + $this->type = 'POST'; + $this->path = '/api/' . $version . '/userDataStream'; + $this->data = $data; return $this->exec(); } /** *PUT /sapi/v1/userDataStream */ - public function putUserDataStreamSapi(array $data=[]){ - $this->type='PUT'; - $this->path='/api/'.$this->version.'/userDataStream'; - $this->data=$data; + public function putUserDataStreamSapi(array $data = [], string $version = Version::V3) + { + $this->type = 'PUT'; + $this->path = '/api/' . $version . '/userDataStream'; + $this->data = $data; return $this->exec(); } /** *DELETE /sapi/v1/userDataStream */ - public function deleteUserDataStreamSapi(array $data=[]){ - $this->type='DELETE'; - $this->path='/api/'.$this->version.'/userDataStream'; - $this->data=$data; + public function deleteUserDataStreamSapi(array $data = [], string $version = Version::V3) + { + $this->type = 'DELETE'; + $this->path = '/api/' . $version . '/userDataStream'; + $this->data = $data; return $this->exec(); } @@ -305,44 +329,47 @@ public function deleteUserDataStreamSapi(array $data=[]){ /** * POST /sapi/v1/userDataStream/isolated */ - public function postUserDataStreamIsolated(array $data=[]){ - $this->type='POST'; - $this->path='/api/'.$this->version.'/userDataStream/isolated'; - $this->data=$data; + public function postUserDataStreamIsolated(array $data = [], string $version = Version::V3) + { + $this->type = 'POST'; + $this->path = '/api/' . $version . '/userDataStream/isolated'; + $this->data = $data; return $this->exec(); } /** *PUT /sapi/v1/userDataStream/isolated */ - public function putUserDataStreamIsolated(array $data=[]){ - $this->type='PUT'; - $this->path='/api/'.$this->version.'/userDataStream/isolated'; - $this->data=$data; + public function putUserDataStreamIsolated(array $data = [], string $version = Version::V3) + { + $this->type = 'PUT'; + $this->path = '/api/' . $version . '/userDataStream/isolated'; + $this->data = $data; return $this->exec(); } /** *DELETE /sapi/v1/userDataStream/isolated */ - public function deleteUserDataStreamIsolated(array $data=[]){ - $this->type='DELETE'; - $this->path='/api/'.$this->version.'/userDataStream/isolated'; - $this->data=$data; + public function deleteUserDataStreamIsolated(array $data = [], string $version = Version::V3) + { + $this->type = 'DELETE'; + $this->path = '/api/' . $version . '/userDataStream/isolated'; + $this->data = $data; return $this->exec(); } - /** *Query OCO (USER_DATA) * GET /api/v3/orderList (HMAC SHA256) */ - public function getOrderList(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/orderList'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function getOrderList(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/orderList'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } @@ -350,11 +377,12 @@ public function getOrderList(array $data=[]){ *Query all OCO (USER_DATA) * GET /api/v3/allOrderList (HMAC SHA256) */ - public function getAllOrderList(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/allOrderList'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function getAllOrderList(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/allOrderList'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } @@ -363,11 +391,12 @@ public function getAllOrderList(array $data=[]){ *Query Open OCO (USER_DATA) * GET /api/v3/openOrderList (HMAC SHA256) */ - public function getOpenOrderList(array $data=[]){ - $this->type='GET'; - $this->path='/api/'.$this->version.'/openOrderList'; - $data['timestamp']=time().'000'; - $this->data=$data; + public function getOpenOrderList(array $data = [], string $version = Version::V3) + { + $this->type = 'GET'; + $this->path = '/api/' . $version . '/openOrderList'; + $data['timestamp'] = time() . '000'; + $this->data = $data; return $this->exec(); } } diff --git a/src/Api/Version.php b/src/Api/Version.php new file mode 100644 index 0000000..b6df9c9 --- /dev/null +++ b/src/Api/Version.php @@ -0,0 +1,13 @@ +