diff --git a/CHANGELOG.md b/CHANGELOG.md index 387c056..6919eb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,40 @@ +## [1.0.10] - 2024-06-15 + +### Added APIs +- `GET /api/v3/hf/margin/order/active/symbols` +- `GET /api/v3/margin/symbols` +- `POST /api/v3/position/update-user-leverage` +- `GET /api/v1/otc-loan/loan` +- `GET /api/v1/otc-loan/accounts` +- `POST /api/v1/earn/orders` +- `DELETE /api/v1/earn/orders` +- `GET /api/v1/earn/redeem-preview` +- `GET /api/v1/earn/saving/products` +- `GET /api/v1/earn/hold-assets` +- `GET /api/v1/earn/promotion/products` +- `GET /api/v1/earn/kcs-staking/products` +- `GET /api/v1/earn/staking/products` +- `GET /api/v1/earn/eth-staking/products` +- `POST /api/v3/hf/margin/order` +- `POST /api/v3/hf/margin/order/test` +- `DELETE /api/v3/hf/margin/orders/{orderId}` +- `DELETE /api/v3/hf/margin/orders/client-order/{clientOid}` +- `DELETE /api/v3/hf/margin/orders` +- `GET /api/v3/hf/margin/orders/active` +- `GET /api/v3/hf/margin/orders/done` +- `GET /api/v3/hf/margin/orders/{orderId}` +- `GET /api/v3/hf/margin/orders/client-order/{clientOid}` +- `GET /api/v3/hf/margin/fills` + +- **TOPIC**: `/margin/isolatedPosition` (Isolated Margin Position Push) + +### Modified APIs +- `POST /api/v3/margin/borrow` - Added `isHf` field +- `POST /api/v3/margin/repay` - Added `isHf` field + +### Deprecated APIs +- **TOPIC**: `/margin/fundingBook` + ## [1.0.9] - 2024-05-30 ### Added APIs diff --git a/README.md b/README.md index e17c886..5ece0c8 100644 --- a/README.md +++ b/README.md @@ -246,6 +246,34 @@ Signature is not required for this part - [x] getRedemptionOrdersV3 - [x] updatePurchaseOrderInterestRateV3 +- [x] getCrossMarginTradingPairs +- [x] updateLeverageMultiplier +- [x] placeHfMarginOrder +- [x] testHfMarginOrder +- [x] cancelHfMarginOrder +- [x] cancelHfMarginOrderByClientOid +- [x] cancelAllHfMarginOrdersBySymbol +- [x] getActiveHfMarginOrders +- [x] getFilledHfMarginOrders +- [x] getHfOrderDetails +- [x] getHfOrderDetailsByClientOid +- [x] getHfTransactionRecords +- [x] getActiveHfOrderSymbols +#### Rest/Earn/General +- [x] subscribeToEarnFixedIncomeProducts +- [x] redeemByEarnHoldingId +- [x] getEarnRedeemPreviewByHoldingId +#### Rest/Earn/KucoinEarn +- [x] getEarnSavingsProducts +- [x] getEarnFixedIncomeCurrentHoldings +- [x] getEarnPromotionProducts +#### Rest/Earn/Staking +- [x] getKcsStakingProducts +- [x] getEarnStakingProducts +- [x] getEthStakingProducts +#### Rest/VIPLending +- [x] getOtcLoanInformation +- [x] getOtcLoanAccounts #### Rest/Others - [x] getTimestamp - [x] getStatus diff --git a/demo/constants.js b/demo/constants.js index 9dfd73d..5788507 100644 --- a/demo/constants.js +++ b/demo/constants.js @@ -1,3 +1,11 @@ +/* + * @Owner: gannicus.zhou@kupotech.com + * @Date: 2024-01-04 15:31:20 + * @LastEditors: gannicus Gannicus.Zhou@kupotech.com + * @LastEditTime: 2024-07-12 09:52:24 + * @FilePath: /kucoin-node-sdk/demo/constants.js + * @Description: + */ const tickerTopics = { 'symbolTicker':"/market/ticker:BTC-USDT", 'allSymbolsTicker':"/market/ticker:all", @@ -21,8 +29,12 @@ const priceTopics = { "indexPrice" :"/indicator/index:USDT-BTC", "markPrice" :"/indicator/markPrice:USDT-BTC" } +//orderBookChange deprecated const orderBookTopics = { - "orderBookChange":"/margin/fundingBook:BTC" + "orderBookChange":"/margin/fundingBook:BTC" +} +const isolatedTopics = { + "isolatedPosition":"/margin/isolatedPosition:BTC-USDT" } module.exports = { tickerTopics, @@ -31,5 +43,6 @@ module.exports = { klineTopics, matchTopics, priceTopics, - orderBookTopics + orderBookTopics, + isolatedTopics } \ No newline at end of file diff --git a/demo/earn.js b/demo/earn.js new file mode 100644 index 0000000..2a6ba82 --- /dev/null +++ b/demo/earn.js @@ -0,0 +1,208 @@ +/* + * @Owner: gannicus.zhou@kupotech.com + * @Date: 2024-07-10 11:12:57 + * @LastEditors: gannicus Gannicus.Zhou@kupotech.com + * @LastEditTime: 2024-07-12 17:43:28 + * @FilePath: /kucoin-node-sdk/demo/earn.js + * @Description: + */ +const API = require("../src"); + +API.init(require("./config")); + +const earnMain = async () => { + const getTimestampRl = await API.rest.Others.getTimestamp(); + console.log(getTimestampRl.data); + + /** + * @name demoSubscribeToEarnFixedIncomeProducts + * @description Demo function to subscribe to fixed income products + * @updateTime 07/12/24 + */ + async function demoSubscribeToEarnFixedIncomeProducts() { + try { + const result = + await API.rest.Earn.General.subscribeToEarnFixedIncomeProducts({ + productId: "12345", // Example product ID + amount: "1000", // Example subscription amount + accountType: "MAIN", // Example account type + }); + console.log("Subscription successful:", result); + } catch (error) { + console.error( + "Error subscribing to fixed income products:", + error.message + ); + } + } + + demoSubscribeToEarnFixedIncomeProducts(); + + /** + * @name demoRedeemByEarnHoldingId + * @description Demo function to initiate redemption by holding ID + * @updateTime 07/12/24 + */ + async function demoRedeemByEarnHoldingId() { + try { + const result = await API.rest.Earn.General.redeemByEarnHoldingId({ + orderId: "13100", // Example holding ID + amount: "1", // Example redemption amount + fromAccountType: "MAIN", // Example account type (optional) + confirmPunishRedeem: "1", // Example confirmation for early redemption penalty (optional) + }); + console.log("Redemption successful:", result); + } catch (error) { + console.error("Error initiating redemption:", error.message); + } + } + + demoRedeemByEarnHoldingId(); + + /** + * @name demoGetEarnRedeemPreviewByHoldingId + * @description Demo function to get redemption preview information by holding ID + * @updateTime 07/12/24 + */ + async function demoGetEarnRedeemPreviewByHoldingId() { + try { + const result = + await API.rest.Earn.General.getEarnRedeemPreviewByHoldingId({ + orderId: "13100", // Example holding ID + fromAccountType: "MAIN", // Example account type (optional) + }); + + console.log("Redemption Preview Information:", result); + } catch (error) { + console.error( + "Error fetching redemption preview information:", + error.message + ); + } + } + + demoGetEarnRedeemPreviewByHoldingId(); + + /** + * @name demoGetEarnSavingsProducts + * @description Demo function to get savings products + * @updateTime 07/12/24 + */ + + async function demoGetEarnSavingsProducts() { + try { + const result = await API.rest.Earn.KucoinEarn.getEarnSavingsProducts({ + currency: "USDT", // Example currency (optional) + }); + + console.log("Savings Products:", result); + } catch (error) { + console.error("Error fetching savings products:", error.message); + } + } + + demoGetEarnSavingsProducts(); + + /** + * @name demoGetEarnFixedIncomeCurrentHoldings + * @description Demo function to get current holding assets of fixed income products + * @updateTime 07/12/24 + */ + + async function demoGetEarnFixedIncomeCurrentHoldings() { + try { + const result = + await API.rest.Earn.KucoinEarn.getEarnFixedIncomeCurrentHoldings({ + currentPage: 1, // Example page number (optional) + pageSize: 20, // Example page size (optional) + productId: "1", // Example product ID (optional) + productCategory: "STAKING", // Example product category (optional) + currency: "ATOM", // Example subscription currency (optional) + }); + + console.log("Current Holdings:", result); + } catch (error) { + console.error("Error fetching current holdings:", error.message); + } + } + + demoGetEarnFixedIncomeCurrentHoldings(); + + /** + * @name demoGetEarnPromotionProducts + * @description Demo function to get limited-time promotion products + * @updateTime 07/12/24 + */ + async function demoGetEarnPromotionProducts() { + try { + const result = await API.rest.Earn.KucoinEarn.getEarnPromotionProducts({ + currency: "USDT", // Example currency (optional) + }); + + console.log("Promotion Products:", result); + } catch (error) { + console.error("Error fetching promotion products:", error.message); + } + } + + demoGetEarnPromotionProducts(); + + /** + * @name demoGetKcsStakingProducts + * @description Demo function to get KCS Staking products + * @updateTime 07/12/24 + */ + async function demoGetKcsStakingProducts() { + try { + const result = await API.rest.Earn.Staking.getKcsStakingProducts({ + currency: "KCS", // Example currency (optional) + }); + + console.log("KCS Staking Products:", result); + } catch (error) { + console.error("Error fetching KCS Staking products:", error.message); + } + } + + demoGetKcsStakingProducts(); + + /** + * @name demoGetEarnStakingProducts + * @description Demo function to get staking products + * @updateTime 07/12/24 + */ + + async function demoGetEarnStakingProducts() { + try { + const result = await API.rest.Earn.Staking.getEarnStakingProducts({ + currency: "USDT", // Example currency (optional) + }); + + console.log("Staking Products:", result); + } catch (error) { + console.error("Error fetching staking products:", error.message); + } + } + + demoGetEarnStakingProducts(); + + /** + * @name demoGetEthStakingProducts + * @description Demo function to get ETH Staking products + * @updateTime 07/12/24 + */ + async function demoGetEthStakingProducts() { + try { + const result = await API.rest.Earn.Staking.getEthStakingProducts(); + + console.log("ETH Staking Products:", result); + } catch (error) { + console.error("Error fetching ETH Staking products:", error.message); + } + } + + demoGetEthStakingProducts(); +}; + +// run rest earnMain +earnMain(); diff --git a/demo/margin.js b/demo/margin.js index 61cd632..2048448 100644 --- a/demo/margin.js +++ b/demo/margin.js @@ -31,7 +31,9 @@ const marginMain = async () => { }; // Call the borrowMargin function with the requestData object - const response = await API.rest.Margin.MarginV3.marginBorrowV3(requestData); + const response = await API.rest.Margin.MarginV3.marginBorrowV3( + requestData + ); // Log the response from the API console.log("Borrow Margin Response:", response); @@ -305,11 +307,12 @@ const marginMain = async () => { */ async function getRedemptionOrdersV3() { try { - const result = await API.rest.Margin.MarginV3.updatePurchaseOrderInterestRateV3({ - currency: "BTC", - purchaseOrderNo: "5da6dba0f943c0c81f5d5db5", - interestRate: "0.05", // Updated interest rate - }); + const result = + await API.rest.Margin.MarginV3.updatePurchaseOrderInterestRateV3({ + currency: "BTC", + purchaseOrderNo: "5da6dba0f943c0c81f5d5db5", + interestRate: "0.05", // Updated interest rate + }); console.log("purchaseOrderNo number:", result.data.purchaseOrderNo); } catch (error) { console.error("Error fetching purchaseOrderNo:", error.message); @@ -317,6 +320,316 @@ const marginMain = async () => { } getRedemptionOrdersV3(); + + /** + * @name demoGetCrossMarginTradingPairs + * @description Demo function to get the configuration of cross margin trading pairs + * @updateTime 05/29/24 + */ + async function demoGetCrossMarginTradingPairs() { + try { + const result = + await API.rest.Margin.MarginV3.getCrossMarginTradingPairs(); + + console.log("Cross Margin Trading Pairs Configuration:", result); + } catch (error) { + console.error( + "Error fetching cross margin trading pairs configuration:", + error.message + ); + } + } + + demoGetCrossMarginTradingPairs(); + + /** + * @name demoUpdateLeverageMultiplier + * @description Demo function to modify the leverage multiplier + * @updateTime 05/29/24 + */ + async function demoUpdateLeverageMultiplier() { + try { + await API.rest.Margin.MarginV3.updateLeverageMultiplier({ + leverage: "5.00", // New leverage multiplier + + symbol: "BTC-USDT", // Specify for isolated margin + + isIsolated: true, // Set to true for isolated margin + }); + + console.log("Leverage multiplier updated successfully."); + } catch (error) { + console.error("Error updating leverage multiplier:", error.message); + } + } + + demoUpdateLeverageMultiplier(); + + /** + * @name demoPlaceHfMarginOrder + * @description Demo function to place a high-frequency margin trading order + * @updateTime 05/29/24 + */ + async function demoPlaceHfMarginOrder() { + try { + const orderDetails = { + clientOid: "unique-order-id-12345", + side: "buy", + symbol: "BTC-USDT", + type: "limit", + price: "30000", + size: "0.01", + isIsolated: false, + autoBorrow: true, + autoRepay: true, + }; + + const result = await API.rest.Margin.MarginV3.placeHfMarginOrder( + orderDetails + ); + + console.log("Order placed successfully:", result); + } catch (error) { + console.error("Error placing order:", error.message); + } + } + + demoPlaceHfMarginOrder(); + + /** + * @name demoTestHfMarginOrder + * @description Demo function to test placing a high-frequency margin trading order + * @updateTime 05/29/24 + */ + async function demoTestHfMarginOrder() { + try { + const orderDetails = { + clientOid: "unique-order-id-12345", + side: "buy", + symbol: "BTC-USDT", + type: "limit", + price: "30000", + size: "0.01", + isIsolated: false, + autoBorrow: true, + autoRepay: true, + }; + + const result = await API.rest.Margin.MarginV3.testHfMarginOrder( + orderDetails + ); + + console.log("Order test successful:", result); + } catch (error) { + console.error("Error testing order:", error.message); + } + } + + demoTestHfMarginOrder(); + + /** + * @name demoCancelHfMarginOrder + * @description Demo function to cancel a high-frequency margin trading order by orderId + * @updateTime 05/29/24 + */ + async function demoCancelHfMarginOrder() { + try { + const orderId = "5bd6e9286d99522a52e458de"; + const symbol = "ETH-BTC"; + const result = await API.rest.Margin.MarginV3.cancelHfMarginOrder( + orderId, + symbol + ); + + console.log("Order canceled successfully:", result); + } catch (error) { + console.error("Error canceling order:", error.message); + } + } + + demoCancelHfMarginOrder(); + + /** + * @name demoCancelHfMarginOrderByClientOid + * @description Demo function to cancel a high-frequency margin trading order by clientOid + * @updateTime 05/29/24 + */ + async function demoCancelHfMarginOrderByClientOid() { + try { + const clientOid = "6d539dc614db3"; + + const symbol = "ETH-BTC"; + + const result = + await API.rest.Margin.MarginV3.cancelHfMarginOrderByClientOid( + clientOid, + symbol + ); + + console.log("Order canceled successfully:", result); + } catch (error) { + console.error("Error canceling order:", error.message); + } + } + + demoCancelHfMarginOrderByClientOid(); + + /** + * @name demoCancelAllHfMarginOrdersBySymbol + * @description Demo function to cancel all open high-frequency margin trading orders by symbol + * @updateTime 05/29/24 + */ + async function demoCancelAllHfMarginOrdersBySymbol() { + try { + const symbol = "ETH-BTC"; + const tradeType = "MARGIN_TRADE"; + const result = + await API.rest.Margin.MarginV3.cancelAllHfMarginOrdersBySymbol( + symbol, + tradeType + ); + + console.log("All orders canceled successfully:", result); + } catch (error) { + console.error("Error canceling all orders:", error.message); + } + } + + demoCancelAllHfMarginOrdersBySymbol(); + + /** + * @name demoGetActiveHfMarginOrders + * @description Demo function to get the list of active high-frequency margin trading orders + * @updateTime 05/29/24 + */ + async function demoGetActiveHfMarginOrders() { + try { + const tradeType = "MARGIN_TRADE"; + + const symbol = "BTC-ETH"; + + const result = await API.rest.Margin.MarginV3.getActiveHfMarginOrders( + tradeType, + symbol + ); + + console.log("Active HF Margin Orders:", result); + } catch (error) { + console.error("Error fetching active HF margin orders:", error.message); + } + } + + demoGetActiveHfMarginOrders(); + + /** + * @name demoGetFilledHfMarginOrders + * @description Demo function to get the list of filled high-frequency margin trading orders + * @updateTime 05/29/24 + */ + async function demoGetFilledHfMarginOrders() { + try { + const params = { + tradeType: "MARGIN_TRADE", + symbol: "BTC-ETH", + side: "buy", + type: "limit", + startAt: Date.now() - 24 * 60 * 60 * 1000, // 24 hours ago + endAt: Date.now(), + }; + + const result = await API.rest.Margin.MarginV3.getFilledHfMarginOrders( + params + ); + + console.log("Filled HF Margin Orders:", result); + } catch (error) { + console.error("Error fetching filled HF margin orders:", error.message); + } + } + + demoGetFilledHfMarginOrders(); + + /** + * @name demoGetHfOrderDetails + * @description Demo function to call getHfOrderDetails and log the result + * @updateTime 10/05/23 + */ + async function demoGetHfOrderDetails() { + try { + const result = await API.rest.Margin.MarginV3.getHfOrderDetails({ + orderId: "5c35c02703aa673ceec2a168", + symbol: "ETH-BTC", + }); + + console.log("HF Order Details:", result); + } catch (error) { + console.error("Error fetching HF order details:", error.message); + } + } + + demoGetHfOrderDetails(); + + /** + * @name demoGetHfOrderDetailsByClientOid + * @description Demo function to call getHfOrderDetailsByClientOid and log the result + * @updateTime 10/05/23 + */ + async function demoGetHfOrderDetailsByClientOid() { + try { + const result = await API.rest.Margin.MarginV3.getHfOrderDetailsByClientOid({ + clientOid: "6d539dc614db312", + symbol: "ETH-BTC", + }); + + console.log("HF Order Details by Client OID:", result); + } catch (error) { + console.error( + "Error fetching HF order details by clientOid:", + error.message + ); + } + } + + demoGetHfOrderDetailsByClientOid(); + /** + * @name demoGetHfTransactionRecords + * @description Demo function to call getHfTransactionRecords and log the result + * @updateTime 10/05/23 + */ + async function demoGetHfTransactionRecords() { + try { + const result = await API.rest.Margin.MarginV3.getHfTransactionRecords({ + symbol: "BTC-USDT", + tradeType: "MARGIN_TRADE", + limit: 5, + }); + + console.log("HF Transaction Records:", result); + } catch (error) { + console.error("Error fetching HF transaction records:", error.message); + } + } + + demoGetHfTransactionRecords(); + + /** + * @name demoGetActiveHfOrderSymbols + * @description Demo function to call getActiveHfOrderSymbols and log the result + * @updateTime 10/05/23 + */ + async function demoGetActiveHfOrderSymbols() { + try { + const result = await API.rest.Margin.MarginV3.getActiveHfOrderSymbols({ + tradeType: "MARGIN_TRADE", + }); + + console.log("Active HF Order Symbols:", result); + } catch (error) { + console.error("Error fetching active HF order symbols:", error.message); + } + } + + demoGetActiveHfOrderSymbols(); }; // run rest marginMain diff --git a/demo/vip_lending.js b/demo/vip_lending.js new file mode 100644 index 0000000..f908bb3 --- /dev/null +++ b/demo/vip_lending.js @@ -0,0 +1,51 @@ +/* + * @Owner: gannicus.zhou@kupotech.com + * @Date: 2024-07-10 11:12:57 + * @LastEditors: gannicus Gannicus.Zhou@kupotech.com + * @LastEditTime: 2024-07-15 19:56:12 + * @FilePath: /kucoin-node-sdk/demo/vip_lending.js + * @Description: + */ +const API = require("../src"); + +API.init(require("./config")); + +const vipLendingMain = async () => { + /** + * @name demoGetOtcLoanInformation + * @description Demo function to get information on off-exchange funding and loans + * @updateTime 07/12/24 + */ + async function demoGetOtcLoanInformation() { + try { + const result = await API.rest.VIPLending.OtcLoan.getOtcLoanInformation(); + + console.log("OTC Loan Information:", result); + } catch (error) { + console.error("Error fetching OTC loan information:", error.message); + } + } + + demoGetOtcLoanInformation(); + + /** + * @name getOtcLoanAccounts + * @description Get information on accounts involved in off-exchange loans + * @updateTime 10/05/23 + * @return {Object} The information on accounts involved in off-exchange loans + */ + async function fetchOtcLoanAccounts() { + try { + const result = await API.rest.VIPLending.OtcLoan.getOtcLoanAccounts(); + + console.log("OTC Loan Accounts Information:", result); + } catch (error) { + console.error("Error fetching OTC loan accounts:", error.message); + } + } + + fetchOtcLoanAccounts(); +}; + +// run rest vipLendingMain +vipLendingMain(); diff --git a/demo/websocket/margin.js b/demo/websocket/margin.js new file mode 100644 index 0000000..20cb3e2 --- /dev/null +++ b/demo/websocket/margin.js @@ -0,0 +1,74 @@ +/* + * @Owner: gannicus.zhou@kupotech.com + * @Date: 2024-07-10 17:16:36 + * @LastEditors: gannicus Gannicus.Zhou@kupotech.com + * @LastEditTime: 2024-07-12 17:47:19 + * @FilePath: /kucoin-node-sdk/demo/websocket/margin.js + * @Description: + */ +const API = require("../../src"); + +const { isolatedTopics } = require("../constants"); + +API.init(require("../config")); + +const datafeed = new API.websocket.Datafeed(); + +// close callback + +datafeed.onClose(() => { + console.log("ws closed, status ", datafeed.trustConnected); +}); + +// connect + +datafeed.connectSocket(); + +/** + * @name isolatedPositionTopic + * @description Isoleted Margin Position Event + * @updateTime + * @return {Object} + * { + * "topic": "/margin/isolatedPosition:BTC-USDT", + * "type": "message", + * "data": { + * "tag": "BTC-USDT", + * "status": "CLEAR", // Position status + * "accumulatedPrincipal": "9.9778022", // Accumulated principal + * "changeAssets": { + * "BTC": { + * "total": "0.00001", // Total assets + * "hold": "0", // Freeze assets + * "liabilityPrincipal": "0", // Liability principal + * "liabilityInterest": "0" // Debt interest + * }, + * "USDT": { + * "total": "9", // Total assets + * "hold": "0", // Freeze assets + * "liabilityPrincipal": "0", // Liability principal + * "liabilityInterest": "0" // Debt interest + * } + * }, + * "timestamp": 1714446276318 // Timestamp (milliseconds) + * }, + * "subject": "positionChange", + * "channelType": "private" + * } + */ + +const isolatedPositionTopic = isolatedTopics.isolatedPosition; + +const callbackId = datafeed.subscribe(isolatedPositionTopic, (message) => { + if (message.topic === isolatedPositionTopic) { + console.log(message.data); + } +}); + +// cancel + +setTimeout(() => { + datafeed.unsubscribe(isolatedPositionTopic, callbackId); + + console.log(`unsubscribed: ${isolatedPositionTopic} ${callbackId}`); +}, 5000); diff --git a/package.json b/package.json index 1ff020c..a1b2684 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kucoin-node-sdk", - "version": "1.0.9", + "version": "1.1.0", "description": "KuCoin API SDK for Node.js language", "main": "src/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 4f688e8..b03cc22 100644 --- a/src/index.js +++ b/src/index.js @@ -45,6 +45,14 @@ exports.rest = { Isolated:require('./rest/Margin/Isolated'), MarginV3:require('./rest/Margin/MarginV3'), }, + Earn: { + General: require('./rest/Earn/General'), + KucoinEarn: require('./rest/Earn/KucoinEarn'), + Staking:require('./rest/Earn/Staking'), + }, + VIPLending: { + OtcLoan:require('./rest/VIPLending'), + }, Others: require('./rest/Others'), }; diff --git a/src/rest/Earn/General.js b/src/rest/Earn/General.js new file mode 100644 index 0000000..4a17f5f --- /dev/null +++ b/src/rest/Earn/General.js @@ -0,0 +1,88 @@ +/* + * @Owner: gannicus.zhou@kupotech.com + * @Date: 2024-07-09 17:00:23 + * @LastEditors: gannicus Gannicus.Zhou@kupotech.com + * @LastEditTime: 2024-07-15 15:55:01 + * @FilePath: /kucoin-node-sdk/src/rest/Earn/General.js + * @Description: + */ +const Http = require("../../lib/http"); + +/** + * @name subscribeToEarnFixedIncomeProducts + * @description Subscribe to fixed income products + * @updateTime 07/12/24 + * @param {String} productId - Product ID (Mandatory) + * @param {String} amount - Subscription amount (Mandatory) + * @param {String} accountType - Account type: MAIN (funding account), TRADE (trading account) (Mandatory) + * @return {Object} - The response containing orderId and orderTxId + */ + +exports.subscribeToEarnFixedIncomeProducts = + async function subscribeToEarnFixedIncomeProducts({ + productId, + amount, + accountType, + }) { + const response = await Http().POST("/api/v1/earn/orders", { + productId, + + amount, + + accountType, + }); + + return response.data; + }; + +/** + * @name redeemByEarnHoldingId + * @description Initiate redemption by holding ID + * @updateTime 07/12/24 + * @param {String} orderId - Holding ID (Mandatory) + * @param {String} amount - Redemption amount (Mandatory) + * @param {String} [fromAccountType] - Account type: MAIN (funding account), TRADE (spot trading account). This parameter is valid only when orderId=ETH2 (Optional) + * @param {String} [confirmPunishRedeem] - Confirmation field for early redemption penalty: 1 (confirm early redemption, and the current holding will be fully redeemed). This parameter is valid only for fixed-term products (Optional) + * @return {Object} - The response containing orderTxId, deliverTime, status, and amount + */ +exports.redeemByEarnHoldingId = async function redeemByEarnHoldingId({ + orderId, + amount, + fromAccountType, + confirmPunishRedeem, +}) { + const params = { + orderId, + amount, + ...(fromAccountType && { fromAccountType }), + ...(confirmPunishRedeem && { confirmPunishRedeem }), + }; + + const response = await Http().DEL("/api/v1/earn/orders", { params }); + + return response.data; +}; + +/** + + * @name getEarnRedeemPreviewByHoldingId + * @description Get redemption preview information by holding ID + * @updateTime 07/12/24 + * @param {String} orderId - Holding ID (Mandatory) + * @param {String} [fromAccountType] - Account type: MAIN (funding account), TRADE (spot trading account). This parameter is valid only when orderId=ETH2 (Optional) + * @return {Object} - The response containing redemption preview information + */ + +exports.getEarnRedeemPreviewByHoldingId = + async function getEarnRedeemPreviewByHoldingId({ orderId, fromAccountType }) { + const params = { + orderId, + ...(fromAccountType && { fromAccountType }), + }; + + const response = await Http().GET("/api/v1/earn/redeem-preview", { + params, + }); + + return response.data; + }; diff --git a/src/rest/Earn/KucoinEarn.js b/src/rest/Earn/KucoinEarn.js new file mode 100644 index 0000000..e700977 --- /dev/null +++ b/src/rest/Earn/KucoinEarn.js @@ -0,0 +1,81 @@ +/* + * @Owner: gannicus.zhou@kupotech.com + * @Date: 2024-07-09 17:00:23 + * @LastEditors: gannicus Gannicus.Zhou@kupotech.com + * @LastEditTime: 2024-07-12 17:41:01 + * @FilePath: /kucoin-node-sdk/src/rest/Earn/KucoinEarn.js + * @Description: + */ +const Http = require("../../lib/http"); + +/** + * @name getEarnSavingsProducts + * @description Get savings products + * @updateTime 07/12/24 + * @param {String} [currency] - Subscription currency (Optional) + * @return {Object} - The response containing the list of savings products + */ +exports.getEarnSavingsProducts = async function getEarnSavingsProducts({ + currency, +}) { + const params = currency ? { currency } : {}; + + const response = await Http().GET("/api/v1/earn/saving/products", { params }); + + return response.data; +}; + +/** + * @name getEarnFixedIncomeCurrentHoldings + * @description Get current holding assets of fixed income products + * @updateTime 07/12/24 + * @param {Number} [currentPage=1] - Page number (Optional, default is 1) + * @param {Number} [pageSize=20] - Number of items per page (Optional, default is 20) + * @param {String} [productId] - Product ID (Optional) + * @param {String} [productCategory] - Product category (Optional) + * @param {String} [currency] - Subscription currency (Optional) + * @return {Object} - The response containing the list of current holdings + */ +exports.getEarnFixedIncomeCurrentHoldings = + async function getEarnFixedIncomeCurrentHoldings({ + currentPage = 1, + pageSize = 20, + productId, + productCategory, + currency, + }) { + const params = { + currentPage, + + pageSize, + + ...(productId && { productId }), + + ...(productCategory && { productCategory }), + + ...(currency && { currency }), + }; + + const response = await Http().GET("/api/v1/earn/hold-assets", { params }); + + return response.data; + }; + +/** + * @name getEarnPromotionProducts + * @description Get limited-time promotion products + * @updateTime 07/12/24 + * @param {String} [currency] - Subscription currency (Optional) + * @return {Object} - The response containing the list of promotion products + */ +exports.getEarnPromotionProducts = async function getEarnPromotionProducts({ + currency, +}) { + const params = currency ? { currency } : {}; + + const response = await Http().GET("/api/v1/earn/promotion/products", { + params, + }); + + return response.data; +}; diff --git a/src/rest/Earn/Staking.js b/src/rest/Earn/Staking.js new file mode 100644 index 0000000..5ea050c --- /dev/null +++ b/src/rest/Earn/Staking.js @@ -0,0 +1,61 @@ +/* + * @Owner: gannicus.zhou@kupotech.com + * @Date: 2024-07-10 11:40:45 + * @LastEditors: gannicus Gannicus.Zhou@kupotech.com + * @LastEditTime: 2024-07-15 15:56:04 + * @FilePath: /kucoin-node-sdk/src/rest/Earn/Staking.js + * @Description: + */ +const Http = require("../../lib/http"); + +/** + * @name getKcsStakingProducts + * @description Get KCS Staking products + * @updateTime 07/12/24 + * @param {String} [currency] - Subscription currency (Optional) + * @return {Object} - The response containing the list of KCS Staking products + */ +exports.getKcsStakingProducts = async function getKcsStakingProducts({ + currency, +}) { + const params = currency ? { currency } : {}; + + const response = await Http().GET("/api/v1/earn/kcs-staking/products", { + params, + }); + + return response.data; +}; + +/** + * @name getEarnStakingProducts + * @description Get staking products + * @updateTime 07/12/24 + * @param {String} [currency] - Subscription currency (Optional) + * @return {Object} - The response containing the list of staking products + */ + +exports.getEarnStakingProducts = async function getEarnStakingProducts({ + currency, +}) { + const params = currency ? { currency } : {}; + + const response = await Http().GET("/api/v1/earn/staking/products", { + params, + }); + + return response.data; +}; + +/** + + * @name getEthStakingProducts + * @description Get ETH Staking products + * @updateTime 07/12/24 + * @return {Object} - The response containing the list of ETH Staking products + */ +exports.getEthStakingProducts = async function getEthStakingProducts() { + const response = await Http().GET("/api/v1/earn/eth-staking/products"); + + return response.data; +}; diff --git a/src/rest/Margin/MarginV3.js b/src/rest/Margin/MarginV3.js index 170a754..bb4b259 100644 --- a/src/rest/Margin/MarginV3.js +++ b/src/rest/Margin/MarginV3.js @@ -1,4 +1,4 @@ -const Http = require("../../lib/http"); +const Http = require('../../lib/http'); /** * @name marginBorrowV3 * @description Initiates a margin borrow request for either cross-margin or isolated margin. @@ -27,7 +27,7 @@ exports.marginBorrowV3 = async function marginBorrowV3({ }; if (isIsolated && !symbol) { - throw new Error("Symbol is required for isolated margin accounts."); + throw new Error('Symbol is required for isolated margin accounts.'); } if (isIsolated) { @@ -35,146 +35,219 @@ exports.marginBorrowV3 = async function marginBorrowV3({ } try { - return await Http().POST("/api/v3/margin/borrow", payload); + return await Http().POST('/api/v3/margin/borrow', payload); } catch (error) { - console.error("Error borrowing margin:", error); + console.error('Error borrowing margin:', error); throw error; } }; - /** -* @name getBorrowHistory -* @description Request via this endpoint to retrieve the borrowing history for both isolated and cross-margin accounts. -* @updateTime 05/29/24 -* @param {String} currency - Currency (Mandatory) -* @param {Boolean} isIsolated - true for isolated margin, false for cross-margin (Optional, default: false) -* @param {String} symbol - Trading pair (required for isolated margin accounts) -* @param {String} orderNo - Order ID (Optional) -* @param {Long} startTime - Start time (Optional) -* @param {Long} endTime - End time (Optional) -* @param {Int} currentPage - Current page for query (starting from 1, default: 1) -* @param {Int} pageSize - Records per page (default: 50, minimum: 10, maximum: 500) -* @return {Object} { orderNo, symbol, currency, size, actualSize, status, createdTime } -*/ -exports.getBorrowHistoryV3 = async function getBorrowHistoryV3({ currency, isIsolated, symbol, orderNo, startTime, endTime, currentPage, pageSize }) { + * @name getBorrowHistory + * @description Request via this endpoint to retrieve the borrowing history for both isolated and cross-margin accounts. + * @updateTime 07/12/24 + * @param {String} currency - Currency (Mandatory) + * @param {Boolean} isIsolated - true for isolated margin, false for cross-margin (Optional, default: false) + * @param {String} symbol - Trading pair (required for isolated margin accounts) + * @param {String} orderNo - Order ID (Optional) + * @param {Long} startTime - Start time (Optional) + * @param {Long} endTime - End time (Optional) + * @param {Int} currentPage - Current page for query (starting from 1, default: 1) + * @param {Int} pageSize - Records per page (default: 50, minimum: 10, maximum: 500) + * @return {Object} { orderNo, symbol, currency, size, actualSize, status, createdTime } + */ +exports.getBorrowHistoryV3 = async function getBorrowHistoryV3({ + currency, + isIsolated, + symbol, + orderNo, + startTime, + endTime, + currentPage, + pageSize, +}) { return await Http().GET('/api/v3/margin/borrow', { - currency, isIsolated, symbol, orderNo, startTime, endTime, currentPage, pageSize + currency, + isIsolated, + symbol, + orderNo, + startTime, + endTime, + currentPage, + pageSize, }); -} - -/** -* @name repayMarginLoan -* @description Request via this endpoint to initiate a repayment application for either cross-margin or isolated margin accounts. -* @updateTime 05/29/24 -* @param {Boolean} isIsolated - true for isolated margin, false for cross-margin (Optional, default: false) -* @param {Boolean} isHf - High-frequency repayment (true) or low-frequency repayment (false, default) (Optional) -* @param {String} symbol - Trading pair (required for isolated margin accounts) -* @param {String} currency - Currency (Mandatory) -* @param {BigDecimal} size - Repayment amount (Mandatory) -* @return {Object} { orderNo, actualSize } -*/ -exports.repayMarginLoanV3 = async function repayMarginLoanV3({ isIsolated, isHf, symbol, currency, size }) { +}; + +/** + * @name repayMarginLoan + * @description Request via this endpoint to initiate a repayment application for either cross-margin or isolated margin accounts. + * @updateTime 05/29/24 + * @param {Boolean} isIsolated - true for isolated margin, false for cross-margin (Optional, default: false) + * @param {Boolean} isHf - High-frequency repayment (true) or low-frequency repayment (false, default) (Optional) + * @param {String} symbol - Trading pair (required for isolated margin accounts) + * @param {String} currency - Currency (Mandatory) + * @param {BigDecimal} size - Repayment amount (Mandatory) + * @return {Object} { orderNo, actualSize } + */ +exports.repayMarginLoanV3 = async function repayMarginLoanV3({ + isIsolated, + isHf, + symbol, + currency, + size, +}) { return await Http().POST('/api/v3/margin/repay', { - isIsolated, isHf, symbol, currency, size + isIsolated, + isHf, + symbol, + currency, + size, }); -} - -/** -* @name getRepayHistory -* @description Request via this endpoint to query the repayment history for both cross-margin and isolated margin accounts. -* @updateTime 05/29/24 -* @param {String} currency - Currency (Mandatory) -* @param {Boolean} isIsolated - true for isolated margin, false for cross-margin (Optional, default: false) -* @param {String} symbol - Trading pair (required for isolated margin accounts) -* @param {String} orderNo - Order ID (Optional) -* @param {Long} startTime - Start time (Optional) -* @param {Long} endTime - End time (Optional) -* @param {Int} currentPage - Current page for query (starting from 1, default: 1) -* @param {Int} pageSize - Records per page (default: 50, minimum: 10, maximum: 500) -* @return {Object} { orderNo, symbol, currency, size, principal, interest, status, createdTime } -*/ -exports.getRepayHistoryV3 = async function getRepayHistoryV3({ currency, isIsolated, symbol, orderNo, startTime, endTime, currentPage, pageSize }) { +}; + +/** + * @name getRepayHistory + * @description Request via this endpoint to query the repayment history for both cross-margin and isolated margin accounts. + * @updateTime 05/29/24 + * @param {String} currency - Currency (Mandatory) + * @param {Boolean} isIsolated - true for isolated margin, false for cross-margin (Optional, default: false) + * @param {String} symbol - Trading pair (required for isolated margin accounts) + * @param {String} orderNo - Order ID (Optional) + * @param {Long} startTime - Start time (Optional) + * @param {Long} endTime - End time (Optional) + * @param {Int} currentPage - Current page for query (starting from 1, default: 1) + * @param {Int} pageSize - Records per page (default: 50, minimum: 10, maximum: 500) + * @return {Object} { orderNo, symbol, currency, size, principal, interest, status, createdTime } + */ +exports.getRepayHistoryV3 = async function getRepayHistoryV3({ + currency, + isIsolated, + symbol, + orderNo, + startTime, + endTime, + currentPage, + pageSize, +}) { return await Http().GET('/api/v3/margin/repay', { - currency, isIsolated, symbol, orderNo, startTime, endTime, currentPage, pageSize + currency, + isIsolated, + symbol, + orderNo, + startTime, + endTime, + currentPage, + pageSize, }); -} - -/** -* @name getMarginInterestRecords -* @description Request via this endpoint to retrieve the borrowing interest records for both cross-margin and isolated margin accounts. -* @updateTime 05/29/24 -* @param {Boolean} isIsolated - true for isolated margin, false for cross-margin (Optional, default: false) -* @param {String} symbol - Trading pair (required for isolated margin accounts) -* @param {String} currency - Currency (Optional) -* @param {Long} startTime - Start timestamp (milliseconds) (Optional) -* @param {Long} endTime - End timestamp (milliseconds) (Optional) -* @param {Int} currentPage - Current page for query (starting from 1, default: 1) -* @param {Int} pageSize - Records per page (default: 50, minimum: 10, maximum: 500) -* @return {Object} { currency, dayRatio, interestAmount, createdTime } -*/ -exports.getMarginInterestRecordsV3 = async function getMarginInterestRecordsV3({ isIsolated, symbol, currency, startTime, endTime, currentPage, pageSize }) { +}; + +/** + * @name getMarginInterestRecords + * @description Request via this endpoint to retrieve the borrowing interest records for both cross-margin and isolated margin accounts. + * @updateTime 05/29/24 + * @param {Boolean} isIsolated - true for isolated margin, false for cross-margin (Optional, default: false) + * @param {String} symbol - Trading pair (required for isolated margin accounts) + * @param {String} currency - Currency (Optional) + * @param {Long} startTime - Start timestamp (milliseconds) (Optional) + * @param {Long} endTime - End timestamp (milliseconds) (Optional) + * @param {Int} currentPage - Current page for query (starting from 1, default: 1) + * @param {Int} pageSize - Records per page (default: 50, minimum: 10, maximum: 500) + * @return {Object} { currency, dayRatio, interestAmount, createdTime } + */ +exports.getMarginInterestRecordsV3 = async function getMarginInterestRecordsV3({ + isIsolated, + symbol, + currency, + startTime, + endTime, + currentPage, + pageSize, +}) { return await Http().GET('/api/v3/margin/interest', { - isIsolated, symbol, currency, startTime, endTime, currentPage, pageSize + isIsolated, + symbol, + currency, + startTime, + endTime, + currentPage, + pageSize, }); -} +}; /** -* @name getLendingCurrencyInfo -* @description Request via this endpoint to get information about lending currencies supported in the lending market. -* @updateTime 05/29/24 -* @param {String} currency - Currency (Optional) -* @return {Object} { currency, purchaseEnable, redeemEnable, increment, minPurchaseSize, minInterestRate, maxInterestRate, interestIncrement, maxPurchaseSize, marketInterestRate, autoPurchaseEnable } -*/ -exports.getLendingCurrencyInfoV3 = async function getLendingCurrencyInfoV3({ currency }) { + * @name getLendingCurrencyInfo + * @description Request via this endpoint to get information about lending currencies supported in the lending market. + * @updateTime 05/29/24 + * @param {String} currency - Currency (Optional) + * @return {Object} { currency, purchaseEnable, redeemEnable, increment, minPurchaseSize, minInterestRate, maxInterestRate, interestIncrement, maxPurchaseSize, marketInterestRate, autoPurchaseEnable } + */ +exports.getLendingCurrencyInfoV3 = async function getLendingCurrencyInfoV3({ + currency, +}) { return await Http().GET('/api/v3/project/list', { - currency + currency, }); -} +}; /** -* @name getMarketInterestRate -* @description Request via this endpoint to get the interest rates for the lending market over the last 7 days. -* @updateTime 05/29/24 -* @param {String} currency - Currency (Mandatory) -* @return {Object[]} Array of { time, marketInterestRate } -*/ -exports.getMarketInterestRateV3 = async function getMarketInterestRateV3({ currency }) { + * @name getMarketInterestRate + * @description Request via this endpoint to get the interest rates for the lending market over the last 7 days. + * @updateTime 05/29/24 + * @param {String} currency - Currency (Mandatory) + * @return {Object[]} Array of { time, marketInterestRate } + */ +exports.getMarketInterestRateV3 = async function getMarketInterestRateV3({ + currency, +}) { return await Http().GET('/api/v3/project/marketInterestRate', { - currency + currency, }); -} - -/** -* @name initiatePurchase -* @description Request via this endpoint to initiate a subscription in the lending market. -* @updateTime 05/29/24 -* @param {String} currency - Currency (Mandatory) -* @param {String} size - Subscription amount (Mandatory) -* @param {String} interestRate - Subscription interest rate (Mandatory) -* @return {Object} { orderNo } -*/ -exports.initiatePurchaseV3 = async function initiatePurchaseV3({ currency, size, interestRate }) { +}; + +/** + * @name initiatePurchase + * @description Request via this endpoint to initiate a subscription in the lending market. + * @updateTime 05/29/24 + * @param {String} currency - Currency (Mandatory) + * @param {String} size - Subscription amount (Mandatory) + * @param {String} interestRate - Subscription interest rate (Mandatory) + * @return {Object} { orderNo } + */ +exports.initiatePurchaseV3 = async function initiatePurchaseV3({ + currency, + size, + interestRate, +}) { return await Http().POST('/api/v3/purchase', { - currency, size, interestRate + currency, + size, + interestRate, }); -} - -/** -* @name getPurchaseOrders -* @description Request via this endpoint to retrieve paginated purchase orders in the lending market. -* @updateTime 05/29/24 -* @param {String} currency - Currency (Mandatory) -* @param {String} status - DONE (completed) or PENDING (settling) (Mandatory) -* @param {Int} currentPage - Current page number (Optional, default: 1) -* @param {Int} pageSize - Records per page (Optional, default: 50, minimum: 1, maximum: 100) -* @return {Object[]} Array of { currency, purchaseOrderNo, purchaseSize, matchSize, redeemSize, interestRate, incomeSize, applyTime, status } -*/ -exports.getPurchaseOrdersV3 = async function getPurchaseOrdersV3({ currency, status, currentPage, pageSize }) { +}; + +/** + * @name getPurchaseOrders + * @description Request via this endpoint to retrieve paginated purchase orders in the lending market. + * @updateTime 05/29/24 + * @param {String} currency - Currency (Mandatory) + * @param {String} status - DONE (completed) or PENDING (settling) (Mandatory) + * @param {Int} currentPage - Current page number (Optional, default: 1) + * @param {Int} pageSize - Records per page (Optional, default: 50, minimum: 1, maximum: 100) + * @return {Object[]} Array of { currency, purchaseOrderNo, purchaseSize, matchSize, redeemSize, interestRate, incomeSize, applyTime, status } + */ +exports.getPurchaseOrdersV3 = async function getPurchaseOrdersV3({ + currency, + status, + currentPage, + pageSize, +}) { return await Http().GET('/api/v3/purchase/orders', { - currency, status, currentPage, pageSize + currency, + status, + currentPage, + pageSize, }); -} +}; /** * @name redeemMarket_V3 @@ -185,13 +258,17 @@ exports.getPurchaseOrdersV3 = async function getPurchaseOrdersV3({ currency, sta * @param {String} purchaseOrderNo - Purchase order number (Mandatory) * @return {Object} { code, success, data } */ -exports.redeemMarketV3 = async function redeemMarketV3({ currency, size, purchaseOrderNo }) { +exports.redeemMarketV3 = async function redeemMarketV3({ + currency, + size, + purchaseOrderNo, +}) { return await Http().POST('/api/v3/redeem', { currency, size, - purchaseOrderNo + purchaseOrderNo, }); -} +}; /** * @name getRedemptionOrders_V3 @@ -204,15 +281,21 @@ exports.redeemMarketV3 = async function redeemMarketV3({ currency, size, purchas * @param {Int} pageSize - Page size (Optional, default: 50, range: 1<=pageSize<=100) * @return {Object} { currency, purchaseOrderNo, redeemOrderNo, redeemSize, receiptSize, applyTime, status } */ -exports.getRedemptionOrdersV3 = async function getRedemptionOrdersV3({ currency, redeemOrderNo, status, currentPage, pageSize }) { +exports.getRedemptionOrdersV3 = async function getRedemptionOrdersV3({ + currency, + redeemOrderNo, + status, + currentPage, + pageSize, +}) { return await Http().GET('/api/v3/redeem/orders', { currency, redeemOrderNo, status, currentPage, - pageSize + pageSize, }); -} +}; /** * @name updatePurchaseOrderInterestRate_V3 @@ -223,10 +306,328 @@ exports.getRedemptionOrdersV3 = async function getRedemptionOrdersV3({ currency, * @param {String} interestRate - Updated purchase interest rate (Mandatory) * @return {void} */ -exports.updatePurchaseOrderInterestRateV3 = async function updatePurchaseOrderInterestRateV3({ currency, purchaseOrderNo, interestRate }) { - await Http().POST('/api/v3/lend/purchase/update', { +exports.updatePurchaseOrderInterestRateV3 = + async function updatePurchaseOrderInterestRateV3({ currency, purchaseOrderNo, - interestRate + interestRate, + }) { + await Http().POST('/api/v3/lend/purchase/update', { + currency, + purchaseOrderNo, + interestRate, + }); + }; + +/** + * @name getCrossMarginTradingPairs + * @description Get the configuration of cross margin trading pairs + * @updateTime 07/12/24 + * @param {String} [symbol] - Optional. If not provided, all cross margin trading pairs will be queried. If provided, only the specified trading pair will be queried. + * @return {Object} The configuration of cross margin trading pairs + */ +exports.getCrossMarginTradingPairs = async function getCrossMarginTradingPairs( + symbol +) { + const params = symbol ? { symbol } : {}; + const response = await Http().GET('/api/v3/margin/symbols', { params }); + return response.data; +}; + +/** + * @name updateLeverageMultiplier + * @description Modify the leverage multiplier for cross margin or isolated margin + * @updateTime 07/12/24 + * @param {String} leverage - New leverage multiplier (Mandatory) + * @param {String} [symbol] - Trading pair. Leave empty for cross margin, or specify for isolated margin (Optional) + * @param {boolean} [isIsolated=false] - Whether it is isolated margin. true: yes, false: cross margin. Default: false (Optional) + * @return {void} + */ + +exports.updateLeverageMultiplier = async function updateLeverageMultiplier({ + leverage, + symbol, + isIsolated = false, +}) { + const payload = { + leverage, + + symbol, + + isIsolated, + }; + + await Http().POST('/api/v3/position/update-user-leverage', payload); +}; + +/** + * @name placeHfMarginOrder + * @description Place a high-frequency margin trading order + * @updateTime 07/12/24 + * @param {Object} orderDetails - The details of the order to be placed + * @param {String} orderDetails.clientOid - Client Order Id, unique identifier created by the user + * @param {String} orderDetails.side - Order side, either 'buy' or 'sell' + * @param {String} orderDetails.symbol - Trading pair symbol + * @param {String} [orderDetails.type='limit'] - Order type, either 'limit' or 'market' + * @param {String} [orderDetails.stp] - Self trade prevention strategy + * @param {boolean} [orderDetails.isIsolated=false] - Whether it is isolated margin, default is false (cross margin) + * @param {boolean} [orderDetails.autoBorrow=false] - Whether to auto borrow if balance is insufficient + * @param {boolean} [orderDetails.autoRepay=false] - Whether to auto repay when closing the position + * @param {String} [orderDetails.price] - Price for limit orders + * @param {String} [orderDetails.size] - Quantity for the order + * @param {String} [orderDetails.timeInForce='GTC'] - Order timing strategy, default is 'GTC' + * @param {long} [orderDetails.cancelAfter] - Cancel after n seconds, applicable for 'GTT' orders + * @param {boolean} [orderDetails.postOnly=false] - Whether the order is a passive order + * @param {boolean} [orderDetails.hidden=false] - Whether the order is hidden + * @param {boolean} [orderDetails.iceberg=false] - Whether the order is an iceberg order + * @param {String} [orderDetails.visibleSize] - Maximum visible quantity in iceberg orders + * @param {String} [orderDetails.funds] - Funds for market orders + * @return {Object} The response from the API + */ +exports.placeHfMarginOrder = async function placeHfMarginOrder(orderDetails) { + const response = await Http().POST('/api/v3/hf/margin/order', orderDetails); + + return response.data; +}; + +/** + * @name testHfMarginOrder + * @description Test placing a high-frequency margin trading order + * @updateTime 07/12/24 + * @param {Object} orderDetails - The details of the order to be tested + * @param {String} orderDetails.clientOid - Client Order Id, unique identifier created by the user + * @param {String} orderDetails.side - Order side, either 'buy' or 'sell' + * @param {String} orderDetails.symbol - Trading pair symbol + * @param {String} [orderDetails.type='limit'] - Order type, either 'limit' or 'market' + * @param {String} [orderDetails.stp] - Self trade prevention strategy + * @param {boolean} [orderDetails.isIsolated=false] - Whether it is isolated margin, default is false (cross margin) + * @param {boolean} [orderDetails.autoBorrow=false] - Whether to auto borrow if balance is insufficient + * @param {boolean} [orderDetails.autoRepay=false] - Whether to auto repay when closing the position + * @param {String} [orderDetails.price] - Price for limit orders + * @param {String} [orderDetails.size] - Quantity for the order + * @param {String} [orderDetails.timeInForce='GTC'] - Order timing strategy, default is 'GTC' + * @param {long} [orderDetails.cancelAfter] - Cancel after n seconds, applicable for 'GTT' orders + * @param {boolean} [orderDetails.postOnly=false] - Whether the order is a passive order + * @param {boolean} [orderDetails.hidden=false] - Whether the order is hidden + * @param {boolean} [orderDetails.iceberg=false] - Whether the order is an iceberg order + * @param {String} [orderDetails.visibleSize] - Maximum visible quantity in iceberg orders + * @param {String} [orderDetails.funds] - Funds for market orders + * @return {Object} The response from the API + */ +exports.testHfMarginOrder = async function testHfMarginOrder(orderDetails) { + const response = await Http().POST( + '/api/v3/hf/margin/order/test', + orderDetails + ); + + return response.data; +}; + +/** + * @name cancelHfMarginOrder + * @description Cancel a high-frequency margin trading order by orderId + * @updateTime 07/12/24 + * @param {String} orderId - The unique identifier of the order to be canceled + * @param {String} symbol - The trading pair symbol + * @return {Object} The response from the API + */ +exports.cancelHfMarginOrder = async function cancelHfMarginOrder( + orderId, + symbol +) { + const response = await Http().DEL(`/api/v3/hf/margin/orders/${orderId}`, { + params: { symbol }, }); -} \ No newline at end of file + + return response.data; +}; + +/** + * @name cancelHfMarginOrderByClientOid + * @description Cancel a high-frequency margin trading order by clientOid + * @updateTime 07/12/24 + * @param {String} clientOid - The unique identifier of the order created by the client + * @param {String} symbol - The trading pair symbol + * @return {Object} The response from the API + */ +exports.cancelHfMarginOrderByClientOid = + async function cancelHfMarginOrderByClientOid(clientOid, symbol) { + const response = await Http().DEL( + `/api/v3/hf/margin/orders/client-order/${clientOid}`, + { params: { symbol } } + ); + + return response.data; + }; + +/** + * @name cancelAllHfMarginOrdersBySymbol + * @description Cancel all open high-frequency margin trading orders by symbol + * @updateTime 07/12/24 + * @param {String} symbol - The trading pair symbol + * @param {String} tradeType - Transaction type, either 'MARGIN_TRADE' for cross margin trade or 'MARGIN_ISOLATED_TRADE' for isolated margin trade + * @return {Object} The response from the API + */ +exports.cancelAllHfMarginOrdersBySymbol = + async function cancelAllHfMarginOrdersBySymbol(symbol, tradeType) { + const response = await Http().DEL('/api/v3/hf/margin/orders', { + params: { symbol, tradeType }, + }); + + return response.data; + }; + +/** + * @name getActiveHfMarginOrders + * @description Get the list of active high-frequency margin trading orders + * @updateTime 07/12/24 + * @param {String} tradeType - Order type, either 'MARGIN_TRADE' for cross margin trading order or 'MARGIN_ISOLATED_TRADE' for isolated margin trading order + * @param {String} symbol - The trading pair symbol + * @return {Object} The response from the API + */ +exports.getActiveHfMarginOrders = async function getActiveHfMarginOrders( + tradeType, + symbol +) { + const response = await Http().GET('/api/v3/hf/margin/orders/active', { + params: { tradeType, symbol }, + }); + + return response.data; +}; + +/** + * @name getFilledHfMarginOrders + * @description Get the list of filled high-frequency margin trading orders + * @updateTime 07/12/24 + * @param {String} tradeType - Transaction type, either 'MARGIN_TRADE' for cross margin trade or 'MARGIN_ISOLATED_TRADE' for isolated margin trade + * @param {String} symbol - The trading pair symbol + * @param {String} [side] - Order side, either 'buy' or 'sell' (optional) + * @param {String} [type] - Order type, either 'limit' or 'market' (optional) + * @param {long} [startAt] - Start time in milliseconds (optional) + * @param {long} [endAt] - End time in milliseconds (optional) + * @param {long} [lastId] - The id of the last data item from the previous batch (optional) + * @param {int} [limit=100] - Maximum number of items to return, default is 100, maximum is 200 (optional) + * @return {Object} The response from the API + */ +exports.getFilledHfMarginOrders = async function getFilledHfMarginOrders({ + tradeType, + symbol, + side, + type, + startAt, + endAt, + lastId, + limit = 100, +}) { + const params = { + tradeType, + symbol, + side, + type, + startAt, + endAt, + lastId, + limit, + }; + + const response = await Http().GET('/api/v3/hf/margin/orders/done', { + params, + }); + + return response.data; +}; + +/** + * @name getHfOrderDetails + * @description Get details of a margin HF order by order ID + * @updateTime 07/12/24 + * @param {String} orderId - Order ID (Mandatory) + * @param {String} symbol - Trading pair (Mandatory) + * @return {Object} - The details of the margin HF order + */ +exports.getHfOrderDetails = async function getHfOrderDetails({ + orderId, + symbol, +}) { + if (!orderId || !symbol) { + throw new Error('Both orderId and symbol are required parameters.'); + } + + const response = await Http().GET(`/api/v3/hf/margin/orders/${orderId}`, { + params: { symbol }, + }); + + return response.data; +}; + +/** + * @name getHfOrderDetailsByClientOid + * @description Get details of a margin HF order by clientOid + * @updateTime 07/12/24 + * @param {String} clientOid - Client OID (Mandatory) + * @param {String} symbol - Trading pair (Mandatory) + * @return {Object} - The details of the margin HF order + */ +exports.getHfOrderDetailsByClientOid = + async function getHfOrderDetailsByClientOid({ clientOid, symbol }) { + if (!clientOid || !symbol) { + throw new Error('Both clientOid and symbol are required parameters.'); + } + + const response = await Http().GET( + `/api/v3/hf/margin/orders/client-order/${clientOid}`, + { params: { symbol } } + ); + + return response.data; + }; + +/** + * @name getHfTransactionRecords + * @description Get the latest margin HF transaction details + * @updateTime 07/12/24 + * @param {Object} params - Query parameters + * @param {String} params.symbol - Trading pair (Mandatory) + * @param {String} [params.orderId] - Order ID (Optional) + * @param {String} [params.tradeType] - Trade type: MARGIN_TRADE or MARGIN_ISOLATED_TRADE (Mandatory) + * @param {String} [params.side] - Buy or sell (Optional) + * @param {String} [params.type] - Order type: limit or market (Optional) + * @param {Number} [params.startAt] - Start time in milliseconds (Optional) + * @param {Number} [params.endAt] - End time in milliseconds (Optional) + * @param {Number} [params.lastId] - The ID of the last data item from the previous batch (Optional) + * @param {Number} [params.limit] - Number of records to return, default 100, maximum 200 (Optional) + * @return {Object} - The details of the margin HF transaction records + */ +exports.getHfTransactionRecords = async function getHfTransactionRecords( + params +) { + if (!params.symbol || !params.tradeType) { + throw new Error('Both symbol and tradeType are required parameters.'); + } + + const response = await Http().GET('/api/v3/hf/margin/fills', { params }); + + return response.data; +}; + +/** + * @name getActiveHfOrderSymbols + * @description Get all trading pairs with active orders + * @updateTime 07/12/24 + * @param {String} tradeType - Trade type: MARGIN_TRADE or MARGIN_ISOLATED_TRADE (Mandatory) + * @return {Object} - The list of trading pairs with active orders + */ +exports.getActiveHfOrderSymbols = async function getActiveHfOrderSymbols({ + tradeType, +}) { + if (!tradeType) { + throw new Error('tradeType is a required parameter.'); + } + + const response = await Http().GET('/api/v3/hf/margin/order/active/symbols', { + params: { tradeType }, + }); + + return response.data; +}; diff --git a/src/rest/Trade/OCOOrder.js b/src/rest/Trade/OCOOrder.js index 72a5149..7d4a044 100644 --- a/src/rest/Trade/OCOOrder.js +++ b/src/rest/Trade/OCOOrder.js @@ -47,7 +47,7 @@ exports.placeOrder = async function placeOrder({ * @return {Object} { code, success, data } */ exports.cancelOrder = async function cancelOrder(orderId) { - return await Http().DELETE(`/api/v3/oco/order/${orderId}`); + return await Http().DEL(`/api/v3/oco/order/${orderId}`); }; /** @@ -60,7 +60,7 @@ exports.cancelOrder = async function cancelOrder(orderId) { exports.cancelOrderByClientOid = async function cancelOrderByClientOid( clientOid ) { - return await Http().DELETE(`/api/v3/oco/client-order/${clientOid}`); + return await Http().DEL(`/api/v3/oco/client-order/${clientOid}`); }; /** @@ -72,7 +72,7 @@ exports.cancelOrderByClientOid = async function cancelOrderByClientOid( * @return {Object} { code, success, data } */ exports.cancelAllOrders = async function cancelAllOrders({ orderIds, symbol }) { - return await Http().DELETE("/api/v3/oco/orders", { orderIds, symbol }); + return await Http().DEL("/api/v3/oco/orders", { orderIds, symbol }); }; /** diff --git a/src/rest/Trade/Orders.js b/src/rest/Trade/Orders.js index b2844a4..56d2f76 100644 --- a/src/rest/Trade/Orders.js +++ b/src/rest/Trade/Orders.js @@ -746,7 +746,7 @@ exports.queryHfAutoCancelOrderSetting = async function queryHfAutoCancelOrderSet * @return {Object} { code, success, data } */ exports.cancelAllHfOrders = async function cancelAllHfOrders() { - return await Http().DELETE('/api/v1/hf/orders/cancelAll'); + return await Http().DEL('/api/v1/hf/orders/cancelAll'); } /** diff --git a/src/rest/VIPLending/index.js b/src/rest/VIPLending/index.js new file mode 100644 index 0000000..3d43a68 --- /dev/null +++ b/src/rest/VIPLending/index.js @@ -0,0 +1,38 @@ +/* + * @Owner: gannicus.zhou@kupotech.com + * @Date: 2024-07-10 12:03:22 + * @LastEditors: gannicus Gannicus.Zhou@kupotech.com + * @LastEditTime: 2024-07-12 17:35:37 + * @FilePath: /kucoin-node-sdk/src/rest/VIPLending/index.js + * @Description: + */ +const Http = require('../../lib/http'); + +/** + * @name getOtcLoanInformation + * @description Get information on off-exchange funding and loans + * @updateTime 07/12/24 + * @return {Object} - The response containing loan information + */ +exports.getOtcLoanInformation = async function getOtcLoanInformation() { + const response = await Http().GET('/api/v1/otc-loan/loan'); + return response.data; + } + + /** + * @name getOtcLoanAccounts + * @description Get information on accounts involved in off-exchange loans + * @updateTime 07/12/24 + * @return {Object} The information on accounts involved in off-exchange loans + */ +exports.getOtcLoanAccounts = async function getOtcLoanAccounts() { + const url = '/api/v1/otc-loan/accounts'; + try { + const response = await Http().GET(url); + return response.data; + } catch (error) { + console.error("Error fetching OTC loan accounts:", error.message); + throw error; + } + } + \ No newline at end of file