Skip to content

Commit

Permalink
Merge pull request #26 from JJ-Cro/master
Browse files Browse the repository at this point in the history
feat(): Added new endpoints, added new params/response types
  • Loading branch information
tiagosiebler authored Aug 20, 2024
2 parents de6b399 + 5f9e75b commit 38506dd
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ localtest.sh

ws-private-spot-wsapi-performance.ts
ws-private-perp-futures-wsapi-readonly.ts
privatetest.ts
privatetest.ts

privaterepotracker
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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/*",
Expand Down
95 changes: 95 additions & 0 deletions src/RestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
SubmitFlashSwapOrderReq,
} from './types/request/flashswap.js';
import {
BatchAmendOrderReq,
DeleteAllFuturesOrdersReq,
GetFuturesAccountBookReq,
GetFuturesAutoOrdersReq,
Expand Down Expand Up @@ -104,6 +105,7 @@ import {
GetAgencyTransactionHistoryReq,
GetBrokerCommissionHistoryReq,
GetBrokerTransactionHistoryReq,
GetPartnerSubordinateListReq,
PartnerTransactionReq,
} from './types/request/rebate.js';
import {
Expand Down Expand Up @@ -140,6 +142,7 @@ import {
GetSavedAddressReq,
GetSmallBalanceHistoryReq,
GetWithdrawalDepositRecordsReq,
ListPushOrdersReq,
SubmitMainSubTransferReq,
SubmitSubToSubTransferReq,
SubmitTransferReq,
Expand Down Expand Up @@ -186,6 +189,7 @@ import {
SubmitFlashSwapOrderPreviewResp,
} from './types/response/flashswap.js';
import {
BatchAmendOrderResp,
DeleteFuturesBatchOrdersResp,
FuturesAccount,
FuturesAutoDeleveragingHistoryRecord,
Expand Down Expand Up @@ -256,6 +260,7 @@ import {
BrokerCommissionHistoryRecord,
BrokerTransactionHistoryRecord,
PartnerCommission,
PartnerSubordinate,
PartnerTransaction,
} from './types/response/rebate.js';
import {
Expand All @@ -278,6 +283,7 @@ import {
CreatedSubAccountAPIKey,
SubAccount,
SubAccountAPIKey,
SubAccountMode,
} from './types/response/subaccount.js';
import {
MarginTier,
Expand All @@ -293,6 +299,7 @@ import {
CreateDepositAddressResp,
CurrencyChain,
GetBalancesResp,
PushOrder,
SavedAddress,
SmallBalanceHistoryRecord,
SmallBalanceRecord,
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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<PushOrder[]>
*/
getPushOrders(params?: ListPushOrdersReq): Promise<PushOrder[]> {
return this.getPrivate('/wallet/push', params);
}

/**==========================================================================================================================
* SUBACCOUNT
* ==========================================================================================================================
Expand Down Expand Up @@ -731,6 +768,21 @@ export class RestClient extends BaseRestClient {
unlockSubAccount(params: { user_id: number }): Promise<any> {
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<SubAccountMode>
*/
getSubAccountMode(): Promise<SubAccountMode> {
return this.getPrivate('/sub_accounts/unified_mode');
}

/**==========================================================================================================================
* UNIFIED
* ==========================================================================================================================
Expand Down Expand Up @@ -1735,6 +1787,8 @@ export class RestClient extends BaseRestClient {
*/
getFlashSwapCurrencyPairs(params?: {
currency?: string;
page?: number;
limit?: number;
}): Promise<FlashSwapCurrencyPair[]> {
return this.get('/flash_swap/currency_pairs', params);
}
Expand Down Expand Up @@ -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<BatchAmendOrderResp[]>
*/
batchUpdateFuturesOrders(
settle: 'btc' | 'usdt' | 'usd',
params: BatchAmendOrderReq[],
): Promise<BatchAmendOrderResp[]> {
return this.postPrivate(`/futures/${settle}/batch_amend_orders`, {
body: params,
});
}

/**
* Create a price-triggered order
*
Expand Down Expand Up @@ -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: PartnerSubordinate[];
}> {
return this.getPrivate('/rebate/partner/sub_list', params);
}

/**
* The broker obtains the user's commission rebate records.
* Record time range cannot exceed 30 days.
Expand Down
11 changes: 11 additions & 0 deletions src/types/request/futures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 10 additions & 0 deletions src/types/request/rebate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/types/request/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 38 additions & 0 deletions src/types/response/futures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export interface FuturesTradingHistoryRecord {
text: string;
fee: string;
point_fee: string;
close_size: number;
}

export interface FuturesPositionHistoryRecord {
Expand Down Expand Up @@ -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;
}
7 changes: 7 additions & 0 deletions src/types/response/rebate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export interface AgencyCommissionHistoryRecord {
source: string;
}

export interface PartnerSubordinate {
user_id: number;
user_join_time: number;
type: number;
desc: string;
}

export interface BrokerCommissionHistoryRecord {
commission_time: number;
user_id: number;
Expand Down
6 changes: 6 additions & 0 deletions src/types/response/subaccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
18 changes: 18 additions & 0 deletions src/types/response/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,21 @@ 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';
}

0 comments on commit 38506dd

Please sign in to comment.