Skip to content

Commit

Permalink
Merge pull request #37 from JJ-Cro/update051124
Browse files Browse the repository at this point in the history
v1.0.22 feat(): new endpoints, updated types
  • Loading branch information
tiagosiebler authored Nov 6, 2024
2 parents acb467a + 8a1a3ef commit ac1f3f9
Show file tree
Hide file tree
Showing 12 changed files with 450 additions and 280 deletions.
542 changes: 273 additions & 269 deletions docs/endpointFunctionList.md

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions examples/apidoc/RestClient/batchCancelFuturesOrders.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
const { RestClient } = require('gateio-api');

// This example shows how to call this Gate.io API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "gateio-api" for Gate.io exchange
// This Gate.io API SDK is available on npm via "npm install gateio-api"
// ENDPOINT: /futures/{settle}/batch_cancel_orders
// METHOD: POST
// PUBLIC: NO
// This example shows how to call this Gate.io API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "gateio-api" for Gate.io exchange
// This Gate.io API SDK is available on npm via "npm install gateio-api"
// ENDPOINT: /futures/{settle}/batch_cancel_orders
// METHOD: POST
// PUBLIC: NO

const client = new RestClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.batchCancelFuturesOrders(params)
client
.batchCancelFuturesOrders(params)
.then((response) => {
console.log(response);
})
Expand Down
20 changes: 20 additions & 0 deletions examples/apidoc/RestClient/getMultiLoanCurrentRates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { RestClient } = require('gateio-api');

// This example shows how to call this Gate.io API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "gateio-api" for Gate.io exchange
// This Gate.io API SDK is available on npm via "npm install gateio-api"
// ENDPOINT: /loan/multi_collateral/current_rate
// METHOD: GET
// PUBLIC: YES

