From 1fe72f3c848b969da9cbd757fd22df47ee001fca Mon Sep 17 00:00:00 2001 From: Fieyum Date: Fri, 5 Jan 2024 10:21:59 +0800 Subject: [PATCH 1/3] add spot, etf api --- README.md | 355 ++++++++++++++++-------------- src/Api.php | 4 +- src/PrivateApi/Margin.php | 13 ++ src/PrivateApi/OcoOrder.php | 135 ++++++++++++ src/PrivateApi/Order.php | 13 ++ tests/PrivateApi/MarginTest.php | 21 ++ tests/PrivateApi/OcoOrderTest.php | 217 ++++++++++++++++++ tests/PrivateApi/OrderTest.php | 14 ++ 8 files changed, 608 insertions(+), 164 deletions(-) create mode 100644 src/PrivateApi/OcoOrder.php create mode 100644 tests/PrivateApi/OcoOrderTest.php diff --git a/README.md b/README.md index a6f3908..d4b4060 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,13 @@ ## Requirements -| Dependency | Requirement | -| -------- | -------- | -| [PHP](https://secure.php.net/manual/en/install.php) | `>=5.5.0` `Recommend PHP7+` | -| [guzzlehttp/guzzle](https://github.com/guzzle/guzzle) | `^6.0\|^7.0` | +| Dependency | Requirement | +|-------------------------------------------------------|-----------------------------| +| [PHP](https://secure.php.net/manual/en/install.php) | `>=5.5.0` `Recommend PHP7+` | +| [guzzlehttp/guzzle](https://github.com/guzzle/guzzle) | `^6.0\|^7.0` | ## Install + > Install package via [Composer](https://getcomposer.org/). ```shell @@ -29,10 +30,10 @@ composer require "kucoin/kucoin-php-sdk:~1.1.0" ### Choose environment -| Environment | BaseUri | -| -------- | -------- | -| *Production* | `https://api.kucoin.com(DEFAULT)`| -| *Sandbox* | `https://openapi-sandbox.kucoin.com` | +| Environment | BaseUri | +|--------------|--------------------------------------| +| *Production* | `https://api.kucoin.com(DEFAULT)` | +| *Sandbox* | `https://openapi-sandbox.kucoin.com` | ```php // Switch to the sandbox environment @@ -52,6 +53,7 @@ KuCoinApi::getLogger()->debug("I'm a debug message"); ``` ### Examples + > See the [test case](tests) for more examples. #### Example of API `without` authentication @@ -65,7 +67,9 @@ var_dump($timestamp); ``` ##### **Note** -To reinforce the security of the API, KuCoin upgraded the API key to version 2.0, the validation logic has also been changed. It is recommended to create(https://www.kucoin.com/account/api) and update your API key to version 2.0. The API key of version 1.0 will be still valid until May 1, 2021 + +To reinforce the security of the API, KuCoin upgraded the API key to version 2.0, the validation logic has also been changed. It is recommended to create(https://www.kucoin.com/account/api) and update your API key to version 2.0. The API key of +version 1.0 will be still valid until May 1, 2021 #### Example of API `with` authentication @@ -136,6 +140,7 @@ $api->subscribePublicChannels($query, $channels, function (array $message, WebSo ``` #### ⚡️Coroutine HTTP client for asynchronous IO + > See the [benchmark](examples/BenchmarkCoroutine.php), almost `20x` faster than `curl`. ```bash @@ -189,246 +194,272 @@ go(function () { ``` ### API list +
KuCoin\SDK\PrivateApi\Account -| API | Authentication | Description | -| -------- | -------- | -------- | -| KuCoin\SDK\PrivateApi\Account::create() | YES | https://docs.kucoin.com/#create-an-account | -| KuCoin\SDK\PrivateApi\Account::getList() | YES | https://docs.kucoin.com/#list-accounts | -| KuCoin\SDK\PrivateApi\Account::getDetail() | YES | https://docs.kucoin.com/#get-an-account | -| KuCoin\SDK\PrivateApi\Account::getLedgers() | YES | `DEPRECATED` https://docs.kucoin.com/#get-account-ledgers-deprecated | -| KuCoin\SDK\PrivateApi\Account::getHolds() | YES | https://docs.kucoin.com/#get-holds | -| KuCoin\SDK\PrivateApi\Account::innerTransfer() | YES | `DEPRECATED` https://docs.kucoin.com/#inner-transfer | -| KuCoin\SDK\PrivateApi\Account::innerTransferV2() | 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 | `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::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 | +| API | Authentication | Description | +|---------------------------------------------------------|----------------|---------------------------------------------------------------------------------------------| +| KuCoin\SDK\PrivateApi\Account::create() | YES | https://docs.kucoin.com/#create-an-account | +| KuCoin\SDK\PrivateApi\Account::getList() | YES | https://docs.kucoin.com/#list-accounts | +| KuCoin\SDK\PrivateApi\Account::getDetail() | YES | https://docs.kucoin.com/#get-an-account | +| KuCoin\SDK\PrivateApi\Account::getLedgers() | YES | `DEPRECATED` https://docs.kucoin.com/#get-account-ledgers-deprecated | +| KuCoin\SDK\PrivateApi\Account::getHolds() | YES | https://docs.kucoin.com/#get-holds | +| KuCoin\SDK\PrivateApi\Account::innerTransfer() | YES | `DEPRECATED` https://docs.kucoin.com/#inner-transfer | +| KuCoin\SDK\PrivateApi\Account::innerTransferV2() | 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 | `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::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 | +
KuCoin\SDK\PrivateApi\Deposit -| API | Authentication | Description | -| -------- | -------- | -------- | -| 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::getAddresses() | YES | https://docs.kucoin.com/#get-deposit-addresses-v2 | -| 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 | +| API | Authentication | Description | +|------------------------------------------------|----------------|----------------------------------------------------------| +| 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::getAddresses() | YES | https://docs.kucoin.com/#get-deposit-addresses-v2 | +| 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 |
KuCoin\SDK\PrivateApi\TradeFee -| API | Authentication | Description | -| -------- | -------- | -------- | -| KuCoin\SDK\PrivateApi\TradeFee::getBaseFee() | YES | https://docs.kucoin.com/#basic-user-fee | -| KuCoin\SDK\PrivateApi\TradeFee::getTradeFees() | YES | https://docs.kucoin.com/#actual-fee-rate-of-the-trading-pair | +| API | Authentication | Description | +|------------------------------------------------|----------------|--------------------------------------------------------------| +| KuCoin\SDK\PrivateApi\TradeFee::getBaseFee() | YES | https://docs.kucoin.com/#basic-user-fee | +| KuCoin\SDK\PrivateApi\TradeFee::getTradeFees() | YES | https://docs.kucoin.com/#actual-fee-rate-of-the-trading-pair |
KuCoin\SDK\PrivateApi\Symbol -| API | Authentication | Description | -| -------- | -------- | -------- | -| KuCoin\SDK\PrivateApi\Symbol::getAggregatedFullOrderBook() | NO | `DEPRECATED`https://docs.kucoin.com/#get-full-order-book-aggregated | +| API | Authentication | Description | +|------------------------------------------------------------|----------------|---------------------------------------------------------------------| +| KuCoin\SDK\PrivateApi\Symbol::getAggregatedFullOrderBook() | NO | `DEPRECATED`https://docs.kucoin.com/#get-full-order-book-aggregated |
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 | -| 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 | `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 | -| 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| +| 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 | +| 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 | `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 | +| 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 | +| KuCoin\SDK\PrivateApi\Order::hfCancelAll() | YES | https://www.kucoin.com/docs/rest/spot-trading/spot-hf-trade-pro-account/cancel-all-hf-orders |
+
+KuCoin\SDK\PrivateApi\OcoOrder + +| API | Authentication | Description | +|--------------------------------------------------------|----------------|-------------------------------------------------------------------------------------| +| KuCoin\SDK\PrivateApi\OcoOrder::create() | YES | https://www.kucoin.com/docs/rest/spot-trading/oco-order/place-order | +| KuCoin\SDK\PrivateApi\OcoOrder::cancel() | YES | https://www.kucoin.com/docs/rest/spot-trading/oco-order/cancel-order-by-orderid | +| KuCoin\SDK\PrivateApi\OcoOrder::cancelByClientOid() | YES | https://www.kucoin.com/docs/rest/spot-trading/oco-order/cancel-order-by-clientoid | +| KuCoin\SDK\PrivateApi\OcoOrder::cancelMulti() | YES | https://www.kucoin.com/docs/rest/spot-trading/oco-order/cancel-multiple-orders | +| KuCoin\SDK\PrivateApi\OcoOrder::getDetail() | YES | https://www.kucoin.com/docs/rest/spot-trading/oco-order/get-order-info-by-orderid | +| KuCoin\SDK\PrivateApi\OcoOrder::getDetailByClientOid() | YES | https://www.kucoin.com/docs/rest/spot-trading/oco-order/get-order-info-by-clientoid | +| KuCoin\SDK\PrivateApi\OcoOrder::getList() | YES | https://www.kucoin.com/docs/rest/spot-trading/oco-order/get-order-list | + +
+ + + +
KuCoin\SDK\PrivateApi\StopOrder -| API | Authentication | Description | -| -------- | -------- | -------- | -| KuCoin\SDK\PrivateApi\StopOrder::create() | YES | https://docs.kucoin.com/#place-a-new-order-2 | -| KuCoin\SDK\PrivateApi\StopOrder::cancel() | YES | https://docs.kucoin.com/#cancel-an-order-2 | -| KuCoin\SDK\PrivateApi\StopOrder::cancelBatch() | YES | https://docs.kucoin.com/#cancel-orders | -| KuCoin\SDK\PrivateApi\StopOrder::getList() | YES | https://docs.kucoin.com/#list-stop-orders | -| KuCoin\SDK\PrivateApi\StopOrder::getDetail() | YES | https://docs.kucoin.com/#get-single-order-info | -| KuCoin\SDK\PrivateApi\StopOrder::getDetailByClientOid() | YES | https://docs.kucoin.com/#get-single-order-by-clientoid | -| KuCoin\SDK\PrivateApi\StopOrder::cancelByClientOid()| YES | https://docs.kucoin.com/#cancel-single-order-by-clientoid-2 | +| API | Authentication | Description | +|---------------------------------------------------------|----------------|-------------------------------------------------------------| +| KuCoin\SDK\PrivateApi\StopOrder::create() | YES | https://docs.kucoin.com/#place-a-new-order-2 | +| KuCoin\SDK\PrivateApi\StopOrder::cancel() | YES | https://docs.kucoin.com/#cancel-an-order-2 | +| KuCoin\SDK\PrivateApi\StopOrder::cancelBatch() | YES | https://docs.kucoin.com/#cancel-orders | +| KuCoin\SDK\PrivateApi\StopOrder::getList() | YES | https://docs.kucoin.com/#list-stop-orders | +| KuCoin\SDK\PrivateApi\StopOrder::getDetail() | YES | https://docs.kucoin.com/#get-single-order-info | +| KuCoin\SDK\PrivateApi\StopOrder::getDetailByClientOid() | YES | https://docs.kucoin.com/#get-single-order-by-clientoid | +| KuCoin\SDK\PrivateApi\StopOrder::cancelByClientOid() | YES | https://docs.kucoin.com/#cancel-single-order-by-clientoid-2 |
KuCoin\SDK\PrivateApi\Fill -| API | Authentication | Description | -| -------- | -------- | -------- | -| KuCoin\SDK\PrivateApi\Fill::getList() | YES | https://docs.kucoin.com/#list-fills | -| KuCoin\SDK\PrivateApi\Fill::getRecentList() | YES | https://docs.kucoin.com/#recent-fills | +| API | Authentication | Description | +|---------------------------------------------|----------------|---------------------------------------| +| KuCoin\SDK\PrivateApi\Fill::getList() | YES | https://docs.kucoin.com/#list-fills | +| KuCoin\SDK\PrivateApi\Fill::getRecentList() | YES | https://docs.kucoin.com/#recent-fills |
KuCoin\SDK\PrivateApi\WebSocketFeed -| API | Authentication | Description | -| -------- | -------- | -------- | -| KuCoin\SDK\PrivateApi\WebSocketFeed::getPublicServer() | NO | https://docs.kucoin.com/#apply-connect-token | -| KuCoin\SDK\PrivateApi\WebSocketFeed::getPrivateServer() | YES | https://docs.kucoin.com/#apply-connect-token | -| KuCoin\SDK\PrivateApi\WebSocketFeed::subscribePublicChannel() | NO | https://docs.kucoin.com/#public-channels | -| KuCoin\SDK\PrivateApi\WebSocketFeed::subscribePublicChannels() | NO | https://docs.kucoin.com/#public-channels | -| KuCoin\SDK\PrivateApi\WebSocketFeed::subscribePrivateChannel() | YES | https://docs.kucoin.com/#private-channels | -| KuCoin\SDK\PrivateApi\WebSocketFeed::subscribePrivateChannels() | YES | https://docs.kucoin.com/#private-channels | +| API | Authentication | Description | +|-----------------------------------------------------------------|----------------|----------------------------------------------| +| KuCoin\SDK\PrivateApi\WebSocketFeed::getPublicServer() | NO | https://docs.kucoin.com/#apply-connect-token | +| KuCoin\SDK\PrivateApi\WebSocketFeed::getPrivateServer() | YES | https://docs.kucoin.com/#apply-connect-token | +| KuCoin\SDK\PrivateApi\WebSocketFeed::subscribePublicChannel() | NO | https://docs.kucoin.com/#public-channels | +| KuCoin\SDK\PrivateApi\WebSocketFeed::subscribePublicChannels() | NO | https://docs.kucoin.com/#public-channels | +| KuCoin\SDK\PrivateApi\WebSocketFeed::subscribePrivateChannel() | YES | https://docs.kucoin.com/#private-channels | +| KuCoin\SDK\PrivateApi\WebSocketFeed::subscribePrivateChannels() | YES | https://docs.kucoin.com/#private-channels |
KuCoin\SDK\PrivateApi\Withdrawal -| API | Authentication | Description | -| -------- | -------- | -------- | -| 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 | +| API | Authentication | Description | +|-----------------------------------------------|----------------|-------------------------------------------------------------| +| 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 |
KuCoin\SDK\PublicApi\Currency -| API | Authentication | Description | -| -------- | -------- | -------- | -| KuCoin\SDK\PublicApi\Currency::getList() | NO | https://docs.kucoin.com/#get-currencies | -| KuCoin\SDK\PublicApi\Currency::getDetail() | NO | https://docs.kucoin.com/#get-currency-detail | -| KuCoin\SDK\PublicApi\Currency::getPrices() | NO | https://docs.kucoin.com/#get-fiat-price | -| KuCoin\SDK\PublicApi\Currency::getV2Detail() | NO | https://docs.kucoin.com/#get-currency-detail-recommend | +| API | Authentication | Description | +|----------------------------------------------|----------------|--------------------------------------------------------| +| KuCoin\SDK\PublicApi\Currency::getList() | NO | https://docs.kucoin.com/#get-currencies | +| KuCoin\SDK\PublicApi\Currency::getDetail() | NO | https://docs.kucoin.com/#get-currency-detail | +| KuCoin\SDK\PublicApi\Currency::getPrices() | NO | https://docs.kucoin.com/#get-fiat-price | +| KuCoin\SDK\PublicApi\Currency::getV2Detail() | NO | https://docs.kucoin.com/#get-currency-detail-recommend |
KuCoin\SDK\PublicApi\Symbol -| API | Authentication | Description | -| -------- | -------- | -------- | -| 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 | -| KuCoin\SDK\PublicApi\Symbol::getTradeHistories() | NO | https://docs.kucoin.com/#get-trade-histories | -| 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 | +| API | Authentication | Description | +|-----------------------------------------------------------|----------------|-------------------------------------------------------------------| +| 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 | +| KuCoin\SDK\PublicApi\Symbol::getTradeHistories() | NO | https://docs.kucoin.com/#get-trade-histories | +| 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 | +
KuCoin\SDK\PrivateApi\Margin -| API | Authentication | Description | -| -------- | -------- | -------- | -| KuCoin\SDK\PrivateApi\Margin::getMarkPrice() | YES | https://docs.kucoin.com/#margin-info | -| KuCoin\SDK\PrivateApi\Margin::getConfig() | YES | https://docs.kucoin.com/#get-margin-configuration-info | -| KuCoin\SDK\PrivateApi\Margin::getAccount() | YES | https://docs.kucoin.com/#get-margin-account | -| KuCoin\SDK\PrivateApi\Margin::borrow() | YES | https://docs.kucoin.com/#post-borrow-order | -| KuCoin\SDK\PrivateApi\Margin::getBorrow() | YES | https://docs.kucoin.com/#get-borrow-order | -| KuCoin\SDK\PrivateApi\Margin::getOutstanding() | YES | https://docs.kucoin.com/#get-repay-record | -| KuCoin\SDK\PrivateApi\Margin::getRepayRecord() | YES | https://docs.kucoin.com/#get-repayment-record | -| KuCoin\SDK\PrivateApi\Margin::repayAll() | YES | https://docs.kucoin.com/#one-click-repayment | -| KuCoin\SDK\PrivateApi\Margin::repaySingle() | YES | https://docs.kucoin.com/#repay-a-single-order | -| KuCoin\SDK\PrivateApi\Margin::lend() | YES | https://docs.kucoin.com/#post-lend-order | -| KuCoin\SDK\PrivateApi\Margin::cancelLend() | YES | https://docs.kucoin.com/#cancel-lend-order | -| KuCoin\SDK\PrivateApi\Margin::setAutoLend() | YES | https://docs.kucoin.com/#set-auto-lend | -| KuCoin\SDK\PrivateApi\Margin::getLendActive() | YES | https://docs.kucoin.com/#get-active-order | -| KuCoin\SDK\PrivateApi\Margin::getLendDone() | YES | https://docs.kucoin.com/#get-lent-history | -| KuCoin\SDK\PrivateApi\Margin::getUnsettled() | YES | https://docs.kucoin.com/#get-active-lend-order-list | -| KuCoin\SDK\PrivateApi\Margin::getSettled() | YES | https://docs.kucoin.com/#get-settled-lend-order-history | -| KuCoin\SDK\PrivateApi\Margin::getLendAssets() | YES | https://docs.kucoin.com/#get-account-lend-record | -| KuCoin\SDK\PrivateApi\Margin::getMarket() | YES | https://docs.kucoin.com/#lending-market-data | -| KuCoin\SDK\PrivateApi\Margin::getTradeLast() | YES | https://docs.kucoin.com/#margin-trade-data | +| API | Authentication | Description | +|------------------------------------------------|----------------|--------------------------------------------------------------------------------------| +| KuCoin\SDK\PrivateApi\Margin::getMarkPrice() | YES | https://docs.kucoin.com/#margin-info | +| KuCoin\SDK\PrivateApi\Margin::getConfig() | YES | https://docs.kucoin.com/#get-margin-configuration-info | +| KuCoin\SDK\PrivateApi\Margin::getAccount() | YES | https://docs.kucoin.com/#get-margin-account | +| KuCoin\SDK\PrivateApi\Margin::borrow() | YES | https://docs.kucoin.com/#post-borrow-order | +| KuCoin\SDK\PrivateApi\Margin::getBorrow() | YES | https://docs.kucoin.com/#get-borrow-order | +| KuCoin\SDK\PrivateApi\Margin::getOutstanding() | YES | https://docs.kucoin.com/#get-repay-record | +| KuCoin\SDK\PrivateApi\Margin::getRepayRecord() | YES | https://docs.kucoin.com/#get-repayment-record | +| KuCoin\SDK\PrivateApi\Margin::repayAll() | YES | https://docs.kucoin.com/#one-click-repayment | +| KuCoin\SDK\PrivateApi\Margin::repaySingle() | YES | https://docs.kucoin.com/#repay-a-single-order | +| KuCoin\SDK\PrivateApi\Margin::lend() | YES | https://docs.kucoin.com/#post-lend-order | +| KuCoin\SDK\PrivateApi\Margin::cancelLend() | YES | https://docs.kucoin.com/#cancel-lend-order | +| KuCoin\SDK\PrivateApi\Margin::setAutoLend() | YES | https://docs.kucoin.com/#set-auto-lend | +| KuCoin\SDK\PrivateApi\Margin::getLendActive() | YES | https://docs.kucoin.com/#get-active-order | +| KuCoin\SDK\PrivateApi\Margin::getLendDone() | YES | https://docs.kucoin.com/#get-lent-history | +| KuCoin\SDK\PrivateApi\Margin::getUnsettled() | YES | https://docs.kucoin.com/#get-active-lend-order-list | +| KuCoin\SDK\PrivateApi\Margin::getSettled() | YES | https://docs.kucoin.com/#get-settled-lend-order-history | +| KuCoin\SDK\PrivateApi\Margin::getLendAssets() | YES | https://docs.kucoin.com/#get-account-lend-record | +| KuCoin\SDK\PrivateApi\Margin::getMarket() | YES | https://docs.kucoin.com/#lending-market-data | +| KuCoin\SDK\PrivateApi\Margin::getTradeLast() | YES | https://docs.kucoin.com/#margin-trade-data | +| KuCoin\SDK\PrivateApi\Margin::getEtfInfo() | YES | https://www.kucoin.com/docs/rest/margin-trading/margin-info/get-leveraged-token-info | +
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 | +| 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 -| API | Authentication | Description | -| -------- | -------- | -------- | -| KuCoin\SDK\PublicApi\Time::timestamp() | NO | https://docs.kucoin.com/#server-time | +| API | Authentication | Description | +|----------------------------------------|----------------|--------------------------------------| +| KuCoin\SDK\PublicApi\Time::timestamp() | NO | https://docs.kucoin.com/#server-time |
KuCoin\SDK\PublicApi\ServiceStatus -| API | Authentication | Description | -| -------- | -------- | -------- | -| KuCoin\SDK\PublicApi\ServiceStatus::getStatus() | NO | https://docs.kucoin.com/#service-status | +| API | Authentication | Description | +|-------------------------------------------------|----------------|-----------------------------------------| +| KuCoin\SDK\PublicApi\ServiceStatus::getStatus() | NO | https://docs.kucoin.com/#service-status |
## Run tests + > Modify your API key in `phpunit.xml` first. ```shell diff --git a/src/Api.php b/src/Api.php index 7068004..1517e00 100644 --- a/src/Api.php +++ b/src/Api.php @@ -16,12 +16,12 @@ abstract class Api /** * @var string SDK Version */ - const VERSION = '1.1.28'; + const VERSION = '1.1.29'; /** * @var string SDK update date */ - const UPDATE_DATE = '2023.06.21'; + const UPDATE_DATE = '2024.01.05'; /** * @var string diff --git a/src/PrivateApi/Margin.php b/src/PrivateApi/Margin.php index bb4a896..9588a80 100644 --- a/src/PrivateApi/Margin.php +++ b/src/PrivateApi/Margin.php @@ -316,4 +316,17 @@ public function getStrategyRiskLimit(string $marginModel) $response = $this->call(Request::METHOD_GET, '/api/v1/risk/limit/strategy', ['marginModel' => $marginModel]); return $response->getApiData(); } + + /** + * This interface returns leveraged token information. + * + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getEtfInfo() + { + return $this->call(Request::METHOD_GET, '/api/v3/etf/info')->getApiData(); + } } \ No newline at end of file diff --git a/src/PrivateApi/OcoOrder.php b/src/PrivateApi/OcoOrder.php new file mode 100644 index 0000000..1a4a249 --- /dev/null +++ b/src/PrivateApi/OcoOrder.php @@ -0,0 +1,135 @@ +call(Request::METHOD_POST, '/api/v3/oco/order', $order)->getApiData(); + } + + /** + * Cancel Order by orderId. + * + * @param $orderId + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function cancel($orderId) + { + return $this->call(Request::METHOD_DELETE, '/api/v3/oco/order/' . $orderId)->getApiData(); + } + + /** + * Cancel an order by clientOid. + * + * @param $clientOid + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function cancelByClientOid($clientOid) + { + return $this->call(Request::METHOD_DELETE, '/api/v3/oco/client-order/' . $clientOid)->getApiData(); + } + + /** + * Cancel Multiple Orders. + * + * @param string $symbol trading pair. If not passed, the oco orders of all symbols will be canceled by default. + * @param array $orderIds Specify the order number, there can be multiple orders, separated by commas. If not passed, all oco orders will be canceled by default. + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function cancelMulti($symbol = '', array $orderIds = []) + { + $query = http_build_query(array_filter([ + 'symbol' => $symbol, + 'orderIds' => implode(',', $orderIds), + ])); + + $path = '/api/v3/oco/orders'; + return $this->call(Request::METHOD_DELETE, $query ? "$path?$query" : $path)->getApiData(); + } + + /** + * Get Order Info by orderId. + * + * @param $orderId + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getDetail($orderId) + { + return $this->call(Request::METHOD_GET, '/api/v3/oco/order/' . $orderId)->getApiData(); + } + + /** + * Get Order Detail by orderId. + * + * @param $orderId + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getOrderDetail($orderId) + { + return $this->call(Request::METHOD_GET, '/api/v3/oco/order/details/' . $orderId)->getApiData(); + } + + /** + * Get Order Info by clientOid. + * + * @param $clientOid + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function getDetailByClientOid($clientOid) + { + return $this->call(Request::METHOD_GET, '/api/v3/oco/client-order/' . $clientOid)->getApiData(); + } + + /** + * + * Get Order 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 getList(array $params = [], array $pagination = []) + { + return $this->call(Request::METHOD_GET, '/api/v3/oco/orders', $params + $pagination)->getApiData(); + } +} diff --git a/src/PrivateApi/Order.php b/src/PrivateApi/Order.php index 2a73861..96d32f9 100644 --- a/src/PrivateApi/Order.php +++ b/src/PrivateApi/Order.php @@ -449,4 +449,17 @@ public function getHfFills(array $params) $response = $this->call(Request::METHOD_GET, '/api/v1/hf/fills', $params); return $response->getApiData(); } + + /** + * Cancel all HF orders. + * + * @return mixed|null + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function hfCancelAll() + { + return $this->call(Request::METHOD_DELETE, '/api/v1/hf/orders/cancelAll')->getApiData(); + } } diff --git a/tests/PrivateApi/MarginTest.php b/tests/PrivateApi/MarginTest.php index fdae168..3a895ec 100644 --- a/tests/PrivateApi/MarginTest.php +++ b/tests/PrivateApi/MarginTest.php @@ -389,4 +389,25 @@ public function testGetStrategyRiskLimit(Margin $api) $this->assertArrayHasKey('precision', $data[0]); } } + + + /** + * @dataProvider apiProvider + * @param Margin $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetEtfInfo(Margin $api) + { + $data = $api->getEtfInfo(); + foreach ($data as $item) { + $this->assertArrayHasKey('currency', $item); + $this->assertArrayHasKey('netAsset', $item); + $this->assertArrayHasKey('targetLeverage', $item); + $this->assertArrayHasKey('actualLeverage', $item); + $this->assertArrayHasKey('issuedSize', $item); + $this->assertArrayHasKey('basket', $item); + } + } } diff --git a/tests/PrivateApi/OcoOrderTest.php b/tests/PrivateApi/OcoOrderTest.php new file mode 100644 index 0000000..f7ecf19 --- /dev/null +++ b/tests/PrivateApi/OcoOrderTest.php @@ -0,0 +1,217 @@ +create($api); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('orderId', $data); + } + + /** + * @dataProvider apiProvider + * @param OcoOrder $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testCancel(OcoOrder $api) + { + $data = $this->create($api); + $result = $api->cancel($data['orderId']); + $this->assertInternalType('array', $result); + $this->assertArrayHasKey('cancelledOrderIds', $result); + } + + /** + * @dataProvider apiProvider + * @param OcoOrder $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testCancelByClientOid(OcoOrder $api) + { + $data = $this->create($api); + if (isset($data['orderId'])) { + $result = $api->cancelByClientOid($data['clientOid']); + $this->assertInternalType('array', $result); + $this->assertArrayHasKey('cancelledOrderIds', $result); + } + } + + /** + * @dataProvider apiProvider + * @param OcoOrder $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetList(OcoOrder $api) + { + $data = $api->getList(['symbol' => 'DOT-USDT'], ['currentPage' => 1, 'pageSize' => 10]); + $this->assertPagination($data); + foreach ($data['items'] as $item) { + $this->assertArrayHasKey('symbol', $item); + $this->assertArrayHasKey('orderId', $item); + $this->assertArrayHasKey('clientOid', $item); + $this->assertArrayHasKey('orderTime', $item); + $this->assertArrayHasKey('status', $item); + } + } + + /** + * @dataProvider apiProvider + * @param OcoOrder $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testCancelMulti(OcoOrder $api) + { + $order = $this->create($api); + $result = $api->cancelMulti($order['symbol']); + $this->assertInternalType('array', $result); + $this->assertArrayHasKey('cancelledOrderIds', $result); + $order = $this->create($api); + $result = $api->cancelMulti('', [$order['orderId']]); + $this->assertInternalType('array', $result); + $this->assertArrayHasKey('cancelledOrderIds', $result); + } + + /** + * @dataProvider apiProvider + * @param OcoOrder $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetDetail(OcoOrder $api) + { + $order = $this->create($api); + $result = $api->getDetail($order['orderId']); + $this->assertInternalType('array', $result); + $this->assertArrayHasKey('symbol', $result); + $this->assertArrayHasKey('orderId', $result); + $this->assertArrayHasKey('clientOid', $result); + $this->assertArrayHasKey('orderTime', $result); + $this->assertArrayHasKey('status', $result); + } + + /** + * @dataProvider apiProvider + * @param OcoOrder $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetDetailByClientOid(OcoOrder $api) + { + $order = $this->create($api); + $result = $api->getDetailByClientOid($order['clientOid']); + $this->assertInternalType('array', $result); + $this->assertArrayHasKey('symbol', $result); + $this->assertArrayHasKey('orderId', $result); + $this->assertArrayHasKey('clientOid', $result); + $this->assertArrayHasKey('orderTime', $result); + $this->assertArrayHasKey('status', $result); + } + + /** + * @dataProvider apiProvider + * @param OcoOrder $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testGetOrderDetail(OcoOrder $api) + { + $order = $this->create($api); + $result = $api->getOrderDetail($order['orderId']); + $this->assertInternalType('array', $result); + $this->assertArrayHasKey('symbol', $result); + $this->assertArrayHasKey('orderId', $result); + $this->assertArrayHasKey('clientOid', $result); + $this->assertArrayHasKey('orderTime', $result); + $this->assertArrayHasKey('status', $result); + $this->assertArrayHasKey('orders', $result); + foreach ($result['orders'] as $order) { + $this->assertArrayHasKey('id', $order); + $this->assertArrayHasKey('symbol', $order); + $this->assertArrayHasKey('side', $order); + $this->assertArrayHasKey('price', $order); + $this->assertArrayHasKey('stopPrice', $order); + $this->assertArrayHasKey('size', $order); + $this->assertArrayHasKey('status', $order); + } + } + + /** + * clean active order + * + * @return void + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public static function tearDownAfterClass() + { + $apiIns = (new OcoOrderTest)->apiProvider(); + foreach ($apiIns as $item) { + /** + * @var $api OcoOrder + */ + $api = current($item); + $api->cancelMulti(); + } + } + + /** + * @param OcoOrder $api + * @return array + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + protected function create(OcoOrder $api) + { + $symbolApi = new Symbol(); + $symbol = 'DOT-USDT'; + + $tradeStats = $symbolApi->get24HStats($symbol); + $nowPrice = $tradeStats['last']; + $openPrice = (string) round($nowPrice * '0.7', 2); + $stopPrice = (string) round($nowPrice * '1.3', 2); + $order = [ + 'clientOid' => uniqid(), + 'type' => 'limit', + 'side' => 'buy', + 'symbol' => $symbol, + 'remark' => 'test oco order', + 'price' => $openPrice, + 'size' => 0.1, + 'stopPrice' => $stopPrice, + 'limitPrice' => $stopPrice, + ]; + + $result = $api->create($order); + $order['orderId'] = $result['orderId']; + return $order; + } +} diff --git a/tests/PrivateApi/OrderTest.php b/tests/PrivateApi/OrderTest.php index 73d26df..9e5c5d9 100644 --- a/tests/PrivateApi/OrderTest.php +++ b/tests/PrivateApi/OrderTest.php @@ -961,4 +961,18 @@ public function testGetHfFills(Order $api) } } + + /** + * @dataProvider apiProvider + * @param Order $api + * @throws \KuCoin\SDK\Exceptions\BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testhfCancelAll(Order $api) + { + $data = $api->hfCancelAll(); + $this->assertArrayHasKey('succeedSymbols', $data); + $this->assertArrayHasKey('failedSymbols', $data); + } } From 0bd23082a9448c7702400fa329f61802292b711f Mon Sep 17 00:00:00 2001 From: Fieyum Date: Mon, 15 Jan 2024 16:29:02 +0800 Subject: [PATCH 2/3] add account test. --- tests/PrivateApi/AccountTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/PrivateApi/AccountTest.php b/tests/PrivateApi/AccountTest.php index 7276e6f..9a4ff2f 100644 --- a/tests/PrivateApi/AccountTest.php +++ b/tests/PrivateApi/AccountTest.php @@ -613,4 +613,29 @@ public function testGetHfLedgersV2(Account $api) $this->assertArrayHasKey('context', $item); } } + + /** + * @dataProvider apiProvider + * + * @param Account $api + * @return void + * @throws BusinessException + * @throws \KuCoin\SDK\Exceptions\HttpException + * @throws \KuCoin\SDK\Exceptions\InvalidApiUriException + */ + public function testFlexTransfer(Account $api) + { + $params = [ + 'clientOid' => uniqid(), + 'type' => 'INTERNAL', + 'currency' => "USDT", + 'amount' => '1', + 'fromAccountType' => 'MAIN', + 'toAccountType' => 'CONTRACT', + ]; + + $data = $api->flexTransfer($params); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('orderId', $data); + } } From 3a199e0fdc75608c645a3b8b1e10a6d5b7c51399 Mon Sep 17 00:00:00 2001 From: Fieyum Date: Mon, 15 Jan 2024 16:44:35 +0800 Subject: [PATCH 3/3] add ocoOrder. --- src/PrivateApi/OcoOrder.php | 7 ++----- tests/PrivateApi/OcoOrderTest.php | 5 ++++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PrivateApi/OcoOrder.php b/src/PrivateApi/OcoOrder.php index 1a4a249..91add97 100644 --- a/src/PrivateApi/OcoOrder.php +++ b/src/PrivateApi/OcoOrder.php @@ -66,13 +66,10 @@ public function cancelByClientOid($clientOid) */ public function cancelMulti($symbol = '', array $orderIds = []) { - $query = http_build_query(array_filter([ + return $this->call(Request::METHOD_DELETE, '/api/v3/oco/orders', [ 'symbol' => $symbol, 'orderIds' => implode(',', $orderIds), - ])); - - $path = '/api/v3/oco/orders'; - return $this->call(Request::METHOD_DELETE, $query ? "$path?$query" : $path)->getApiData(); + ])->getApiData(); } /** diff --git a/tests/PrivateApi/OcoOrderTest.php b/tests/PrivateApi/OcoOrderTest.php index f7ecf19..14987c7 100644 --- a/tests/PrivateApi/OcoOrderTest.php +++ b/tests/PrivateApi/OcoOrderTest.php @@ -178,7 +178,10 @@ public static function tearDownAfterClass() * @var $api OcoOrder */ $api = current($item); - $api->cancelMulti(); + try { + $api->cancelMulti(); + } catch (\Exception $e) { + } } }