From 681d63150c733d75a965b05929def4d122334ab8 Mon Sep 17 00:00:00 2001 From: Jerko J <83344666+JJ-Cro@users.noreply.github.com> Date: Tue, 20 Aug 2024 10:30:30 +0200 Subject: [PATCH 1/5] feat(): Added new endpoints, added new params/response types --- .gitignore | 4 +- src/RestClient.ts | 95 ++++++++++++++++++++++++++++++++ src/types/request/futures.ts | 11 ++++ src/types/request/rebate.ts | 10 ++++ src/types/request/wallet.ts | 8 +++ src/types/response/futures.ts | 38 +++++++++++++ src/types/response/rebate.ts | 7 +++ src/types/response/subaccount.ts | 6 ++ src/types/response/wallet.ts | 11 ++++ 9 files changed, 189 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index cece781..70a8ed9 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,6 @@ localtest.sh ws-private-spot-wsapi-performance.ts ws-private-perp-futures-wsapi-readonly.ts -privatetest.ts \ No newline at end of file +privatetest.ts + +privaterepotracker \ No newline at end of file diff --git a/src/RestClient.ts b/src/RestClient.ts index 734d51d..dcd2b9c 100644 --- a/src/RestClient.ts +++ b/src/RestClient.ts @@ -43,6 +43,7 @@ import { SubmitFlashSwapOrderReq, } from './types/request/flashswap.js'; import { + BatchAmendOrderReq, DeleteAllFuturesOrdersReq, GetFuturesAccountBookReq, GetFuturesAutoOrdersReq, @@ -104,6 +105,7 @@ import { GetAgencyTransactionHistoryReq, GetBrokerCommissionHistoryReq, GetBrokerTransactionHistoryReq, + GetPartnerSubordinateListReq, PartnerTransactionReq, } from './types/request/rebate.js'; import { @@ -140,6 +142,7 @@ import { GetSavedAddressReq, GetSmallBalanceHistoryReq, GetWithdrawalDepositRecordsReq, + ListPushOrdersReq, SubmitMainSubTransferReq, SubmitSubToSubTransferReq, SubmitTransferReq, @@ -186,6 +189,7 @@ import { SubmitFlashSwapOrderPreviewResp, } from './types/response/flashswap.js'; import { + BatchAmendOrderResp, DeleteFuturesBatchOrdersResp, FuturesAccount, FuturesAutoDeleveragingHistoryRecord, @@ -256,6 +260,7 @@ import { BrokerCommissionHistoryRecord, BrokerTransactionHistoryRecord, PartnerCommission, + PartnerSubordinateListRecord, PartnerTransaction, } from './types/response/rebate.js'; import { @@ -278,6 +283,7 @@ import { CreatedSubAccountAPIKey, SubAccount, SubAccountAPIKey, + SubAccountMode, } from './types/response/subaccount.js'; import { MarginTier, @@ -293,6 +299,7 @@ import { CreateDepositAddressResp, CurrencyChain, GetBalancesResp, + PushOrder, SavedAddress, SmallBalanceHistoryRecord, SmallBalanceRecord, @@ -343,6 +350,26 @@ export class RestClient extends BaseRestClient { return this.postPrivate('/withdrawals', { body: params }); } + /** + * Transfer between spot main accounts + * + * Both parties cannot be sub-accounts. + * + * @param params Transfer parameters + * @returns Promise<{ + * id: number; + * }> + */ + submitSpotMainAccountTransfer(params: { + receive_uid: number; + currency: string; + amount: string; + }): Promise<{ + id: number; + }> { + return this.postPrivate('/withdrawals/push', { body: params }); + } + /** * Cancel withdrawal with specified ID * @@ -611,6 +638,16 @@ export class RestClient extends BaseRestClient { return this.getPrivate('/wallet/small_balance_history', params); } + /** + * List push orders + * + * @param params Parameters for listing push orders + * @returns Promise + */ + listPushOrders(params?: ListPushOrdersReq): Promise { + return this.getPrivate('/wallet/push', params); + } + /**========================================================================================================================== * SUBACCOUNT * ========================================================================================================================== @@ -731,6 +768,21 @@ export class RestClient extends BaseRestClient { unlockSubAccount(params: { user_id: number }): Promise { return this.postPrivate(`/sub_accounts/${params.user_id}/unlock`); } + + /** + * Get sub-account mode + * + * Unified account mode: + * - classic: Classic account mode + * - multi_currency: Multi-currency margin mode + * - portfolio: Portfolio margin mode + * + * @returns Promise + */ + getSubAccountMode(): Promise { + return this.getPrivate('/sub_accounts/unified_mode'); + } + /**========================================================================================================================== * UNIFIED * ========================================================================================================================== @@ -1735,6 +1787,8 @@ export class RestClient extends BaseRestClient { */ getFlashSwapCurrencyPairs(params?: { currency?: string; + page?: number; + limit?: number; }): Promise { return this.get('/flash_swap/currency_pairs', params); } @@ -2436,6 +2490,24 @@ export class RestClient extends BaseRestClient { }); } + /** + * Batch modify orders with specified IDs + * + * You can specify multiple different order IDs. You can only modify up to 10 orders in one request. + * + * @param params Array of BatchAmendOrderReq objects + * @param settle Settlement currency (e.g., 'btc', 'usdt', 'usd') + * @returns Promise + */ + batchUpdateFuturesOrders( + settle: 'btc' | 'usdt' | 'usd', + params: BatchAmendOrderReq[], + ): Promise { + return this.postPrivate(`/futures/${settle}/batch_amend_orders`, { + body: params, + }); + } + /** * Create a price-triggered order * @@ -3837,6 +3909,29 @@ export class RestClient extends BaseRestClient { return this.getPrivate('/rebate/partner/commission_history', params); } + /** + * Partner subordinate list + * + * Including sub-agents, direct customers, indirect customers + * + * @param params Parameters for retrieving partner subordinate list + * @returns Promise<{ + * total: number; + * list: { + * user_id: number; + * user_join_time: number; + * type: number; + * desc: string; + * }[]; + * }> + */ + getPartnerSubordinateList(params?: GetPartnerSubordinateListReq): Promise<{ + total: number; + list: PartnerSubordinateListRecord[]; + }> { + return this.getPrivate('/rebate/partner/sub_list', params); + } + /** * The broker obtains the user's commission rebate records. * Record time range cannot exceed 30 days. diff --git a/src/types/request/futures.ts b/src/types/request/futures.ts index a1ae1f7..6dab4e3 100644 --- a/src/types/request/futures.ts +++ b/src/types/request/futures.ts @@ -211,3 +211,14 @@ export interface GetFuturesAutoOrdersReq { limit?: number; offset?: number; } + +/** + * Modify contract order parameters + */ +export interface BatchAmendOrderReq { + order_id?: number; // Order id, order_id and text must contain at least one + text?: string; // User-defined order text, at least one of order_id and text must be passed + size?: number; // The new order size, including the executed order size + price?: string; // New order price + amend_text?: string; // Custom info during amending order +} diff --git a/src/types/request/rebate.ts b/src/types/request/rebate.ts index e70580e..f05b0a6 100644 --- a/src/types/request/rebate.ts +++ b/src/types/request/rebate.ts @@ -16,16 +16,26 @@ export interface GetAgencyCommissionHistoryReq { offset?: number; } +export interface GetPartnerSubordinateListReq { + user_id?: number; + limit?: number; + offset?: number; +} + export interface GetBrokerCommissionHistoryReq { limit?: number; offset?: number; user_id?: number; + from?: number; + to?: number; } export interface GetBrokerTransactionHistoryReq { limit?: number; offset?: number; user_id?: number; + from?: number; + to?: number; } // Interfaces for request and response diff --git a/src/types/request/wallet.ts b/src/types/request/wallet.ts index e969236..20714e3 100644 --- a/src/types/request/wallet.ts +++ b/src/types/request/wallet.ts @@ -36,6 +36,14 @@ export interface GetSmallBalanceHistoryReq { limit?: number; } +export interface ListPushOrdersReq { + id?: number; + from?: number; + to?: number; + limit?: number; + offset?: number; +} + export interface SubmitSubToSubTransferReq { currency: string; sub_account_from: string; diff --git a/src/types/response/futures.ts b/src/types/response/futures.ts index 165a20e..80196ea 100644 --- a/src/types/response/futures.ts +++ b/src/types/response/futures.ts @@ -257,6 +257,7 @@ export interface FuturesTradingHistoryRecord { text: string; fee: string; point_fee: string; + close_size: number; } export interface FuturesPositionHistoryRecord { @@ -426,3 +427,40 @@ export interface FuturesDeliveryContract { in_delisting?: boolean; orders_limit?: number; } + +export interface BatchAmendOrderResp { + succeeded: boolean; + label?: string; + detail?: string; + id: number; + user: number; + create_time: number; + finish_time?: number; + finish_as?: + | 'filled' + | 'cancelled' + | 'liquidated' + | 'ioc' + | 'auto_deleveraged' + | 'reduce_only' + | 'position_closed' + | 'reduce_out' + | 'stp'; + status: 'open' | 'finished'; + contract: string; + size: number; + iceberg: number; + price: string; + is_close: boolean; + is_reduce_only: boolean; + is_liq: boolean; + tif: 'gtc' | 'ioc' | 'poc' | 'fok'; + left: number; + fill_price: string; + text: string; + tkfr: string; + mkfr: string; + refu: number; + stp_act: 'co' | 'cn' | 'cb' | '-'; + stp_id: number; +} diff --git a/src/types/response/rebate.ts b/src/types/response/rebate.ts index 0625531..08fa8ad 100644 --- a/src/types/response/rebate.ts +++ b/src/types/response/rebate.ts @@ -19,6 +19,13 @@ export interface AgencyCommissionHistoryRecord { source: string; } +export interface PartnerSubordinateListRecord { + user_id: number; + user_join_time: number; + type: number; + desc: string; +} + export interface BrokerCommissionHistoryRecord { commission_time: number; user_id: number; diff --git a/src/types/response/subaccount.ts b/src/types/response/subaccount.ts index da522e0..8544bdc 100644 --- a/src/types/response/subaccount.ts +++ b/src/types/response/subaccount.ts @@ -58,3 +58,9 @@ export interface SubAccountAPIKey { updated_at?: number; last_access?: number; } + +export interface SubAccountMode { + user_id: number; + is_unified: boolean; + mode: 'classic' | 'multi_currency' | 'portfolio'; +} diff --git a/src/types/response/wallet.ts b/src/types/response/wallet.ts index df78ccd..901b6e3 100644 --- a/src/types/response/wallet.ts +++ b/src/types/response/wallet.ts @@ -186,3 +186,14 @@ export interface SmallBalanceHistoryRecord { gt_amount: string; create_time: number; } + +export interface PushOrder { + id: number; + push_uid: number; + receive_uid: number; + currency: string; + amount: string; + create_time: number; + status: 'CREATING' | 'PENDING' | 'CANCELLING' | 'CANCELLED' | 'REFUSING' | 'REFUSED' | 'RECEIVING' | 'RECEIVED'; +} + From f717deb44ea32619c0f5a90fa89599039389706d Mon Sep 17 00:00:00 2001 From: Jerko J <83344666+JJ-Cro@users.noreply.github.com> Date: Tue, 20 Aug 2024 10:44:04 +0200 Subject: [PATCH 2/5] fix(): fixed lint --- src/types/response/wallet.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/types/response/wallet.ts b/src/types/response/wallet.ts index 901b6e3..02d550a 100644 --- a/src/types/response/wallet.ts +++ b/src/types/response/wallet.ts @@ -194,6 +194,13 @@ export interface PushOrder { currency: string; amount: string; create_time: number; - status: 'CREATING' | 'PENDING' | 'CANCELLING' | 'CANCELLED' | 'REFUSING' | 'REFUSED' | 'RECEIVING' | 'RECEIVED'; + status: + | 'CREATING' + | 'PENDING' + | 'CANCELLING' + | 'CANCELLED' + | 'REFUSING' + | 'REFUSED' + | 'RECEIVING' + | 'RECEIVED'; } - From 6053108cfce34ba4b48ce2ab6c07749ecb69c8c3 Mon Sep 17 00:00:00 2001 From: Jerko J <83344666+JJ-Cro@users.noreply.github.com> Date: Tue, 20 Aug 2024 10:45:57 +0200 Subject: [PATCH 3/5] chore(): changed naming --- src/RestClient.ts | 4 ++-- src/types/response/rebate.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/RestClient.ts b/src/RestClient.ts index dcd2b9c..7685c53 100644 --- a/src/RestClient.ts +++ b/src/RestClient.ts @@ -260,7 +260,7 @@ import { BrokerCommissionHistoryRecord, BrokerTransactionHistoryRecord, PartnerCommission, - PartnerSubordinateListRecord, + PartnerSubordinate, PartnerTransaction, } from './types/response/rebate.js'; import { @@ -3927,7 +3927,7 @@ export class RestClient extends BaseRestClient { */ getPartnerSubordinateList(params?: GetPartnerSubordinateListReq): Promise<{ total: number; - list: PartnerSubordinateListRecord[]; + list: PartnerSubordinate[]; }> { return this.getPrivate('/rebate/partner/sub_list', params); } diff --git a/src/types/response/rebate.ts b/src/types/response/rebate.ts index 08fa8ad..f8c4aa5 100644 --- a/src/types/response/rebate.ts +++ b/src/types/response/rebate.ts @@ -19,7 +19,7 @@ export interface AgencyCommissionHistoryRecord { source: string; } -export interface PartnerSubordinateListRecord { +export interface PartnerSubordinate { user_id: number; user_join_time: number; type: number; From af344a335b01acf8f7bf0a50652b0a816bc6b671 Mon Sep 17 00:00:00 2001 From: Jerko J <83344666+JJ-Cro@users.noreply.github.com> Date: Tue, 20 Aug 2024 11:00:57 +0200 Subject: [PATCH 4/5] chore(): Name fix --- src/RestClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RestClient.ts b/src/RestClient.ts index 7685c53..6922ca5 100644 --- a/src/RestClient.ts +++ b/src/RestClient.ts @@ -644,7 +644,7 @@ export class RestClient extends BaseRestClient { * @param params Parameters for listing push orders * @returns Promise */ - listPushOrders(params?: ListPushOrdersReq): Promise { + getPushOrders(params?: ListPushOrdersReq): Promise { return this.getPrivate('/wallet/push', params); } From 5f9e75b8f80794b50c0a784989b57e1601c7ed49 Mon Sep 17 00:00:00 2001 From: Jerko J <83344666+JJ-Cro@users.noreply.github.com> Date: Tue, 20 Aug 2024 11:06:23 +0200 Subject: [PATCH 5/5] chore(): bumped version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index fc1010b..2508bb9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gateio-api", - "version": "1.0.12", + "version": "1.0.14", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gateio-api", - "version": "1.0.12", + "version": "1.0.14", "license": "MIT", "dependencies": { "axios": "^1.6.6", diff --git a/package.json b/package.json index 29ec94b..a6b9396 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gateio-api", - "version": "1.0.13", + "version": "1.0.14", "description": "Complete & robust Node.js SDK for Gate.io's REST APIs, WebSockets & WebSocket APIs, with TypeScript declarations.", "scripts": { "clean": "rm -rf dist/*",