const client = new RestClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.getMultiLoanCurrentRates(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
20 changes: 20 additions & 0 deletions examples/apidoc/RestClient/getUserCurrencyLeverageConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { RestClient } = require('gateio-api');

// This example shows how to call this Gate.io API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "gateio-api" for Gate.io exchange
// This Gate.io API SDK is available on npm via "npm install gateio-api"
// ENDPOINT: /unified/leverage/user_currency_config
// METHOD: GET
// PUBLIC: NO

const client = new RestClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.getUserCurrencyLeverageConfig(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
20 changes: 20 additions & 0 deletions examples/apidoc/RestClient/getUserCurrencyLeverageSettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { RestClient } = require('gateio-api');

// This example shows how to call this Gate.io API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "gateio-api" for Gate.io exchange
// This Gate.io API SDK is available on npm via "npm install gateio-api"
// ENDPOINT: /unified/leverage/user_currency_setting
// METHOD: GET
// PUBLIC: NO

const client = new RestClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.getUserCurrencyLeverageSettings(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
20 changes: 20 additions & 0 deletions examples/apidoc/RestClient/updateUserCurrencyLeverage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { RestClient } = require('gateio-api');

// This example shows how to call this Gate.io API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "gateio-api" for Gate.io exchange
// This Gate.io API SDK is available on npm via "npm install gateio-api"
// ENDPOINT: /unified/leverage/user_currency_setting
// METHOD: POST
// PUBLIC: NO

const client = new RestClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.updateUserCurrencyLeverage(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
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.21",
"version": "1.0.22",
"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
75 changes: 73 additions & 2 deletions src/RestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ import {
BatchAmendOrderResp,
DeleteFuturesBatchOrdersResp,
FuturesAccount,
FuturesAccountBookRecord,
FuturesAutoDeleveragingHistoryRecord,
FuturesCandle,
FuturesContract,
Expand Down Expand Up @@ -298,6 +299,7 @@ import {
UnifiedLoan,
UnifiedLoanRecord,
UnifiedRiskUnitDetails,
UserCurrencyLeverageConfig,
} from './types/response/unified.js';
import {
CreateDepositAddressResp,
Expand Down Expand Up @@ -1043,6 +1045,52 @@ export class RestClient extends BaseRestClient {
return this.post('/unified/portfolio_calculator', { body: params });
}

/**
* Query user currency leverage configuration
*
* Get the maximum and minimum leverage multiples that users can set for a currency type
*
* @param params Parameters containing the currency
* @returns Promise<UserCurrencyLeverageConfig>
*/
getUserCurrencyLeverageConfig(params: {
currency: string;
}): Promise<UserCurrencyLeverageConfig> {
return this.getPrivate('/unified/leverage/user_currency_config', params);
}

/**
* Get the user's currency leverage
*
* If currency is not passed, query all currencies.
*
* @param params Optional parameters containing the currency
* @returns Promise<UserCurrencyLeverageSetting[]>
*/
getUserCurrencyLeverageSettings(params?: { currency?: string }): Promise<
{
currency: string;
leverage: string;
}[]
> {
return this.getPrivate('/unified/leverage/user_currency_setting', params);
}

/**
* Set the currency leverage ratio
*
* @param params Parameters for setting currency leverage ratio
* @returns Promise<any> Returns nothing on success (204 No Content)
*/
updateUserCurrencyLeverage(params: {
currency: string;
leverage: string;
}): Promise<any> {
return this.postPrivate('/unified/leverage/user_currency_setting', {
body: params,
});
}

/**==========================================================================================================================
* SPOT
* ==========================================================================================================================
Expand Down Expand Up @@ -2130,7 +2178,7 @@ export class RestClient extends BaseRestClient {
*/
getFuturesAccountBook(
params: GetFuturesAccountBookReq,
): Promise<GetFuturesAccountBookReq[]> {
): Promise<FuturesAccountBookRecord[]> {
const { settle, ...query } = params;
return this.getPrivate(`/futures/${settle}/account_book`, query);
}
Expand Down Expand Up @@ -2310,7 +2358,7 @@ export class RestClient extends BaseRestClient {
* Set stp_act to decide the strategy of self-trade prevention. For detailed usage, refer to the stp_act parameter in the request body.
*
* @param params Parameters for creating a futures order
* @returns Promise<SubmitFuturesOrderReq>
* @returns Promise<FuturesOrder>
*/
submitFuturesOrder(params: SubmitFuturesOrderReq): Promise<FuturesOrder> {
const { settle, ...body } = params;
Expand Down Expand Up @@ -3790,6 +3838,27 @@ export class RestClient extends BaseRestClient {
return this.get(`/loan/multi_collateral/fixed_rate`);
}

/**
* Query the current interest rate of currencies
*
* Query the current interest rate of currencies in the last hour.
* The current interest rate is updated every hour.
*
* @param params Parameters containing currencies to query and optional VIP level
* @returns Promise<MultiLoanCurrentRate[]>
*/
getMultiLoanCurrentRates(params: {
currencies: string[];
vip_level?: string;
}): Promise<
{
currency: string;
current_rate: string;
}[]
> {
return this.get('/loan/multi_collateral/current_rate', params);
}

/**==========================================================================================================================
* EARN
* ==========================================================================================================================
Expand Down Expand Up @@ -3831,6 +3900,8 @@ export class RestClient extends BaseRestClient {
submitDualInvestmentOrder(params: {
plan_id: string;
copies: string;
is_max: number;
amount: string;
}): Promise<any> {
return this.postPrivate(`/earn/dual/orders`, { body: params });
}
Expand Down
1 change: 1 addition & 0 deletions src/types/response/futures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export interface FuturesAccountBookRecord {
text: string;
contract?: string;
trade_id: string;
id: string;
}

export interface UpdateFuturesDualModeResp {
Expand Down
2 changes: 2 additions & 0 deletions src/types/response/spot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export interface SpotTicker {
currency_pair: string;
last: string;
lowest_ask: string;
lowest_size: string;
highest_bid: string;
highest_size: string;
change_percentage: string;
change_utc0: string;
change_utc8: string;
Expand Down
11 changes: 11 additions & 0 deletions src/types/response/unified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,20 @@ export interface UnifiedCurrencyDiscountTiers {
discount: string;
lower_limit: string;
upper_limit: string;
leverage: string;
}[];
}

export interface UserCurrencyLeverageConfig {
current_leverage: string;
min_leverage: string;
max_leverage: string;
debit: string;
available_margin: string;
borrowable: string;
except_leverage_borrowable: string;
}

export interface MarginTier {
tier: string;
margin_rate: string;
Expand Down

0 comments on commit ac1f3f9

Please sign in to comment.