Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

update new api #14

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ go(function () {
| KuMEX\SDK\PublicApi\Symbol::getLevel3Message() | NO | https://docs.kucoin.com/futures/##level-3-pulling-messages |
| KuMEX\SDK\PublicApi\Symbol::getTradeHistory() | NO | https://docs.kucoin.com/futures/#get-trade-histories |
| KuMEX\SDK\PublicApi\Symbol::getKLines() | NO | https://docs.kucoin.com/futures/?lang=en_US#get-k-line-data-of-contract |
| KuMEX\SDK\PublicApi\Symbol::getLevel2Depth20 | NO | https://docs.kucoin.center/futures/cn/#level-2-2 |
| KuMEX\SDK\PublicApi\Symbol::getLevel2Depth100 | NO | https://docs.kucoin.center/futures/cn/#level-2-2 |

</details>

Expand Down
2 changes: 1 addition & 1 deletion src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class Api
/**
* @var string SDK update date
*/
const UPDATE_DATE = '2020.06.18';
const UPDATE_DATE = '2021.08.02';

/**
* @var string
Expand Down
58 changes: 43 additions & 15 deletions src/PublicApi/Symbol.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Symbol extends KuMEXApi
/**
* Get the ticker details of a symbol.
*
* @param string $symbol
* @param string $symbol
* @return array
* @throws \KuMEX\SDK\Exceptions\BusinessException
* @throws \KuMEX\SDK\Exceptions\HttpException
Expand All @@ -30,7 +30,7 @@ public function getTicker($symbol)
/**
* Get the snapshot details of a symbol.
*
* @param string $symbol
* @param string $symbol
* @return array
* @throws \KuMEX\SDK\Exceptions\BusinessException
* @throws \KuMEX\SDK\Exceptions\HttpException
Expand All @@ -45,7 +45,7 @@ public function getLevel2Snapshot($symbol)
/**
* Get the snapshot details of a symbol.
*
* @param string $symbol
* @param string $symbol
* @return array
* @throws \KuMEX\SDK\Exceptions\BusinessException
* @throws \KuMEX\SDK\Exceptions\HttpException
Expand All @@ -60,7 +60,7 @@ public function getLevel3Snapshot($symbol)
/**
* Get the snapshot details of a symbol.
*
* @param string $symbol
* @param string $symbol
* @return array
* @throws \KuMEX\SDK\Exceptions\BusinessException
* @throws \KuMEX\SDK\Exceptions\HttpException
Expand All @@ -75,9 +75,9 @@ public function getV2Level3Snapshot($symbol)
/**
* Get the level2 message of a symbol.
*
* @param string $symbol
* @param number $start
* @param number $end
* @param string $symbol
* @param number $start
* @param number $end
* @return array
* @throws \KuMEX\SDK\Exceptions\BusinessException
* @throws \KuMEX\SDK\Exceptions\HttpException
Expand All @@ -92,17 +92,17 @@ public function getLevel2Message($symbol, $start, $end)
}

/**
* @deprecated
*
* Get the level3 message of a symbol.
*
* @param string $symbol
* @param number $start
* @param number $end
* @param string $symbol
* @param number $start
* @param number $end
* @return array
* @throws \KuMEX\SDK\Exceptions\BusinessException
* @throws \KuMEX\SDK\Exceptions\HttpException
* @throws \KuMEX\SDK\Exceptions\InvalidApiUriException
* @deprecated
*
* Get the level3 message of a symbol.
*
*/
public function getLevel3Message($symbol, $start, $end)
{
Expand All @@ -115,7 +115,7 @@ public function getLevel3Message($symbol, $start, $end)
/**
* Get the trade history details of a symbol.
*
* @param string $symbol
* @param string $symbol
* @return array
* @throws \KuMEX\SDK\Exceptions\BusinessException
* @throws \KuMEX\SDK\Exceptions\HttpException
Expand Down Expand Up @@ -151,4 +151,32 @@ public function getKLines($symbol, $from, $to, $granularity)
);
return $response->getApiData();
}

/**
* Get the depth20 of level2.
* @param string $symbol
* @return mixed
* @throws \KuMEX\SDK\Exceptions\BusinessException
* @throws \KuMEX\SDK\Exceptions\HttpException
* @throws \KuMEX\SDK\Exceptions\InvalidApiUriException
*/
public function getLevel2Depth20($symbol)
{
$response = $this->call(Request::METHOD_GET, '/api/v1/level2/depth20', ['symbol' => $symbol]);
return $response->getApiData();
}

/**
* Get the depth100 of level2.
* @param string $symbol
* @return mixed
* @throws \KuMEX\SDK\Exceptions\BusinessException
* @throws \KuMEX\SDK\Exceptions\HttpException
* @throws \KuMEX\SDK\Exceptions\InvalidApiUriException
*/
public function getLevel2Depth100($symbol)
{
$response = $this->call(Request::METHOD_GET, '/api/v1/level2/depth100', ['symbol' => $symbol]);
return $response->getApiData();
}
}
43 changes: 27 additions & 16 deletions tests/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace KuMEX\SDK\Tests;

use KuMEX\SDK\ApiCode;
use KuMEX\SDK\Exceptions\BusinessException;
use KuMEX\SDK\PrivateApi\Account;

class AccountTest extends TestCase
{
protected $apiClass = Account::class;
protected $apiClass = Account::class;
protected $apiWithAuth = true;

/**
Expand Down Expand Up @@ -53,12 +52,12 @@ public function testGetTransactionHistory(Account $api)
}

/**
* @deprecated
* @dataProvider apiProvider
* @param Account $api
* @throws BusinessException
* @throws \KuMEX\SDK\Exceptions\HttpException
* @throws \KuMEX\SDK\Exceptions\InvalidApiUriException
* @deprecated
* @dataProvider apiProvider
*/
// public function testTransferIn(Account $api)
// {
Expand All @@ -79,8 +78,8 @@ public function testGetTransactionHistory(Account $api)
*/
public function testTransferOut(Account $api)
{
$bizNo = rand(1, 9999);
$amount = 0.1;
$bizNo = rand(1, 9999);
$amount = 0.1;
$accounts = $api->transferOut($bizNo, $amount);
$this->assertInternalType('array', $accounts);
if (isset($accounts['applyId'])) {
Expand Down Expand Up @@ -133,7 +132,7 @@ public function testGetTransferList(Account $api)
private function getTransferId($api)
{
$bizNo = '10000000001';
$amount = 0.1;
$amount = 0.1;
$accounts = $api->transferOut($bizNo, $amount);
$this->assertInternalType('array', $accounts);
return $accounts['applyId'];
Expand All @@ -149,14 +148,26 @@ private function getTransferId($api)
*/
public function testTransferOutV2(Account $api)
{
$bizNo = rand(1, 9999);
$amount = 0.1;
$currency = 'XBT';
$accounts = $api->transferOutV2($bizNo, $amount, $currency);
$this->assertInternalType('array', $accounts);
if (isset($accounts['applyId'])) {
$this->assertArrayHasKey('applyId', $accounts);
}
}
$bizNo = uniqid('t_', false);
$amount = 0.01;
$currency = 'USDT';
$data = $api->transferOutV2($bizNo, $amount, $currency);

$this->assertInternalType('array', $data);

$this->assertArrayHasKey('applyId', $data);
$this->assertArrayHasKey('bizNo', $data);
$this->assertArrayHasKey('payAccountType', $data);
$this->assertArrayHasKey('payTag', $data);
$this->assertArrayHasKey('remark', $data);
$this->assertArrayHasKey('recAccountType', $data);
$this->assertArrayHasKey('recTag', $data);
$this->assertArrayHasKey('recRemark', $data);
$this->assertArrayHasKey('recSystem', $data);
$this->assertArrayHasKey('status', $data);
$this->assertArrayHasKey('currency', $data);
$this->assertArrayHasKey('amount', $data);
$this->assertArrayHasKey('fee', $data);
$this->assertArrayHasKey('sn', $data);
}
}
129 changes: 108 additions & 21 deletions tests/ContractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace KuMEX\SDK\Tests;

use \KuMEX\SDK\PublicApi\Contract;
use KuMEX\SDK\PublicApi\Contract;


class ContractTest extends TestCase
Expand All @@ -16,8 +16,7 @@ class ContractTest extends TestCase
protected $apiWithAuth = false;

/**
*
* @depends testGetList
* @dataProvider apiProvider
* @param Contract $api
* @throws \KuMEX\SDK\Exceptions\BusinessException
* @throws \KuMEX\SDK\Exceptions\HttpException
Expand All @@ -27,19 +26,65 @@ public function testGetList(Contract $api)
{
$data = $api->getList();
$this->assertInternalType('array', $data);
$this->assertArrayHasKey('currency', $data);
$this->assertArrayHasKey('status', $data);
$this->assertArrayHasKey('address', $data);
$this->assertArrayHasKey('isInner', $data);
$this->assertArrayHasKey('amount', $data);
$this->assertArrayHasKey('fee', $data);
$this->assertArrayHasKey('walletTxId', $data);
$this->assertArrayHasKey('createdAt', $data);

foreach ($data as $item) {
$this->assertInternalType('array', $item);

$this->assertArrayHasKey('symbol', $item);
$this->assertArrayHasKey('rootSymbol', $item);
$this->assertArrayHasKey('type', $item);
$this->assertArrayHasKey('firstOpenDate', $item);
$this->assertArrayHasKey('expireDate', $item);
$this->assertArrayHasKey('settleDate', $item);
$this->assertArrayHasKey('baseCurrency', $item);
$this->assertArrayHasKey('quoteCurrency', $item);
$this->assertArrayHasKey('settleCurrency', $item);
$this->assertArrayHasKey('maxOrderQty', $item);
$this->assertArrayHasKey('maxPrice', $item);
$this->assertArrayHasKey('lotSize', $item);
$this->assertArrayHasKey('tickSize', $item);
$this->assertArrayHasKey('indexPriceTickSize', $item);
$this->assertArrayHasKey('multiplier', $item);
$this->assertArrayHasKey('initialMargin', $item);
$this->assertArrayHasKey('maintainMargin', $item);
$this->assertArrayHasKey('maxRiskLimit', $item);
$this->assertArrayHasKey('minRiskLimit', $item);
$this->assertArrayHasKey('riskStep', $item);
$this->assertArrayHasKey('makerFeeRate', $item);
$this->assertArrayHasKey('takerFeeRate', $item);
$this->assertArrayHasKey('takerFixFee', $item);
$this->assertArrayHasKey('makerFixFee', $item);
$this->assertArrayHasKey('settlementFee', $item);
$this->assertArrayHasKey('isDeleverage', $item);
$this->assertArrayHasKey('isQuanto', $item);
$this->assertArrayHasKey('isInverse', $item);
$this->assertArrayHasKey('markMethod', $item);
$this->assertArrayHasKey('fairMethod', $item);
$this->assertArrayHasKey('fundingBaseSymbol', $item);
$this->assertArrayHasKey('fundingQuoteSymbol', $item);
$this->assertArrayHasKey('fundingRateSymbol', $item);
$this->assertArrayHasKey('indexSymbol', $item);
$this->assertArrayHasKey('settlementSymbol', $item);
$this->assertArrayHasKey('status', $item);
$this->assertArrayHasKey('fundingFeeRate', $item);
$this->assertArrayHasKey('predictedFundingFeeRate', $item);
$this->assertArrayHasKey('openInterest', $item);
$this->assertArrayHasKey('turnoverOf24h', $item);
$this->assertArrayHasKey('volumeOf24h', $item);
$this->assertArrayHasKey('markPrice', $item);
$this->assertArrayHasKey('indexPrice', $item);
$this->assertArrayHasKey('lastTradePrice', $item);
$this->assertArrayHasKey('nextFundingRateTime', $item);
$this->assertArrayHasKey('maxLeverage', $item);
$this->assertArrayHasKey('lowPrice', $item);
$this->assertArrayHasKey('highPrice', $item);
$this->assertArrayHasKey('priceChgPct', $item);
$this->assertArrayHasKey('priceChg', $item);
}
}

/**
*
* @depends testGetDetail
* @dataProvider apiProvider
* @param Contract $api
* @throws \KuMEX\SDK\Exceptions\BusinessException
* @throws \KuMEX\SDK\Exceptions\HttpException
Expand All @@ -49,14 +94,56 @@ public function testGetDetail(Contract $api)
{
$data = $api->getDetail('XBTUSDM');
$this->assertInternalType('array', $data);
$this->assertArrayHasKey('currency', $data);

$this->assertArrayHasKey('symbol', $data);
$this->assertArrayHasKey('rootSymbol', $data);
$this->assertArrayHasKey('type', $data);
$this->assertArrayHasKey('firstOpenDate', $data);
$this->assertArrayHasKey('expireDate', $data);
$this->assertArrayHasKey('settleDate', $data);
$this->assertArrayHasKey('baseCurrency', $data);
$this->assertArrayHasKey('quoteCurrency', $data);
$this->assertArrayHasKey('settleCurrency', $data);
$this->assertArrayHasKey('maxOrderQty', $data);
$this->assertArrayHasKey('maxPrice', $data);
$this->assertArrayHasKey('lotSize', $data);
$this->assertArrayHasKey('tickSize', $data);
$this->assertArrayHasKey('indexPriceTickSize', $data);
$this->assertArrayHasKey('multiplier', $data);
$this->assertArrayHasKey('initialMargin', $data);
$this->assertArrayHasKey('maintainMargin', $data);
$this->assertArrayHasKey('maxRiskLimit', $data);
$this->assertArrayHasKey('minRiskLimit', $data);
$this->assertArrayHasKey('riskStep', $data);
$this->assertArrayHasKey('makerFeeRate', $data);
$this->assertArrayHasKey('takerFeeRate', $data);
$this->assertArrayHasKey('takerFixFee', $data);
$this->assertArrayHasKey('makerFixFee', $data);
$this->assertArrayHasKey('settlementFee', $data);
$this->assertArrayHasKey('isDeleverage', $data);
$this->assertArrayHasKey('isQuanto', $data);
$this->assertArrayHasKey('isInverse', $data);
$this->assertArrayHasKey('markMethod', $data);
$this->assertArrayHasKey('fairMethod', $data);
$this->assertArrayHasKey('fundingBaseSymbol', $data);
$this->assertArrayHasKey('fundingQuoteSymbol', $data);
$this->assertArrayHasKey('fundingRateSymbol', $data);
$this->assertArrayHasKey('indexSymbol', $data);
$this->assertArrayHasKey('settlementSymbol', $data);
$this->assertArrayHasKey('status', $data);
$this->assertArrayHasKey('address', $data);
$this->assertArrayHasKey('isInner', $data);
$this->assertArrayHasKey('amount', $data);
$this->assertArrayHasKey('fee', $data);
$this->assertArrayHasKey('walletTxId', $data);
$this->assertArrayHasKey('createdAt', $data);
$this->assertArrayHasKey('fundingFeeRate', $data);
$this->assertArrayHasKey('predictedFundingFeeRate', $data);
$this->assertArrayHasKey('openInterest', $data);
$this->assertArrayHasKey('turnoverOf24h', $data);
$this->assertArrayHasKey('volumeOf24h', $data);
$this->assertArrayHasKey('markPrice', $data);
$this->assertArrayHasKey('indexPrice', $data);
$this->assertArrayHasKey('lastTradePrice', $data);
$this->assertArrayHasKey('nextFundingRateTime', $data);
$this->assertArrayHasKey('maxLeverage', $data);
$this->assertArrayHasKey('lowPrice', $data);
$this->assertArrayHasKey('highPrice', $data);
$this->assertArrayHasKey('priceChgPct', $data);
$this->assertArrayHasKey('priceChg', $data);
}

}
Loading