From a299ea474ef6e0d906324a07934d76257267c814 Mon Sep 17 00:00:00 2001 From: Artisan Date: Mon, 5 Jun 2023 18:59:16 +0800 Subject: [PATCH 1/7] Add account related interface --- src/PrivateApi/Account.php | 99 +++++++++++++++++- tests/PrivateApi/AccountTest.php | 168 +++++++++++++++++++++++++++++++ 2 files changed, 266 insertions(+), 1 deletion(-) diff --git a/src/PrivateApi/Account.php b/src/PrivateApi/Account.php index e6e0c6b..2174d6d 100644 --- a/src/PrivateApi/Account.php +++ b/src/PrivateApi/Account.php @@ -216,4 +216,101 @@ public function getLedgersV2(array $params = [], array $pagination = []) $response = $this->call(Request::METHOD_GET, '/api/v1/accounts/ledgers', $params + $pagination); return $response->getApiData(); } -} \ No newline at end of file + /** + * Get sub user + * @param array $pagination + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getSubUserV2(array $pagination = []) + { + $response = $this->call(Request::METHOD_GET, '/api/v2/sub/user', $pagination); + return $response->getApiData(); + } + + /** + * Get account description + * @param array $pagination + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getUserinfoV2() + { + $response = $this->call(Request::METHOD_GET, '/api/v2/user-info'); + return $response->getApiData(); + } + + /** + * Create sub user + * @param array $params + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function createSubUserV2(array $params = []) + { + $response = $this->call(Request::METHOD_POST, '/api/v2/sub/user/created', $params); + return $response->getApiData(); + } + + /** + * Create sub account api key + * @param array $params + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function createSubUserApiKey(array $params = []) + { + $response = $this->call(Request::METHOD_POST, '/api/v1/sub/api-key', $params); + return $response->getApiData(); + } + + /** + * Get sub user api key + * @param array $params + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getSubUserApiKey(array $params = []) + { + $response = $this->call(Request::METHOD_GET, '/api/v1/sub/api-key', $params); + return $response->getApiData(); + } + + /** + * Update sub user api key + * @param array $params + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function updateSubUserApiKey(array $params = []) + { + $response = $this->call(Request::METHOD_POST, '/api/v1/sub/api-key/update', $params); + return $response->getApiData(); + } + + /** + * Delete sub user api key + * @param array $params + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function deleteSubUserApiKey(array $params = []) + { + $response = $this->call(Request::METHOD_DELETE, '/api/v1/sub/api-key', $params); + return $response->getApiData(); + } +} diff --git a/tests/PrivateApi/AccountTest.php b/tests/PrivateApi/AccountTest.php index 5035e27..63d7d23 100644 --- a/tests/PrivateApi/AccountTest.php +++ b/tests/PrivateApi/AccountTest.php @@ -346,4 +346,172 @@ public function testGetLedgersV2(Account $api) $this->assertArrayHasKey('context', $item); } } + + /** + * @dataProvider apiProvider + * @param Account $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetSubUserV2(Account $api) + { + $data = $api->getSubUserV2(['currentPage' => 1, 'pageSize' => 10]); + $this->assertPagination($data); + foreach ($data['items'] as $item) { + $this->assertArrayHasKey('userId', $item); + $this->assertArrayHasKey('uid', $item); + $this->assertArrayHasKey('subName', $item); + $this->assertArrayHasKey('status', $item); + $this->assertArrayHasKey('type', $item); + $this->assertArrayHasKey('access', $item); + $this->assertArrayHasKey('createdAt', $item); + $this->assertArrayHasKey('remarks', $item); + } + } + + /** + * @dataProvider apiProvider + * @param Account $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetUserinfoV2(Account $api) + { + $data = $api->getUserinfoV2(); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('level', $data); + $this->assertArrayHasKey('subQuantity', $data); + $this->assertArrayHasKey('spotSubQuantity', $data); + $this->assertArrayHasKey('marginSubQuantity', $data); + $this->assertArrayHasKey('futuresSubQuantity', $data); + $this->assertArrayHasKey('maxSubQuantity', $data); + $this->assertArrayHasKey('maxDefaultSubQuantity', $data); + $this->assertArrayHasKey('maxSpotSubQuantity', $data); + $this->assertArrayHasKey('maxMarginSubQuantity', $data); + $this->assertArrayHasKey('maxFuturesSubQuantity', $data); + } + + /** + * @dataProvider apiProvider + * @param Account $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testCreateSubUserV2(Account $api) + { + $params = [ + 'password' => 'phpunit123', + 'remarks' => 'phpunit123', + 'subName' => 'phpunit123', + 'access' => 'Futures,Spot,Margin', + ]; + $result = $api->createSubUserV2($params); + $this->assertInternalType('array', $result); + $this->assertArrayHasKey('uid', $result); + $this->assertArrayHasKey('subName', $result); + $this->assertArrayHasKey('access', $result); + $this->assertArrayHasKey('remarks', $result); + } + + /** + * @dataProvider apiProvider + * @param Account $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testCreateSubUserApiKey(Account $api) + { + $params = [ + 'subName' => 'testsubtest', + 'passphrase' => 'createSubAccountApi', + 'remark' => 'createSubAccountApi', + 'permission' => 'General,Trade', + 'ipWhitelist' => '221.236.30.91', + 'expire' => '30', + ]; + $result = $api->createSubUserApiKey($params); + $this->assertInternalType('array', $result); + $this->assertArrayHasKey('apiKey', $result); + $this->assertArrayHasKey('apiSecret', $result); + $this->assertArrayHasKey('subName', $result); + $this->assertArrayHasKey('passphrase', $result); + $this->assertArrayHasKey('remark', $result); + $this->assertArrayHasKey('permission', $result); + $this->assertArrayHasKey('ipWhitelist', $result); + $this->assertArrayHasKey('createdAt', $result); + } + + /** + * @dataProvider apiProvider + * @param Account $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetSubUserApiKey(Account $api) + { + $params = [ + 'subName' => 'testsubtest', + 'apiKey' => '647da6a7bfe99b00011961db', + ]; + $result = $api->getSubUserApiKey($params); + foreach ($result as $item) { + $this->assertInternalType('array', $item); + $this->assertArrayHasKey('apiKey', $item); + $this->assertArrayHasKey('subName', $item); + $this->assertArrayHasKey('remark', $item); + $this->assertArrayHasKey('permission', $item); + $this->assertArrayHasKey('ipWhitelist', $item); + $this->assertArrayHasKey('createdAt', $item); + } + } + + /** + * @dataProvider apiProvider + * @param Account $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testUpdateSubUserApiKey(Account $api) + { + $params = [ + 'subName' => 'testsubtest', + 'apiKey' => '647da940d35150000196a56c', + 'passphrase' => 'createSubAccountApi', + 'permission' => 'General,Trade', + 'ipWhitelist' => '221.236.30.91,221.236.30.92', + 'expire' => '90', + ]; + $result = $api->updateSubUserApiKey($params); + $this->assertInternalType('array', $result); + $this->assertArrayHasKey('apiKey', $result); + $this->assertArrayHasKey('subName', $result); + $this->assertArrayHasKey('permission', $result); + $this->assertArrayHasKey('ipWhitelist', $result); + } + + /** + * @dataProvider apiProvider + * @param Account $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testDeleteSubUserApiKey(Account $api) + { + $params = [ + 'subName' => 'testsubtest', + 'apiKey' => '647da940d35150000196a56c', + 'passphrase' => 'createSubAccountApi', + ]; + $result = $api->deleteSubUserApiKey($params); + $this->assertInternalType('array', $result); + $this->assertArrayHasKey('apiKey', $result); + $this->assertArrayHasKey('subName', $result); + } } From e423908447c44d0e0656cda5d3a27694a430cda6 Mon Sep 17 00:00:00 2001 From: Artisan Date: Tue, 13 Jun 2023 17:58:19 +0800 Subject: [PATCH 2/7] Spot and Isolated Margin Interface --- README.md | 52 +- src/PrivateApi/Account.php | 45 +- src/PrivateApi/IsolatedMargin.php | 127 +++++ src/PrivateApi/Order.php | 280 ++++++++++- src/PublicApi/Symbol.php | 17 +- tests/PrivateApi/AccountTest.php | 101 +++- tests/PrivateApi/IsolatedMarginTest.php | 209 ++++++++ tests/PrivateApi/OrderTest.php | 603 +++++++++++++++++++++++- tests/PublicApi/SymbolTest.php | 34 +- 9 files changed, 1457 insertions(+), 11 deletions(-) create mode 100644 src/PrivateApi/IsolatedMargin.php create mode 100644 tests/PrivateApi/IsolatedMarginTest.php diff --git a/README.md b/README.md index ef25a42..e7a23f6 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,17 @@ go(function () { | KuCoin\SDK\PrivateApi\Account::subTransfer() | YES | `DEPRECATED` https://docs.kucoin.com/#transfer-between-master-account-and-sub-account | | KuCoin\SDK\PrivateApi\Account::subTransferV2() | YES | https://docs.kucoin.com/#transfer-between-master-user-and-sub-user | | KuCoin\SDK\PrivateApi\Account::getLedgersV2() | YES | https://docs.kucoin.com/#get-account-ledgers | - +| KuCoin\SDK\PrivateApi\Account::getLedgersV2() | YES | https://docs.kucoin.com/#get-account-ledgers | +| KuCoin\SDK\PrivateApi\Account::getSubUserV2() | YES | https://docs.kucoin.com/#get-paginated-list-of-sub-accounts | +| KuCoin\SDK\PrivateApi\Account::getUserinfoV2() | YES | https://docs.kucoin.com/#get-account-summary-info-v2 | +| KuCoin\SDK\PrivateApi\Account::createSubUserV2() | YES | https://docs.kucoin.com/#create-sub-account-v2 | +| KuCoin\SDK\PrivateApi\Account::createSubUserApiKey() | YES | https://docs.kucoin.com/#create-spot-apis-for-sub-account | +| KuCoin\SDK\PrivateApi\Account::getSubUserApiKey() | YES | https://docs.kucoin.com/#get-sub-account-spot-api-list | +| KuCoin\SDK\PrivateApi\Account::updateSubUserApiKey() | YES | https://docs.kucoin.com/#modify-sub-account-spot-apis | +| KuCoin\SDK\PrivateApi\Account::deleteSubUserApiKey() | YES | https://docs.kucoin.com/#delete-sub-account-spot-apis | +| KuCoin\SDK\PrivateApi\Account::getSubAccountListV2() | YES | https://docs.kucoin.com/#get-paginated-sub-account-information | +| KuCoin\SDK\PrivateApi\Account::getAccountTransferable() | YES | https://docs.kucoin.com/#get-the-transferable | +| KuCoin\SDK\PrivateApi\Account::getHfLedgersV2() | YES | https://docs.kucoin.com/spot-hf/#account-ledger-in-high-frequency-trading-accounts |
@@ -246,7 +256,7 @@ go(function () { KuCoin\SDK\PrivateApi\Order | API | Authentication | Description | -| -------- | -------- | -------- | +| -------- | -------- | ------ | | KuCoin\SDK\PrivateApi\Order::create() | YES | https://docs.kucoin.com/#place-a-new-order | | KuCoin\SDK\PrivateApi\Order::createMulti() | YES | https://docs.kucoin.com/#place-bulk-orders | | KuCoin\SDK\PrivateApi\Order::cancel() | YES | https://docs.kucoin.com/#cancel-an-order | @@ -258,6 +268,25 @@ go(function () { | KuCoin\SDK\PrivateApi\Order::createMarginOrder()| YES | https://docs.kucoin.com/#place-a-margin-order | | KuCoin\SDK\PrivateApi\Order::cancelByClientOid() | YES | https://docs.kucoin.com/#cancel-single-order-by-clientoid | | KuCoin\SDK\PrivateApi\Order::getDetailByClientOid() | YES | https://docs.kucoin.com/#get-single-active-order-by-clientoid| +| KuCoin\SDK\PrivateApi\Order::hfCreate() | YES | https://docs.kucoin.com/spot-hf/#place-hf-order| +| KuCoin\SDK\PrivateApi\Order::hfSyncCreate() | YES | https://docs.kucoin.com/spot-hf/#sync-place-hf-order| +| KuCoin\SDK\PrivateApi\Order::hfCreateMulti() | YES | https://docs.kucoin.com/spot-hf/#place-multiple-hf-orders| +| KuCoin\SDK\PrivateApi\Order::hfSyncCreateMulti() | YES | https://docs.kucoin.com/spot-hf/#sync-place-multiple-hf-orders| +| KuCoin\SDK\PrivateApi\Order::hfModify() | YES | https://docs.kucoin.com/spot-hf/#modify-order| +| KuCoin\SDK\PrivateApi\Order::hfCancel() | YES | https://docs.kucoin.com/spot-hf/#cancel-orders-by-orderid| +| KuCoin\SDK\PrivateApi\Order::hfSyncCancel() | YES | https://docs.kucoin.com/spot-hf/#sync-cancel-orders-by-orderid| +| KuCoin\SDK\PrivateApi\Order::hfCancelByClientOid() | YES | https://docs.kucoin.com/spot-hf/#cancel-order-by-clientoid| +| KuCoin\SDK\PrivateApi\Order::hfSyncCancelByClientOid() | YES | https://docs.kucoin.com/spot-hf/#sync-cancel-orders-by-clientoid| +| KuCoin\SDK\PrivateApi\Order::hfSyncCancelSize() | YES | https://docs.kucoin.com/spot-hf/#cancel-specified-number-of-orders-by-orderid| +| KuCoin\SDK\PrivateApi\Order::hfSyncCancelAll() | YES | https://docs.kucoin.com/spot-hf/#cancel-all-hf-orders-by-symbol| +| KuCoin\SDK\PrivateApi\Order::getActiveOrderList() | YES | https://docs.kucoin.com/spot-hf/#obtain-list-of-active-hf-orders| +| KuCoin\SDK\PrivateApi\Order::getActiveSymbols() | YES | https://docs.kucoin.com/spot-hf/#obtain-list-of-symbol-with-active-hf-orders| +| KuCoin\SDK\PrivateApi\Order::getDoneOrderList() | YES | https://docs.kucoin.com/spot-hf/#obtain-list-of-filled-hf-orders| +| KuCoin\SDK\PrivateApi\Order::getHfDetail() | YES | https://docs.kucoin.com/spot-hf/#details-of-a-single-hf-order| +| KuCoin\SDK\PrivateApi\Order::getHfDetailByClientOid() | YES | https://docs.kucoin.com/spot-hf/#obtain-details-of-a-single-hf-order-using-clientoid| +| KuCoin\SDK\PrivateApi\Order::hfAutoCancel() | YES | https://docs.kucoin.com/spot-hf/#hf-auto-cancel-setting| +| KuCoin\SDK\PrivateApi\Order::getHfAutoCancel() | YES | https://docs.kucoin.com/spot-hf/#hf-auto-cancel-order-setting-query| +| KuCoin\SDK\PrivateApi\Order::getHfFills() | YES | https://docs.kucoin.com/spot-hf/#hf-transaction-records|
@@ -330,7 +359,7 @@ go(function () { | API | Authentication | Description | | -------- | -------- | -------- | -| KuCoin\SDK\PublicApi\Symbol::getList() | NO | https://docs.kucoin.com/#get-symbols-list | +| KuCoin\SDK\PublicApi\Symbol::getList() | NO | `DEPRECATED` https://docs.kucoin.com/#get-symbols-list-deprecated | | KuCoin\SDK\PublicApi\Symbol::getTicker() | NO | https://docs.kucoin.com/#get-ticker | | KuCoin\SDK\PublicApi\Symbol::getAllTickers() | NO | https://docs.kucoin.com/#get-all-tickers | | KuCoin\SDK\PublicApi\Symbol::getAggregatedPartOrderBook() | NO | https://docs.kucoin.com/#get-part-order-book-aggregated | @@ -338,7 +367,7 @@ go(function () { | KuCoin\SDK\PublicApi\Symbol::getKLines() | NO | https://docs.kucoin.com/#get-klines | | KuCoin\SDK\PublicApi\Symbol::get24HStats() | NO | https://docs.kucoin.com/#get-24hr-stats | | KuCoin\SDK\PublicApi\Symbol::getMarkets() | NO | https://docs.kucoin.com/#get-market-list | - +| KuCoin\SDK\PublicApi\Symbol::getListV2() | NO | https://docs.kucoin.com/#get-symbols-list |
@@ -367,6 +396,21 @@ go(function () { | KuCoin\SDK\PrivateApi\Margin::getTradeLast() | YES | https://docs.kucoin.com/#margin-trade-data |
+
+KuCoin\SDK\PrivateApi\IsolatedMargin + +| API | Authentication | Description | +| -------- | -------- | -------- | +| KuCoin\SDK\PrivateApi\IsolatedMargin::getSymbols() | YES | https://docs.kucoin.com/#query-isolated-margin-trading-pair-configuration | +| KuCoin\SDK\PrivateApi\IsolatedMargin::getAccountList() | YES | https://docs.kucoin.com/#query-isolated-margin-account-info | +| KuCoin\SDK\PrivateApi\IsolatedMargin::getAccountDetail() | YES | https://docs.kucoin.com/#query-single-isolated-margin-account-info | +| KuCoin\SDK\PrivateApi\IsolatedMargin::borrow() | YES | https://docs.kucoin.com/#isolated-margin-borrowing | +| KuCoin\SDK\PrivateApi\IsolatedMargin::getOutstanding() | YES | https://docs.kucoin.com/#query-outstanding-repayment-records | +| KuCoin\SDK\PrivateApi\IsolatedMargin::getRepaid() | YES | https://docs.kucoin.com/#query-repayment-records | +| KuCoin\SDK\PrivateApi\IsolatedMargin::repayAll() | YES | https://docs.kucoin.com/#quick-repayment | +| KuCoin\SDK\PrivateApi\IsolatedMargin::repaySingle() | YES | https://docs.kucoin.com/#single-repayment | +
+
KuCoin\SDK\PublicApi\Time diff --git a/src/PrivateApi/Account.php b/src/PrivateApi/Account.php index 2174d6d..2e51724 100644 --- a/src/PrivateApi/Account.php +++ b/src/PrivateApi/Account.php @@ -259,7 +259,7 @@ public function createSubUserV2(array $params = []) } /** - * Create sub account api key + * Create sub user api key * @param array $params * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -313,4 +313,47 @@ public function deleteSubUserApiKey(array $params = []) $response = $this->call(Request::METHOD_DELETE, '/api/v1/sub/api-key', $params); return $response->getApiData(); } + + /** + * Get the aggregated balance of all sub-accounts of the current user for V2 version + * @param array $params + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getSubAccountListV2(array $params = []) + { + $response = $this->call(Request::METHOD_GET, '/api/v2/sub-accounts', $params); + return $response->getApiData(); + } + + /** + * Get transferable funds under the specified account and currency + * @param array $params + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getAccountTransferable(array $params = []) + { + $response = $this->call(Request::METHOD_GET, '/api/v1/accounts/transferable', $params); + return $response->getApiData(); + } + + /** + * Get account ledgers for high-frequency + * @param array $params + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getHfLedgersV2(array $params = []) + { + $response = $this->call(Request::METHOD_GET, '/api/v1/hf/accounts/ledgers', $params); + return $response->getApiData(); + } + } diff --git a/src/PrivateApi/IsolatedMargin.php b/src/PrivateApi/IsolatedMargin.php new file mode 100644 index 0000000..a107f71 --- /dev/null +++ b/src/PrivateApi/IsolatedMargin.php @@ -0,0 +1,127 @@ +call(Request::METHOD_GET, '/api/v1/isolated/symbols'); + return $response->getApiData(); + } + + /** + * Get all isolated margin accounts of the current user + * @param array $params + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getAccountList(array $params) + { + $response = $this->call(Request::METHOD_GET, '/api/v1/isolated/accounts', $params); + return $response->getApiData(); + } + + /** + * Get the info on a single isolated margin account of the current user + * @param string $symbol + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getAccountDetail($symbol) + { + $response = $this->call(Request::METHOD_GET, '/api/v1/isolated/account/' . $symbol); + return $response->getApiData(); + } + + /** + * Initiates isolated margin borrowing. + * @param array $params + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function borrow(array $params) + { + $response = $this->call(Request::METHOD_POST, '/api/v1/isolated/borrow', $params); + return $response->getApiData(); + } + + + /** + * Get outstanding repayment records of isolated margin + * @param array $params + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getOutstanding(array $params) + { + $response = $this->call(Request::METHOD_GET, '/api/v1/isolated/borrow/outstanding', $params); + return $response->getApiData(); + } + + /** + * Get repayment records of isolated margin positions. + * @param array $params + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getRepaid(array $params) + { + $response = $this->call(Request::METHOD_GET, '/api/v1/isolated/borrow/repaid', $params); + return $response->getApiData(); + } + + /** + * Initiate quick repayment for isolated margin accounts + * @param array $params + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function repayAll(array $params) + { + $response = $this->call(Request::METHOD_POST, '/api/v1/isolated/repay/all', $params); + return $response->getApiData(); + } + + /** + * Initiate quick repayment for single margin accounts + * @param array $params + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function repaySingle(array $params) + { + $response = $this->call(Request::METHOD_POST, '/api/v1/isolated/repay/single', $params); + return $response->getApiData(); + } +} diff --git a/src/PrivateApi/Order.php b/src/PrivateApi/Order.php index 00e0c4c..e6948ec 100644 --- a/src/PrivateApi/Order.php +++ b/src/PrivateApi/Order.php @@ -87,13 +87,13 @@ public function getList(array $params = [], array $pagination = []) /** * Get v1 historical orders list - * @deprecated * @param array $params * @param array $pagination * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException * @throws \KuCoin\SDK\Exceptions\HttpException * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + * @deprecated */ public function getV1List(array $params = [], array $pagination = []) { @@ -173,4 +173,280 @@ public function createMarginOrder(array $order) $response = $this->call(Request::METHOD_POST, '/api/v1/margin/order', $order); return $response->getApiData(); } -} \ No newline at end of file + + /** + * Place a high-frequency new order + * @param array $order + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function hfCreate(array $order) + { + $response = $this->call(Request::METHOD_POST, '/api/v1/hf/orders', $order); + return $response->getApiData(); + } + + /** + * Place synchronize high-frequency new order + * @param array $order + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function hfSyncCreate(array $order) + { + $response = $this->call(Request::METHOD_POST, '/api/v1/hf/orders/sync', $order); + return $response->getApiData(); + } + + /** + * Place high-frequency bulk orders + * @param array $orderList + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function hfCreateMulti(array $orderList) + { + $response = $this->call(Request::METHOD_POST, '/api/v1/hf/orders/multi', $orderList); + return $response->getApiData(); + } + + /** + * Place synchronize high-frequency bulk orders + * @param array $orderList + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function hfSyncCreateMulti(array $orderList) + { + $response = $this->call(Request::METHOD_POST, '/api/v1/hf/orders/multi/sync', $orderList); + return $response->getApiData(); + } + + /** + * Modify the price and quantity of the order according to orderId or clientOid. + * @param array $orderList + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function hfModify(array $orderList) + { + $response = $this->call(Request::METHOD_POST, '/api/v1/hf/orders/alter', $orderList); + return $response->getApiData(); + } + + /** + * Cancel a high-frequency order by orderId. + * @param $orderId + * @param array $params + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function hfCancel($orderId, array $params) + { + $response = $this->call(Request::METHOD_DELETE, '/api/v1/hf/orders/' . $orderId, $params); + return $response->getApiData(); + } + + /** + * Cancel synchronize high-frequency order by orderId. + * @param $orderId + * @param array $params + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function hfSyncCancel($orderId, array $params) + { + $response = $this->call(Request::METHOD_DELETE, '/api/v1/hf/orders/sync/' . $orderId, $params); + return $response->getApiData(); + } + + /** + * Cancel a high-frequency order by ClientOid. + * @param $orderId + * @param array $params + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function hfCancelByClientOid($clientOid, array $params) + { + $response = $this->call(Request::METHOD_DELETE, '/api/v1/hf/orders/client-order/' . $clientOid, $params); + return $response->getApiData(); + } + + /** + * Cancel synchronize high-frequency order by ClientOid + * @param $clientOid + * @param array $params + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function hfSyncCancelByClientOid($clientOid, array $params) + { + $response = $this->call(Request::METHOD_DELETE, '/api/v1/hf/orders/sync/client-order/' . $clientOid, $params); + return $response->getApiData(); + } + + /** + * Cancel the specified quantity of the order according to the orderId. + * @param $orderId + * @param array $params + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function hfSyncCancelSize($orderId, array $params) + { + $response = $this->call(Request::METHOD_DELETE, '/api/v1/hf/orders/cancel' . $orderId, $params); + return $response->getApiData(); + } + + /** + * Cancel the specified quantity of the order according to the orderId. + * @param array $params + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function hfSyncCancelAll(array $params) + { + $response = $this->call(Request::METHOD_DELETE, '/api/v1/hf/orders', $params); + return $response->getApiData(); + } + + /** + * Get a list of all active HF orders. The return data is sorted in descending order based on the latest update times. + * @param array $params + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getActiveOrderList(array $params) + { + $response = $this->call(Request::METHOD_GET, '/api/v1/hf/orders/active', $params); + return $response->getApiData(); + } + + /** + * Get all trading pairs that the user has active orders + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getActiveSymbols() + { + $response = $this->call(Request::METHOD_GET, '/api/v1/hf/orders/active/symbols'); + return $response->getApiData(); + } + + /** + * Get a list of filled HF orders and returns paginated data. The returned data is sorted in descending order based on the latest order update times. + * @param array $params + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getDoneOrderList(array $params) + { + $response = $this->call(Request::METHOD_GET, '/api/v1/hf/orders/done', $params); + return $response->getApiData(); + } + + /** + * Get information for a single HF order using the order id. + * @param $orderId + * @param array $params + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getHfDetail($orderId, array $params) + { + $response = $this->call(Request::METHOD_GET, '/api/v1/hf/orders/' . $orderId, $params); + return $response->getApiData(); + } + + /** + * Get information about a single order using clientOid. If the order does not exist, then there will be a prompt saying that the order does not exist. + * @param $clientOid + * @param array $params + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getHfDetailByClientOid($clientOid, array $params) + { + $response = $this->call(Request::METHOD_GET, '/api/v1/hf/orders/client-order/' . $clientOid, $params); + return $response->getApiData(); + } + + /** + * Cancel all orders of the set trading pair after the specified time. + * If this interface is not called again for renewal or cancellation before the set time, + * the system will help the user to cancel the order of the corresponding trading pair. + * Otherwise, it will not.Call this interface to automatically cancel all orders of the set trading pair after the specified time. + * If this interface is not called again for renewal or cancellation before the set time, + * the system will help the user to cancel the order of the corresponding trading pair. Otherwise it will not. + * @param array $params + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function hfAutoCancel(array $params) + { + $response = $this->call(Request::METHOD_POST, '/api/v1/hf/orders/dead-cancel-all', $params); + return $response->getApiData(); + } + + /** + * Get the settings of automatic order cancellation + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getHfAutoCancel() + { + $response = $this->call(Request::METHOD_GET, '/api/v1/hf/orders/dead-cancel-all/query'); + return $response->getApiData(); + } + + /** + * Get a list of the latest HF transaction details. The returned results are paginated. The data is sorted in descending order according to time. + * @param array $params + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getHfFills(array $params) + { + $response = $this->call(Request::METHOD_GET, '/api/v1/hf/fills',$params); + return $response->getApiData(); + } +} diff --git a/src/PublicApi/Symbol.php b/src/PublicApi/Symbol.php index 656cb22..b0f2e45 100644 --- a/src/PublicApi/Symbol.php +++ b/src/PublicApi/Symbol.php @@ -14,6 +14,7 @@ class Symbol extends KuCoinApi { /** * Get a list of symbol + * @deprecated Recommended to use /api/v2/symbols * @param string|null $market * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -174,4 +175,18 @@ public function getMarkets() $response = $this->call(Request::METHOD_GET, '/api/v1/markets'); return $response->getApiData(); } -} \ No newline at end of file + + /** + * Get a list of symbol for V2 + * @param string|null $market + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getListV2($market = null) + { + $response = $this->call(Request::METHOD_GET, '/api/v2/symbols', compact('market')); + return $response->getApiData(); + } +} diff --git a/tests/PrivateApi/AccountTest.php b/tests/PrivateApi/AccountTest.php index 63d7d23..7276e6f 100644 --- a/tests/PrivateApi/AccountTest.php +++ b/tests/PrivateApi/AccountTest.php @@ -159,7 +159,7 @@ public function testInnerTransfer(Account $api) */ public function testInnerTransferV2(Account $api) { - $order = $api->innerTransferV2(uniqid(), 'KCS', 'main', 'trade', '2'); + $order = $api->innerTransferV2(uniqid(), 'USDT', 'main', 'trade_hf', '200'); $this->assertArrayHasKey('orderId', $order); } @@ -514,4 +514,103 @@ public function testDeleteSubUserApiKey(Account $api) $this->assertArrayHasKey('apiKey', $result); $this->assertArrayHasKey('subName', $result); } + + /** + * @dataProvider apiProvider + * @param Account $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetSubAccountListV2(Account $api) + { + $params = ['currentPage' => 1, 'pageSize' => 10]; + $accounts = $api->getSubAccountListV2($params); + foreach ($accounts['items'] as $account) { + $this->assertInternalType('array', $account); + $this->assertArrayHasKey('subUserId', $account); + $this->assertArrayHasKey('subName', $account); + $this->assertArrayHasKey('mainAccounts', $account); + $this->assertArrayHasKey('marginAccounts', $account); + $this->assertArrayHasKey('tradeAccounts', $account); + $this->assertInternalType('array', $account['mainAccounts']); + $this->assertInternalType('array', $account['marginAccounts']); + $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); + $this->assertArrayHasKey('baseCurrency', $item); + $this->assertArrayHasKey('baseCurrencyPrice', $item); + $this->assertArrayHasKey('baseAmount', $item); + } + foreach ($account['marginAccounts'] as $item) { + $this->assertArrayHasKey('currency', $item); + $this->assertArrayHasKey('balance', $item); + $this->assertArrayHasKey('available', $item); + $this->assertArrayHasKey('holds', $item); + $this->assertArrayHasKey('baseCurrency', $item); + $this->assertArrayHasKey('baseCurrencyPrice', $item); + $this->assertArrayHasKey('baseAmount', $item); + } + foreach ($account['tradeAccounts'] as $item) { + $this->assertArrayHasKey('currency', $item); + $this->assertArrayHasKey('balance', $item); + $this->assertArrayHasKey('available', $item); + $this->assertArrayHasKey('holds', $item); + $this->assertArrayHasKey('baseCurrency', $item); + $this->assertArrayHasKey('baseCurrencyPrice', $item); + $this->assertArrayHasKey('baseAmount', $item); + } + } + } + + /** + * @dataProvider apiProvider + * @param Account $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetAccountTransferable(Account $api) + { + $params = [ + 'currency' => 'USDT', + 'type' => 'MAIN', + ]; + $result = $api->getAccountTransferable($params); + $this->assertInternalType('array', $result); + $this->assertArrayHasKey('balance', $result); + $this->assertArrayHasKey('available', $result); + $this->assertArrayHasKey('currency', $result); + $this->assertArrayHasKey('holds', $result); + $this->assertArrayHasKey('transferable', $result); + } + + /** + * @dataProvider apiProvider + * @param Account $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetHfLedgersV2(Account $api) + { + $params = ['currency' => 'USDT']; + $data = $api->getHfLedgersV2($params); + $this->assertInternalType('array', $data); + foreach ($data as $item) { + $this->assertArrayHasKey('id', $item); + $this->assertArrayHasKey('currency', $item); + $this->assertArrayHasKey('amount', $item); + $this->assertArrayHasKey('fee', $item); + $this->assertArrayHasKey('balance', $item); + $this->assertArrayHasKey('accountType', $item); + $this->assertArrayHasKey('bizType', $item); + $this->assertArrayHasKey('direction', $item); + $this->assertArrayHasKey('createdAt', $item); + $this->assertArrayHasKey('context', $item); + } + } } diff --git a/tests/PrivateApi/IsolatedMarginTest.php b/tests/PrivateApi/IsolatedMarginTest.php new file mode 100644 index 0000000..0becf1d --- /dev/null +++ b/tests/PrivateApi/IsolatedMarginTest.php @@ -0,0 +1,209 @@ +getSymbols(); + $this->assertInternalType('array', $symbols); + foreach ($symbols as $symbol) { + $this->assertInternalType('array', $symbol); + $this->assertArrayHasKey('symbol', $symbol); + $this->assertArrayHasKey('symbolName', $symbol); + $this->assertArrayHasKey('baseCurrency', $symbol); + $this->assertArrayHasKey('quoteCurrency', $symbol); + $this->assertArrayHasKey('maxLeverage', $symbol); + $this->assertArrayHasKey('flDebtRatio', $symbol); + $this->assertArrayHasKey('tradeEnable', $symbol); + $this->assertArrayHasKey('autoRenewMaxDebtRatio', $symbol); + $this->assertArrayHasKey('baseBorrowEnable', $symbol); + $this->assertArrayHasKey('quoteBorrowEnable', $symbol); + $this->assertArrayHasKey('baseTransferInEnable', $symbol); + $this->assertArrayHasKey('quoteTransferInEnable', $symbol); + } + } + + /** + * @dataProvider apiProvider + * @param IsolatedMargin $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testAccountList(IsolatedMargin $api) + { + $params = [ + 'balanceCurrency' => 'USDT', + ]; + $accounts = $api->getAccountList($params); + $this->assertInternalType('array', $accounts); + $this->assertArrayHasKey('totalConversionBalance', $accounts); + $this->assertArrayHasKey('liabilityConversionBalance', $accounts); + $this->assertInternalType('array', $accounts['assets']); + foreach ($accounts['assets'] as $asset) { + $this->assertInternalType('array', $asset); + $this->assertArrayHasKey('symbol', $asset); + $this->assertArrayHasKey('status', $asset); + $this->assertArrayHasKey('debtRatio', $asset); + $this->assertInternalType('array', $asset['baseAsset']); + $this->assertArrayHasKey('currency', $asset['baseAsset']); + $this->assertArrayHasKey('totalBalance', $asset['baseAsset']); + $this->assertArrayHasKey('holdBalance', $asset['baseAsset']); + $this->assertArrayHasKey('availableBalance', $asset['baseAsset']); + $this->assertArrayHasKey('liability', $asset['baseAsset']); + $this->assertArrayHasKey('interest', $asset['baseAsset']); + $this->assertArrayHasKey('borrowableAmount', $asset['baseAsset']); + $this->assertInternalType('array', $asset['quoteAsset']); + $this->assertArrayHasKey('currency', $asset['quoteAsset']); + $this->assertArrayHasKey('totalBalance', $asset['quoteAsset']); + $this->assertArrayHasKey('holdBalance', $asset['quoteAsset']); + $this->assertArrayHasKey('availableBalance', $asset['quoteAsset']); + $this->assertArrayHasKey('liability', $asset['quoteAsset']); + $this->assertArrayHasKey('interest', $asset['quoteAsset']); + $this->assertArrayHasKey('borrowableAmount', $asset['quoteAsset']); + } + } + + /** + * @dataProvider apiProvider + * @param IsolatedMargin $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testAccountDetail(IsolatedMargin $api) + { + $symbol = 'BTC-USDT'; + $account = $api->getAccountDetail($symbol); + $this->assertInternalType('array', $account); + $this->assertArrayHasKey('symbol', $account); + $this->assertArrayHasKey('status', $account); + $this->assertArrayHasKey('debtRatio', $account); + $this->assertInternalType('array', $account['baseAsset']); + $this->assertArrayHasKey('currency', $account['baseAsset']); + $this->assertArrayHasKey('totalBalance', $account['baseAsset']); + $this->assertArrayHasKey('holdBalance', $account['baseAsset']); + $this->assertArrayHasKey('availableBalance', $account['baseAsset']); + $this->assertArrayHasKey('liability', $account['baseAsset']); + $this->assertArrayHasKey('interest', $account['baseAsset']); + $this->assertArrayHasKey('borrowableAmount', $account['baseAsset']); + $this->assertInternalType('array', $account['quoteAsset']); + $this->assertArrayHasKey('currency', $account['quoteAsset']); + $this->assertArrayHasKey('totalBalance', $account['quoteAsset']); + $this->assertArrayHasKey('holdBalance', $account['quoteAsset']); + $this->assertArrayHasKey('availableBalance', $account['quoteAsset']); + $this->assertArrayHasKey('liability', $account['quoteAsset']); + $this->assertArrayHasKey('interest', $account['quoteAsset']); + $this->assertArrayHasKey('borrowableAmount', $account['quoteAsset']); + } + + /** + * @dataProvider apiProvider + * @param IsolatedMargin $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testBorrow(IsolatedMargin $api) + { + $params = ['symbol' => 'BTC-USDT', 'currency' => 'USDT', 'size' => 9, 'borrowStrategy' => 'IOC', 'period' => '7,14']; + $result = $api->borrow($params); + $this->assertInternalType('array', $result); + $this->assertArrayHasKey('orderId', $result); + $this->assertArrayHasKey('currency', $result); + $this->assertArrayHasKey('actualSize', $result); + } + + /** + * @dataProvider apiProvider + * @param IsolatedMargin $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetOutstanding(IsolatedMargin $api) + { + $params = ['symbol' => 'BTC-USDT', 'currency' => 'USDT', 'pageSize' => 10, 'currentPage' => 1]; + $records = $api->getOutstanding($params); + $this->assertInternalType('array', $records['items']); + foreach ($records['items'] as $item) { + $this->assertArrayHasKey('loanId', $item); + $this->assertArrayHasKey('symbol', $item); + $this->assertArrayHasKey('currency', $item); + $this->assertArrayHasKey('liabilityBalance', $item); + $this->assertArrayHasKey('principalTotal', $item); + $this->assertArrayHasKey('interestBalance', $item); + $this->assertArrayHasKey('createdAt', $item); + $this->assertArrayHasKey('maturityTime', $item); + $this->assertArrayHasKey('period', $item); + $this->assertArrayHasKey('repaidSize', $item); + $this->assertArrayHasKey('dailyInterestRate', $item); + } + } + + /** + * @dataProvider apiProvider + * @param IsolatedMargin $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetRepaid(IsolatedMargin $api) + { + $params = ['symbol' => 'BTC-USDT', 'currency' => 'USDT', 'pageSize' => 10, 'currentPage' => 1]; + $records = $api->getRepaid($params); + $this->assertInternalType('array', $records['items']); + foreach ($records['items'] as $item) { + $this->assertArrayHasKey('loanId', $item); + $this->assertArrayHasKey('symbol', $item); + $this->assertArrayHasKey('currency', $item); + $this->assertArrayHasKey('principalTotal', $item); + $this->assertArrayHasKey('interestBalance', $item); + $this->assertArrayHasKey('repaidSize', $item); + $this->assertArrayHasKey('createdAt', $item); + $this->assertArrayHasKey('period', $item); + $this->assertArrayHasKey('dailyInterestRate', $item); + $this->assertArrayHasKey('repayFinishAt', $item); + } + } + /** + * @dataProvider apiProvider + * @param IsolatedMargin $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testRepayAll(IsolatedMargin $api) + { + $params = ['symbol' => 'BTC-USDT', 'currency' => 'USDT', 'size' => 10, 'seqStrategy' => 'RECENTLY_EXPIRE_FIRST']; + $result = $api->repayAll($params); + $this->assertInternalType('array', $result); + } + /** + * @dataProvider apiProvider + * @param IsolatedMargin $api + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testRepaySingle(IsolatedMargin $api) + { + $params = ['symbol' => 'BTC-USDT', 'currency' => 'USDT', 'size' => 10, 'loanId' => '123456789123456789123451']; + $result = $api->repaySingle($params); + $this->assertInternalType('array', $result); + } +} diff --git a/tests/PrivateApi/OrderTest.php b/tests/PrivateApi/OrderTest.php index 30aa2b9..73d26df 100644 --- a/tests/PrivateApi/OrderTest.php +++ b/tests/PrivateApi/OrderTest.php @@ -339,7 +339,6 @@ public function testCancelByClientOid(Order $api) /** * @dataProvider apiProvider * @param Order $api - * @return array|string * @throws \KuCoin\SDK\Exceptions\BusinessException * @throws \KuCoin\SDK\Exceptions\HttpException * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException @@ -360,4 +359,606 @@ public function testCreateMarginLimit(Order $api) $this->assertInternalType('array', $data); $this->assertArrayHasKey('orderId', $data); } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testHfCreateLimit(Order $api) + { + $order = [ + 'clientOid' => uniqid(), + 'type' => 'limit', + 'side' => 'buy', + 'symbol' => 'BTC-USDT', + 'remark' => 'test', + 'price' => 100, + 'size' => 1, + ]; + $data = $api->hfCreate($order); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('orderId', $data); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testHfCreateMarket(Order $api) + { + $order = [ + 'clientOid' => uniqid(), + 'type' => 'market', + 'side' => 'buy', + 'symbol' => 'BTC-USDT', + 'remark' => 'Test Order ', + 'size' => 2, + ]; + $data = $api->hfCreate($order); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('orderId', $data); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testHfSyncCreateLimit(Order $api) + { + $order = [ + 'clientOid' => uniqid(), + 'type' => 'limit', + 'side' => 'buy', + 'symbol' => 'BTC-USDT', + 'remark' => 'test', + 'price' => "1", + 'size' => "1", + ]; + $data = $api->hfSyncCreate($order); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('orderId', $data); + $this->assertArrayHasKey('orderTime', $data); + $this->assertArrayHasKey('originSize', $data); + $this->assertArrayHasKey('dealSize', $data); + $this->assertArrayHasKey('remainSize', $data); + $this->assertArrayHasKey('canceledSize', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('matchTime', $data); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testHfSyncCreateMarket(Order $api) + { + $order = [ + 'clientOid' => uniqid(), + 'type' => 'market', + 'side' => 'buy', + 'symbol' => 'BTC-USDT', + 'remark' => 'Test Order ', + 'size' => 2, + ]; + $data = $api->hfSyncCreate($order); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('orderId', $data); + $this->assertArrayHasKey('orderTime', $data); + $this->assertArrayHasKey('originSize', $data); + $this->assertArrayHasKey('dealSize', $data); + $this->assertArrayHasKey('remainSize', $data); + $this->assertArrayHasKey('canceledSize', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('matchTime', $data); + var_dump($data['orderId'], $order); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testHfCreateMulti(Order $api) + { + $order = [ + 'type' => 'limit', + 'side' => 'buy', + 'price' => 100, + 'size' => 1, + ]; + $orderList = []; + for ($i = 0; $i < 5; $i++) { + $order['clientOid'] = uniqid(); + $order['remark'] = 'Multi'; + $order['symbol'] = 'BTC-USDT'; + $orderList[] = $order; + } + $data = $api->hfCreateMulti($orderList); + foreach ($data as $item) { + $this->assertArrayHasKey('orderId', $item); + $this->assertArrayHasKey('success', $item); + } + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testHfSyncCreateMulti(Order $api) + { + $order = [ + 'type' => 'limit', + 'side' => 'buy', + 'price' => 100, + 'size' => 1, + ]; + $orderList = []; + for ($i = 0; $i < 5; $i++) { + $order['clientOid'] = uniqid(); + $order['symbol'] = 'BTC-USDT'; + $order['remark'] = 'Multi'; + $orderList[] = $order; + } + + $data = $api->hfSyncCreateMulti($orderList); + $this->assertInternalType('array', $data); + foreach ($data as $item) { + $this->assertArrayHasKey('orderId', $item); + $this->assertArrayHasKey('orderTime', $item); + $this->assertArrayHasKey('originSize', $item); + $this->assertArrayHasKey('dealSize', $item); + $this->assertArrayHasKey('remainSize', $item); + $this->assertArrayHasKey('canceledSize', $item); + $this->assertArrayHasKey('status', $item); + $this->assertArrayHasKey('matchTime', $item); + $this->assertArrayHasKey('success', $item); + } + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testHfModify(Order $api) + { + $order = [ + 'symbol' => 'BTC-USDT', + 'clientOid' => '64819b02d066b', +// 'orderId' => '64819b035b13c7000179854c', + 'newPrice' => 2, + ]; + $data = $api->hfModify($order); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('orderId', $data); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testHfCancel(Order $api) + { + $params = [ + 'symbol' => 'BTC-USDT', + ]; + $orderId = '64819b035b13c7000179854c'; + $data = $api->hfCancel($orderId, $params); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('orderId', $data); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testHfSyncCancel(Order $api) + { + $params = [ + 'symbol' => 'BTC-USDT', + ]; + $orderId = '64819b035b13c7000179854c'; + $data = $api->hfSyncCancel($orderId, $params); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('orderId', $data); + $this->assertArrayHasKey('originSize', $data); + $this->assertArrayHasKey('originFunds', $data); + $this->assertArrayHasKey('dealSize', $data); + $this->assertArrayHasKey('remainSize', $data); + $this->assertArrayHasKey('canceledSize', $data); + $this->assertArrayHasKey('status', $data); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testHfCancelByClientOid(Order $api) + { + $params = [ + 'symbol' => 'BTC-USDT', + ]; + $clientOid = '64819b02d066b'; + $data = $api->hfCancelByClientOid($clientOid, $params); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('clientOid', $data); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testHfSyncCancelByClientOid(Order $api) + { + $params = [ + 'symbol' => 'BTC-USDT', + ]; + $clientOid = '64819b02d066b'; + $data = $api->hfSyncCancelByClientOid($clientOid, $params); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('orderId', $data); + $this->assertArrayHasKey('originSize', $data); + $this->assertArrayHasKey('originFunds', $data); + $this->assertArrayHasKey('dealSize', $data); + $this->assertArrayHasKey('remainSize', $data); + $this->assertArrayHasKey('canceledSize', $data); + $this->assertArrayHasKey('status', $data); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testHfSyncCancelSize(Order $api) + { + $params = [ + 'symbol' => 'BTC-USDT', + 'cancelSize' => 1, + ]; + $orderId = '64819b035b13c7000179854c'; + $data = $api->hfSyncCancelSize($orderId, $params); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('orderId', $data); + $this->assertArrayHasKey('cancelSize', $data); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testHfSyncCancelAll(Order $api) + { + $params = [ + 'symbol' => 'BTC-USDT', + ]; + $api->hfSyncCancelAll($params); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetActiveOrderList(Order $api) + { + $params = [ + 'symbol' => 'BTC-USDT', + ]; + $data = $api->getActiveOrderList($params); + $this->assertInternalType('array', $data); + foreach ($data as $item) { + $this->assertInternalType('array', $item); + $this->assertArrayHasKey('id', $item); + $this->assertArrayHasKey('symbol', $item); + $this->assertArrayHasKey('opType', $item); + $this->assertArrayHasKey('type', $item); + $this->assertArrayHasKey('side', $item); + $this->assertArrayHasKey('price', $item); + $this->assertArrayHasKey('size', $item); + $this->assertArrayHasKey('cancelledSize', $item); + $this->assertArrayHasKey('dealSize', $item); + $this->assertArrayHasKey('remainSize', $item); + $this->assertArrayHasKey('funds', $item); + $this->assertArrayHasKey('cancelledFunds', $item); + $this->assertArrayHasKey('dealFunds', $item); + $this->assertArrayHasKey('remainFunds', $item); + $this->assertArrayHasKey('fee', $item); + $this->assertArrayHasKey('feeCurrency', $item); + $this->assertArrayHasKey('stp', $item); + $this->assertArrayHasKey('timeInForce', $item); + $this->assertArrayHasKey('postOnly', $item); + $this->assertArrayHasKey('hidden', $item); + $this->assertArrayHasKey('iceberg', $item); + $this->assertArrayHasKey('visibleSize', $item); + $this->assertArrayHasKey('cancelAfter', $item); + $this->assertArrayHasKey('channel', $item); + $this->assertArrayHasKey('clientOid', $item); + $this->assertArrayHasKey('remark', $item); + $this->assertArrayHasKey('tags', $item); + $this->assertArrayHasKey('active', $item); + $this->assertArrayHasKey('inOrderBook', $item); + $this->assertArrayHasKey('cancelExist', $item); + $this->assertArrayHasKey('createdAt', $item); + $this->assertArrayHasKey('lastUpdatedAt', $item); + $this->assertArrayHasKey('tradeType', $item); + } + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetActiveSymbols(Order $api) + { + $data = $api->getActiveSymbols(); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('symbols', $data); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetDoneOrderList(Order $api) + { + $params = [ + 'symbol' => 'BTC-USDT', + ]; + $response = $api->getDoneOrderList($params); + $this->assertInternalType('array', $response); + $this->assertArrayHasKey('lastId', $response); + foreach ($response['items'] as $item) { + $this->assertInternalType('array', $item); + $this->assertArrayHasKey('id', $item); + $this->assertArrayHasKey('symbol', $item); + $this->assertArrayHasKey('opType', $item); + $this->assertArrayHasKey('type', $item); + $this->assertArrayHasKey('side', $item); + $this->assertArrayHasKey('price', $item); + $this->assertArrayHasKey('size', $item); + $this->assertArrayHasKey('cancelledSize', $item); + $this->assertArrayHasKey('dealSize', $item); + $this->assertArrayHasKey('remainSize', $item); + $this->assertArrayHasKey('funds', $item); + $this->assertArrayHasKey('cancelledFunds', $item); + $this->assertArrayHasKey('dealFunds', $item); + $this->assertArrayHasKey('remainFunds', $item); + $this->assertArrayHasKey('fee', $item); + $this->assertArrayHasKey('feeCurrency', $item); + $this->assertArrayHasKey('stp', $item); + $this->assertArrayHasKey('timeInForce', $item); + $this->assertArrayHasKey('postOnly', $item); + $this->assertArrayHasKey('hidden', $item); + $this->assertArrayHasKey('iceberg', $item); + $this->assertArrayHasKey('visibleSize', $item); + $this->assertArrayHasKey('cancelAfter', $item); + $this->assertArrayHasKey('channel', $item); + $this->assertArrayHasKey('clientOid', $item); + $this->assertArrayHasKey('remark', $item); + $this->assertArrayHasKey('tags', $item); + $this->assertArrayHasKey('active', $item); + $this->assertArrayHasKey('inOrderBook', $item); + $this->assertArrayHasKey('cancelExist', $item); + $this->assertArrayHasKey('createdAt', $item); + $this->assertArrayHasKey('lastUpdatedAt', $item); + $this->assertArrayHasKey('tradeType', $item); + } + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetHfDetail(Order $api) + { + $params = [ + 'symbol' => 'BTC-USDT', + ]; + $orderId = '64819b035b13c7000179854c'; + $item = $api->getHfDetail($orderId, $params); + $this->assertInternalType('array', $item); + $this->assertArrayHasKey('id', $item); + $this->assertArrayHasKey('symbol', $item); + $this->assertArrayHasKey('opType', $item); + $this->assertArrayHasKey('type', $item); + $this->assertArrayHasKey('side', $item); + $this->assertArrayHasKey('price', $item); + $this->assertArrayHasKey('size', $item); + $this->assertArrayHasKey('cancelledSize', $item); + $this->assertArrayHasKey('dealSize', $item); + $this->assertArrayHasKey('remainSize', $item); + $this->assertArrayHasKey('funds', $item); + $this->assertArrayHasKey('cancelledFunds', $item); + $this->assertArrayHasKey('dealFunds', $item); + $this->assertArrayHasKey('remainFunds', $item); + $this->assertArrayHasKey('fee', $item); + $this->assertArrayHasKey('feeCurrency', $item); + $this->assertArrayHasKey('stp', $item); + $this->assertArrayHasKey('timeInForce', $item); + $this->assertArrayHasKey('postOnly', $item); + $this->assertArrayHasKey('hidden', $item); + $this->assertArrayHasKey('iceberg', $item); + $this->assertArrayHasKey('visibleSize', $item); + $this->assertArrayHasKey('cancelAfter', $item); + $this->assertArrayHasKey('channel', $item); + $this->assertArrayHasKey('clientOid', $item); + $this->assertArrayHasKey('remark', $item); + $this->assertArrayHasKey('tags', $item); + $this->assertArrayHasKey('active', $item); + $this->assertArrayHasKey('inOrderBook', $item); + $this->assertArrayHasKey('cancelExist', $item); + $this->assertArrayHasKey('createdAt', $item); + $this->assertArrayHasKey('lastUpdatedAt', $item); + $this->assertArrayHasKey('tradeType', $item); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetHfDetailByClientOid(Order $api) + { + $params = [ + 'symbol' => 'BTC-USDT', + ]; + $clientOid = '64819b02d066b'; + $item = $api->getHfDetailByClientOid($clientOid, $params); + $this->assertInternalType('array', $item); + $this->assertArrayHasKey('id', $item); + $this->assertArrayHasKey('symbol', $item); + $this->assertArrayHasKey('opType', $item); + $this->assertArrayHasKey('type', $item); + $this->assertArrayHasKey('side', $item); + $this->assertArrayHasKey('price', $item); + $this->assertArrayHasKey('size', $item); + $this->assertArrayHasKey('cancelledSize', $item); + $this->assertArrayHasKey('dealSize', $item); + $this->assertArrayHasKey('remainSize', $item); + $this->assertArrayHasKey('funds', $item); + $this->assertArrayHasKey('cancelledFunds', $item); + $this->assertArrayHasKey('dealFunds', $item); + $this->assertArrayHasKey('remainFunds', $item); + $this->assertArrayHasKey('fee', $item); + $this->assertArrayHasKey('feeCurrency', $item); + $this->assertArrayHasKey('stp', $item); + $this->assertArrayHasKey('timeInForce', $item); + $this->assertArrayHasKey('postOnly', $item); + $this->assertArrayHasKey('hidden', $item); + $this->assertArrayHasKey('iceberg', $item); + $this->assertArrayHasKey('visibleSize', $item); + $this->assertArrayHasKey('cancelAfter', $item); + $this->assertArrayHasKey('channel', $item); + $this->assertArrayHasKey('clientOid', $item); + $this->assertArrayHasKey('remark', $item); + $this->assertArrayHasKey('tags', $item); + $this->assertArrayHasKey('active', $item); + $this->assertArrayHasKey('inOrderBook', $item); + $this->assertArrayHasKey('cancelExist', $item); + $this->assertArrayHasKey('createdAt', $item); + $this->assertArrayHasKey('lastUpdatedAt', $item); + $this->assertArrayHasKey('tradeType', $item); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testHfAutoCancel(Order $api) + { + $params = ['timeout' => 20]; + $data = $api->hfAutoCancel($params); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('currentTime', $data); + $this->assertArrayHasKey('triggerTime', $data); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetHfAutoCancel(Order $api) + { + $data = $api->getHfAutoCancel(); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('timeout', $data); + $this->assertArrayHasKey('symbols', $data); + $this->assertArrayHasKey('currentTime', $data); + $this->assertArrayHasKey('triggerTime', $data); + } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetHfFills(Order $api) + { + $params = [ + 'symbol' => 'BTC-USDT', + ]; + $data = $api->getHfFills($params); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('lastId', $data); + foreach ($data['items'] as $item) { + $this->assertArrayHasKey('id', $item); + $this->assertArrayHasKey('symbol', $item); + $this->assertArrayHasKey('tradeId', $item); + $this->assertArrayHasKey('orderId', $item); + $this->assertArrayHasKey('counterOrderId', $item); + $this->assertArrayHasKey('side', $item); + $this->assertArrayHasKey('liquidity', $item); + $this->assertArrayHasKey('forceTaker', $item); + $this->assertArrayHasKey('price', $item); + $this->assertArrayHasKey('size', $item); + $this->assertArrayHasKey('funds', $item); + $this->assertArrayHasKey('fee', $item); + $this->assertArrayHasKey('feeRate', $item); + $this->assertArrayHasKey('feeCurrency', $item); + $this->assertArrayHasKey('feeCurrency', $item); + $this->assertArrayHasKey('type', $item); + $this->assertArrayHasKey('stop', $item); + $this->assertArrayHasKey('createdAt', $item); + $this->assertArrayHasKey('tradeType', $item); + } + } + } diff --git a/tests/PublicApi/SymbolTest.php b/tests/PublicApi/SymbolTest.php index 9634d2f..b13eb72 100644 --- a/tests/PublicApi/SymbolTest.php +++ b/tests/PublicApi/SymbolTest.php @@ -233,4 +233,36 @@ public function testGetMarkets(Symbol $api) $this->assertInternalType('array', $data); $this->assertNotEmpty($data, 'Empty markets'); } -} \ No newline at end of file + + /** + * @dataProvider apiProvider + * @param Symbol $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetListV2(Symbol $api) + { + $data = $api->getListV2('BTC'); + $this->assertInternalType('array', $data); + foreach ($data as $item) { + $this->assertArrayHasKey('symbol', $item); + $this->assertArrayHasKey('name', $item); + $this->assertArrayHasKey('baseCurrency', $item); + $this->assertArrayHasKey('quoteCurrency', $item); + $this->assertArrayHasKey('market', $item); + $this->assertArrayHasKey('baseMinSize', $item); + $this->assertArrayHasKey('quoteMinSize', $item); + $this->assertArrayHasKey('baseMaxSize', $item); + $this->assertArrayHasKey('quoteMaxSize', $item); + $this->assertArrayHasKey('baseIncrement', $item); + $this->assertArrayHasKey('quoteIncrement', $item); + $this->assertArrayHasKey('priceIncrement', $item); + $this->assertArrayHasKey('feeCurrency', $item); + $this->assertArrayHasKey('enableTrading', $item); + $this->assertArrayHasKey('isMarginEnabled', $item); + $this->assertArrayHasKey('priceLimitRate', $item); + $this->assertArrayHasKey('minFunds', $item); + } + } +} From 285e876ff906cff065ca5e302ec39686598a60ee Mon Sep 17 00:00:00 2001 From: Artisan Date: Wed, 21 Jun 2023 15:29:46 +0800 Subject: [PATCH 3/7] update version and date --- src/Api.php | 6 +++--- src/PrivateApi/Account.php | 20 ++++++++++---------- src/PrivateApi/IsolatedMargin.php | 12 ++++++------ src/PrivateApi/Order.php | 14 +++++++------- src/PublicApi/Symbol.php | 2 +- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Api.php b/src/Api.php index 37714f6..7068004 100644 --- a/src/Api.php +++ b/src/Api.php @@ -16,12 +16,12 @@ abstract class Api /** * @var string SDK Version */ - const VERSION = '1.1.27'; + const VERSION = '1.1.28'; /** * @var string SDK update date */ - const UPDATE_DATE = '2022.03.25'; + const UPDATE_DATE = '2023.06.21'; /** * @var string @@ -245,4 +245,4 @@ public function call($method, $uri, array $params = [], array $headers = [], $ti return $response; } -} \ No newline at end of file +} diff --git a/src/PrivateApi/Account.php b/src/PrivateApi/Account.php index 2e51724..0164379 100644 --- a/src/PrivateApi/Account.php +++ b/src/PrivateApi/Account.php @@ -217,7 +217,7 @@ public function getLedgersV2(array $params = [], array $pagination = []) return $response->getApiData(); } /** - * Get sub user + * Get sub user. * @param array $pagination * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -231,7 +231,7 @@ public function getSubUserV2(array $pagination = []) } /** - * Get account description + * Get account description. * @param array $pagination * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -245,7 +245,7 @@ public function getUserinfoV2() } /** - * Create sub user + * Create sub user. * @param array $params * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -259,7 +259,7 @@ public function createSubUserV2(array $params = []) } /** - * Create sub user api key + * Create sub user api key. * @param array $params * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -273,7 +273,7 @@ public function createSubUserApiKey(array $params = []) } /** - * Get sub user api key + * Get sub user api key. * @param array $params * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -287,7 +287,7 @@ public function getSubUserApiKey(array $params = []) } /** - * Update sub user api key + * Update sub user api key. * @param array $params * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -301,7 +301,7 @@ public function updateSubUserApiKey(array $params = []) } /** - * Delete sub user api key + * Delete sub user api key. * @param array $params * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -315,7 +315,7 @@ public function deleteSubUserApiKey(array $params = []) } /** - * Get the aggregated balance of all sub-accounts of the current user for V2 version + * Get the aggregated balance of all sub-accounts of the current user for V2 version. * @param array $params * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -329,7 +329,7 @@ public function getSubAccountListV2(array $params = []) } /** - * Get transferable funds under the specified account and currency + * Get transferable funds under the specified account and currency. * @param array $params * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -343,7 +343,7 @@ public function getAccountTransferable(array $params = []) } /** - * Get account ledgers for high-frequency + * Get account ledgers for high-frequency. * @param array $params * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException diff --git a/src/PrivateApi/IsolatedMargin.php b/src/PrivateApi/IsolatedMargin.php index a107f71..d51d968 100644 --- a/src/PrivateApi/IsolatedMargin.php +++ b/src/PrivateApi/IsolatedMargin.php @@ -14,7 +14,7 @@ class IsolatedMargin extends KuCoinApi { /** - * Get the current isolated margin trading pair configuration + * Get the current isolated margin trading pair configuration. * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException * @throws \KuCoin\SDK\Exceptions\HttpException @@ -27,7 +27,7 @@ public function getSymbols() } /** - * Get all isolated margin accounts of the current user + * Get all isolated margin accounts of the current user. * @param array $params * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -41,7 +41,7 @@ public function getAccountList(array $params) } /** - * Get the info on a single isolated margin account of the current user + * Get the info on a single isolated margin account of the current user. * @param string $symbol * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -70,7 +70,7 @@ public function borrow(array $params) /** - * Get outstanding repayment records of isolated margin + * Get outstanding repayment records of isolated margin. * @param array $params * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -98,7 +98,7 @@ public function getRepaid(array $params) } /** - * Initiate quick repayment for isolated margin accounts + * Initiate quick repayment for isolated margin accounts. * @param array $params * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -112,7 +112,7 @@ public function repayAll(array $params) } /** - * Initiate quick repayment for single margin accounts + * Initiate quick repayment for single margin accounts. * @param array $params * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException diff --git a/src/PrivateApi/Order.php b/src/PrivateApi/Order.php index e6948ec..ee91907 100644 --- a/src/PrivateApi/Order.php +++ b/src/PrivateApi/Order.php @@ -175,7 +175,7 @@ public function createMarginOrder(array $order) } /** - * Place a high-frequency new order + * Place a high-frequency new order. * @param array $order * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -189,7 +189,7 @@ public function hfCreate(array $order) } /** - * Place synchronize high-frequency new order + * Place synchronize high-frequency new order. * @param array $order * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -203,7 +203,7 @@ public function hfSyncCreate(array $order) } /** - * Place high-frequency bulk orders + * Place high-frequency bulk orders. * @param array $orderList * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -217,7 +217,7 @@ public function hfCreateMulti(array $orderList) } /** - * Place synchronize high-frequency bulk orders + * Place synchronize high-frequency bulk orders. * @param array $orderList * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException @@ -290,7 +290,7 @@ public function hfCancelByClientOid($clientOid, array $params) } /** - * Cancel synchronize high-frequency order by ClientOid + * Cancel synchronize high-frequency order by ClientOid. * @param $clientOid * @param array $params * @return mixed|null @@ -348,7 +348,7 @@ public function getActiveOrderList(array $params) } /** - * Get all trading pairs that the user has active orders + * Get all trading pairs that the user has active orders. * @return mixed|null * @throws \KuCoin\SDK\Exceptions\BusinessException * @throws \KuCoin\SDK\Exceptions\HttpException @@ -424,7 +424,7 @@ public function hfAutoCancel(array $params) } /** - * Get the settings of automatic order cancellation + * Get the settings of automatic order cancellation. * @return mixed|null * @throws \KuCoin\SDK\Exceptions\BusinessException * @throws \KuCoin\SDK\Exceptions\HttpException diff --git a/src/PublicApi/Symbol.php b/src/PublicApi/Symbol.php index b0f2e45..cc82553 100644 --- a/src/PublicApi/Symbol.php +++ b/src/PublicApi/Symbol.php @@ -177,7 +177,7 @@ public function getMarkets() } /** - * Get a list of symbol for V2 + * Get a list of symbol for V2. * @param string|null $market * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException From f79de77578b805a0f79f13eada5b01d0b96f1c5a Mon Sep 17 00:00:00 2001 From: Artisan Date: Wed, 21 Jun 2023 15:44:02 +0800 Subject: [PATCH 4/7] code format --- src/PrivateApi/Account.php | 11 ++++++----- src/PrivateApi/Order.php | 2 +- src/PublicApi/Symbol.php | 2 +- tests/PrivateApi/IsolatedMarginTest.php | 2 ++ 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/PrivateApi/Account.php b/src/PrivateApi/Account.php index 0164379..d29ef72 100644 --- a/src/PrivateApi/Account.php +++ b/src/PrivateApi/Account.php @@ -56,9 +56,6 @@ public function getDetail($accountId) } /** - * @deprecated Use getLedgersV1 instead - * - * Get account ledgers * @param string $accountId * @param array $params * @param array $pagination @@ -66,6 +63,9 @@ public function getDetail($accountId) * @throws \KuCoin\SDK\Exceptions\BusinessException * @throws \KuCoin\SDK\Exceptions\HttpException * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + * @deprecated Use getLedgersV1 instead + * + * Get account ledgers */ public function getLedgers($accountId, array $params = [], array $pagination = []) { @@ -173,13 +173,13 @@ public function getSubAccountList() } /** - * @deprecated Use subTransferV2 instead. - * 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 + * @deprecated Use subTransferV2 instead. + * Transfer between master account and sub-account */ public function subTransfer(array $params) { @@ -216,6 +216,7 @@ public function getLedgersV2(array $params = [], array $pagination = []) $response = $this->call(Request::METHOD_GET, '/api/v1/accounts/ledgers', $params + $pagination); return $response->getApiData(); } + /** * Get sub user. * @param array $pagination diff --git a/src/PrivateApi/Order.php b/src/PrivateApi/Order.php index ee91907..2a73861 100644 --- a/src/PrivateApi/Order.php +++ b/src/PrivateApi/Order.php @@ -446,7 +446,7 @@ public function getHfAutoCancel() */ public function getHfFills(array $params) { - $response = $this->call(Request::METHOD_GET, '/api/v1/hf/fills',$params); + $response = $this->call(Request::METHOD_GET, '/api/v1/hf/fills', $params); return $response->getApiData(); } } diff --git a/src/PublicApi/Symbol.php b/src/PublicApi/Symbol.php index cc82553..f5d1953 100644 --- a/src/PublicApi/Symbol.php +++ b/src/PublicApi/Symbol.php @@ -14,12 +14,12 @@ class Symbol extends KuCoinApi { /** * Get a list of symbol - * @deprecated Recommended to use /api/v2/symbols * @param string|null $market * @return array * @throws \KuCoin\SDK\Exceptions\BusinessException * @throws \KuCoin\SDK\Exceptions\HttpException * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + * @deprecated Recommended to use /api/v2/symbols */ public function getList($market = null) { diff --git a/tests/PrivateApi/IsolatedMarginTest.php b/tests/PrivateApi/IsolatedMarginTest.php index 0becf1d..10977cb 100644 --- a/tests/PrivateApi/IsolatedMarginTest.php +++ b/tests/PrivateApi/IsolatedMarginTest.php @@ -180,6 +180,7 @@ public function testGetRepaid(IsolatedMargin $api) $this->assertArrayHasKey('repayFinishAt', $item); } } + /** * @dataProvider apiProvider * @param IsolatedMargin $api @@ -193,6 +194,7 @@ public function testRepayAll(IsolatedMargin $api) $result = $api->repayAll($params); $this->assertInternalType('array', $result); } + /** * @dataProvider apiProvider * @param IsolatedMargin $api From 36388c99267a1ec03b0382aee16eb0add5bf0d00 Mon Sep 17 00:00:00 2001 From: Artisan Date: Mon, 26 Jun 2023 16:32:03 +0800 Subject: [PATCH 5/7] update readme.md --- README.md | 1 - src/PublicApi/Symbol.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index e7a23f6..f0b0b21 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,6 @@ go(function () { | KuCoin\SDK\PrivateApi\Account::subTransfer() | YES | `DEPRECATED` https://docs.kucoin.com/#transfer-between-master-account-and-sub-account | | KuCoin\SDK\PrivateApi\Account::subTransferV2() | YES | https://docs.kucoin.com/#transfer-between-master-user-and-sub-user | | KuCoin\SDK\PrivateApi\Account::getLedgersV2() | YES | https://docs.kucoin.com/#get-account-ledgers | -| KuCoin\SDK\PrivateApi\Account::getLedgersV2() | YES | https://docs.kucoin.com/#get-account-ledgers | | KuCoin\SDK\PrivateApi\Account::getSubUserV2() | YES | https://docs.kucoin.com/#get-paginated-list-of-sub-accounts | | KuCoin\SDK\PrivateApi\Account::getUserinfoV2() | YES | https://docs.kucoin.com/#get-account-summary-info-v2 | | KuCoin\SDK\PrivateApi\Account::createSubUserV2() | YES | https://docs.kucoin.com/#create-sub-account-v2 | diff --git a/src/PublicApi/Symbol.php b/src/PublicApi/Symbol.php index f5d1953..a80c969 100644 --- a/src/PublicApi/Symbol.php +++ b/src/PublicApi/Symbol.php @@ -19,7 +19,7 @@ class Symbol extends KuCoinApi * @throws \KuCoin\SDK\Exceptions\BusinessException * @throws \KuCoin\SDK\Exceptions\HttpException * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException - * @deprecated Recommended to use /api/v2/symbols + * @deprecated Call getListV2() instead */ public function getList($market = null) { From 750f36a47a979ee95fb4c5cf90d252a2aedcd77c Mon Sep 17 00:00:00 2001 From: Artisan Date: Mon, 26 Jun 2023 17:50:07 +0800 Subject: [PATCH 6/7] update deprecated note --- src/PrivateApi/Account.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/PrivateApi/Account.php b/src/PrivateApi/Account.php index d29ef72..86d35c4 100644 --- a/src/PrivateApi/Account.php +++ b/src/PrivateApi/Account.php @@ -56,6 +56,7 @@ public function getDetail($accountId) } /** + * Get account ledgers * @param string $accountId * @param array $params * @param array $pagination @@ -63,9 +64,7 @@ public function getDetail($accountId) * @throws \KuCoin\SDK\Exceptions\BusinessException * @throws \KuCoin\SDK\Exceptions\HttpException * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException - * @deprecated Use getLedgersV1 instead - * - * Get account ledgers + * @deprecated Call getLedgersV2() instead */ public function getLedgers($accountId, array $params = [], array $pagination = []) { @@ -173,13 +172,13 @@ public function getSubAccountList() } /** + * 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 - * @deprecated Use subTransferV2 instead. - * Transfer between master account and sub-account + * @deprecated Call subTransferV2() instead. */ public function subTransfer(array $params) { From 1f83fb657ae2e459971de22618ea93c4075cccdd Mon Sep 17 00:00:00 2001 From: Artisan Date: Mon, 26 Jun 2023 18:43:23 +0800 Subject: [PATCH 7/7] update readme.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f0b0b21..a6f3908 100644 --- a/README.md +++ b/README.md @@ -247,7 +247,7 @@ go(function () { | API | Authentication | Description | | -------- | -------- | -------- | -| KuCoin\SDK\PrivateApi\Symbol::getAggregatedFullOrderBook() | NO | https://docs.kucoin.com/#get-full-order-book-aggregated | +| KuCoin\SDK\PrivateApi\Symbol::getAggregatedFullOrderBook() | NO | `DEPRECATED`https://docs.kucoin.com/#get-full-order-book-aggregated |
@@ -261,7 +261,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::getV1List() | YES | `DEPRECATED`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 | | KuCoin\SDK\PrivateApi\Order::createMarginOrder()| YES | https://docs.kucoin.com/#place-a-margin-order |