Skip to content

Commit

Permalink
Merge pull request #46 from hhxsv5/master
Browse files Browse the repository at this point in the history
Add some APIs
  • Loading branch information
hhxsv5 authored Apr 28, 2019
2 parents beebef2 + 5fdc2fb commit 40abc58
Show file tree
Hide file tree
Showing 9 changed files with 292 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ go(function () {
| KuCoin\SDK\PrivateApi\Account::getLedgers() | YES | https://docs.kucoin.com/#get-account-ledgers |
| KuCoin\SDK\PrivateApi\Account::getHolds() | YES | https://docs.kucoin.com/#get-holds |
| KuCoin\SDK\PrivateApi\Account::innerTransfer() | YES | https://docs.kucoin.com/#inner-transfer |
| KuCoin\SDK\PrivateApi\Account::getSubAccountUsers() | YES | https://docs.kucoin.com/#get-user-info-of-all-sub-accounts |
| KuCoin\SDK\PrivateApi\Account::getSubAccountDetail() | YES | https://docs.kucoin.com/#get-account-balance-of-a-sub-account |
| KuCoin\SDK\PrivateApi\Account::getSubAccountList() | YES | https://docs.kucoin.com/#get-the-aggregated-balance-of-all-sub-accounts-of-the-current-user |
| KuCoin\SDK\PrivateApi\Account::subTransfer() | YES | https://docs.kucoin.com/#transfer-between-master-account-and-sub-account |

</details>

Expand All @@ -149,6 +153,7 @@ go(function () {
| KuCoin\SDK\PrivateApi\Deposit::createAddress() | YES | https://docs.kucoin.com/#create-deposit-address |
| KuCoin\SDK\PrivateApi\Deposit::getAddress() | YES | https://docs.kucoin.com/#get-deposit-address |
| KuCoin\SDK\PrivateApi\Deposit::getDeposits() | YES | https://docs.kucoin.com/#get-deposit-list |
| KuCoin\SDK\PrivateApi\Deposit::getV1Deposits() | YES | https://docs.kucoin.com/#get-v1-historical-deposits-list |

</details>

Expand All @@ -171,6 +176,7 @@ go(function () {
| KuCoin\SDK\PrivateApi\Order::cancel() | YES | https://docs.kucoin.com/#cancel-an-order |
| KuCoin\SDK\PrivateApi\Order::cancelAll() | YES | https://docs.kucoin.com/#cancel-all-orders |
| KuCoin\SDK\PrivateApi\Order::getList() | YES | https://docs.kucoin.com/#list-orders |
| KuCoin\SDK\PrivateApi\Order::getV1List() | YES | https://docs.kucoin.com/#get-v1-historical-orders-list |
| KuCoin\SDK\PrivateApi\Order::getDetail() | YES | https://docs.kucoin.com/#get-an-order |
| KuCoin\SDK\PrivateApi\Order::getRecentList() | YES | https://docs.kucoin.com/#recent-orders |

Expand All @@ -197,6 +203,7 @@ go(function () {
| -------- | -------- | -------- |
| KuCoin\SDK\PrivateApi\Withdrawal::getQuotas() | YES | https://docs.kucoin.com/#get-withdrawal-quotas |
| KuCoin\SDK\PrivateApi\Withdrawal::getList() | YES | https://docs.kucoin.com/#get-withdrawals-list |
| KuCoin\SDK\PrivateApi\Withdrawal::getV1List() | YES | https://docs.kucoin.com/#get-v1-historical-withdrawals-list |
| KuCoin\SDK\PrivateApi\Withdrawal::apply() | YES | https://docs.kucoin.com/#apply-withdraw |
| KuCoin\SDK\PrivateApi\Withdrawal::cancel() | YES | https://docs.kucoin.com/#cancel-withdrawal |

Expand Down
54 changes: 54 additions & 0 deletions src/PrivateApi/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,58 @@ public function innerTransfer($clientOid, $payAccountId, $recAccountId, $amount)
);
return $response->getApiData();
}

/**
* Get user info of all sub-accounts
* @return array
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getSubAccountUsers()
{
$response = $this->call(Request::METHOD_GET, '/api/v1/sub/user');
return $response->getApiData();
}

/**
* Get account balance of a sub-account
* @param string $subUserId
* @return array
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getSubAccountDetail($subUserId)
{
$response = $this->call(Request::METHOD_GET, '/api/v1/sub-accounts/' . $subUserId);
return $response->getApiData();
}

/**
* Get the aggregated balance of all sub-accounts of the current user
* @return array
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getSubAccountList()
{
$response = $this->call(Request::METHOD_GET, '/api/v1/sub-accounts');
return $response->getApiData();
}

/**
* Transfer between master account and sub-account
* @param array $params
* @return array
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function subTransfer(array $params)
{
$response = $this->call(Request::METHOD_POST, '/api/v1/accounts/sub-transfer', $params);
return $response->getApiData();
}
}
15 changes: 15 additions & 0 deletions src/PrivateApi/Deposit.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,19 @@ public function getDeposits(array $params, array $pagination = [])
$response = $this->call(Request::METHOD_GET, '/api/v1/deposits', $params + $pagination);
return $response->getApiData();
}

/**
* Get v1 historical deposits list
* @param array $params
* @param array $pagination
* @return array
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getV1Deposits(array $params, array $pagination = [])
{
$response = $this->call(Request::METHOD_GET, '/api/v1/hist-deposits', $params + $pagination);
return $response->getApiData();
}
}
15 changes: 15 additions & 0 deletions src/PrivateApi/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ public function getList(array $params = [], array $pagination = [])
return $response->getApiData();
}

/**
* Get v1 historical orders list
* @param array $params
* @param array $pagination
* @return array
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getV1List(array $params = [], array $pagination = [])
{
$response = $this->call(Request::METHOD_GET, '/api/v1/hist-orders', $params + $pagination);
return $response->getApiData();
}

/**
* Get an order
* @param $orderId
Expand Down
15 changes: 15 additions & 0 deletions src/PrivateApi/Withdrawal.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ public function getList(array $params, array $pagination = [])
return $response->getApiData();
}

/**
* Get v1 historical withdrawals list
* @param array $params
* @param array $pagination
* @return array
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getV1List(array $params, array $pagination = [])
{
$response = $this->call(Request::METHOD_GET, '/api/v1/hist-withdrawals', $params + $pagination);
return $response->getApiData();
}

/**
* Apply a withdrawal
* @param array $params
Expand Down
111 changes: 110 additions & 1 deletion tests/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ public function testInnerTransfer(Account $api)

/**
* @dataProvider apiProvider
* @depends testGetMainList
* @param Account $api
* @throws BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
Expand All @@ -176,4 +175,114 @@ public function testGetHolds(Account $api)
}
}

/**
* @dataProvider apiProvider
* @param Account $api
* @return array
* @throws BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetSubAccountUsers(Account $api)
{
$users = $api->getSubAccountUsers();
$this->assertInternalType('array', $users);
foreach ($users as $item) {
$this->assertArrayHasKey('userId', $item);
$this->assertArrayHasKey('subName', $item);
$this->assertArrayHasKey('remarks', $item);
}
return $users;
}

/**
* @dataProvider apiProvider
* @param Account $api
* @throws BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetSubAccountList(Account $api)
{
$accounts = $api->getSubAccountList();
$this->assertInternalType('array', $accounts);
foreach ($accounts as $account) {
$this->assertInternalType('array', $account);
$this->assertArrayHasKey('subUserId', $account);
$this->assertArrayHasKey('subName', $account);
$this->assertArrayHasKey('mainAccounts', $account);
$this->assertArrayHasKey('tradeAccounts', $account);
$this->assertInternalType('array', $account['mainAccounts']);
$this->assertInternalType('array', $account['tradeAccounts']);
foreach ($account['mainAccounts'] as $item) {
$this->assertArrayHasKey('currency', $item);
$this->assertArrayHasKey('balance', $item);
$this->assertArrayHasKey('available', $item);
$this->assertArrayHasKey('holds', $item);
}
foreach ($account['tradeAccounts'] as $item) {
$this->assertArrayHasKey('currency', $item);
$this->assertArrayHasKey('balance', $item);
$this->assertArrayHasKey('available', $item);
$this->assertArrayHasKey('holds', $item);
}
}
}

/**
* @dataProvider apiProvider
* @param Account $api
* @throws BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetSubAccountDetail(Account $api)
{
$users = $api->getSubAccountUsers();
if (empty($users)) {
return;
}
$account = $api->getSubAccountDetail($users[0]['userId']);
$this->assertInternalType('array', $account);
$this->assertArrayHasKey('subUserId', $account);
$this->assertArrayHasKey('subName', $account);
$this->assertArrayHasKey('mainAccounts', $account);
$this->assertArrayHasKey('tradeAccounts', $account);
$this->assertInternalType('array', $account['mainAccounts']);
$this->assertInternalType('array', $account['tradeAccounts']);
foreach ($account['mainAccounts'] as $item) {
$this->assertArrayHasKey('currency', $item);
$this->assertArrayHasKey('balance', $item);
$this->assertArrayHasKey('available', $item);
$this->assertArrayHasKey('holds', $item);
}
foreach ($account['tradeAccounts'] as $item) {
$this->assertArrayHasKey('currency', $item);
$this->assertArrayHasKey('balance', $item);
$this->assertArrayHasKey('available', $item);
$this->assertArrayHasKey('holds', $item);
}
}

/**
* @dataProvider apiProvider
* @param Account $api
* @throws BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testSubTransfer(Account $api)
{
$transfer = [
'clientOid' => uniqid(),
'amount' => 1,
'direction' => 'OUT',
'currency' => 'KCS',
'subUserId' => '5cc5b31c38300c336230d071',
];
$result = $api->subTransfer($transfer);
$this->assertInternalType('array', $result);
$this->assertArrayHasKey('orderId', $result);
}

}
22 changes: 22 additions & 0 deletions tests/DepositTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,26 @@ public function testGetDeposits(Deposit $api)
$this->assertArrayHasKey('updatedAt', $item);
}
}

/**
* @dataProvider apiProvider
* @param Deposit $api
* @return array|string
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetV1Deposits(Deposit $api)
{
$data = $api->getV1Deposits(['currency' => 'ETH'], ['currentPage' => 1, 'pageSize' => 10]);
$this->assertPagination($data);
foreach ($data['items'] as $item) {
$this->assertArrayHasKey('amount', $item);
$this->assertArrayHasKey('currency', $item);
$this->assertArrayHasKey('isInner', $item);
$this->assertArrayHasKey('walletTxId', $item);
$this->assertArrayHasKey('createAt', $item);
$this->assertArrayHasKey('status', $item);
}
}
}
23 changes: 23 additions & 0 deletions tests/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,29 @@ public function testGetList(Order $api)
}
}

/**
* @dataProvider apiProvider
* @param Order $api
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetV1List(Order $api)
{
$data = $api->getV1List(['symbol' => 'BTC-USDT'], ['currentPage' => 1, 'pageSize' => 10]);
$this->assertPagination($data);
foreach ($data['items'] as $item) {
$this->assertArrayHasKey('symbol', $item);
$this->assertArrayHasKey('createdAt', $item);
$this->assertArrayHasKey('amount', $item);
$this->assertArrayHasKey('side', $item);
$this->assertArrayHasKey('dealValue', $item);
$this->assertArrayHasKey('fee', $item);
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('dealPrice', $item);
}
}

/**
* @dataProvider apiProvider
* @param Order $api
Expand Down
32 changes: 31 additions & 1 deletion tests/WithdrawalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,37 @@ public function testGetList(Withdrawal $api)
$this->assertArrayHasKey('createdAt', $item);
$this->assertArrayHasKey('updatedAt', $item);
}
return $data['items'];
}

/**
* @dataProvider apiProvider
* @param Withdrawal $api
* @return array
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetV1List(Withdrawal $api)
{
$params = [
'currency' => 'BTC',
];
$pagination = [
'currentPage' => 1,
'pageSize' => 10,
];
$data = $api->getV1List($params, $pagination);
$this->assertPagination($data);
foreach ($data['items'] as $item) {
$this->assertInternalType('array', $item);
$this->assertArrayHasKey('amount', $item);
$this->assertArrayHasKey('address', $item);
$this->assertArrayHasKey('currency', $item);
$this->assertArrayHasKey('isInner', $item);
$this->assertArrayHasKey('walletTxId', $item);
$this->assertArrayHasKey('createAt', $item);
$this->assertArrayHasKey('status', $item);
}
}

/**
Expand Down

0 comments on commit 40abc58

Please sign in to comment.