From a5efe89612cc457cec341f584ab4cb3c1394f01f Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Tue, 11 Jun 2024 16:43:36 +0100 Subject: [PATCH] chore(): type refactoring --- src/RestClient.ts | 102 +++++---- src/types/request/futures.ts | 4 +- src/types/request/spot.ts | 13 ++ src/types/response/futures.ts | 195 +++++++++++++++++- src/types/response/shared.types.ts | 9 +- src/types/response/spot.ts | 68 +++++- src/types/response/subaccount.ts | 25 +++ src/types/response/wallet.ts | 6 - src/types/response/withdrawal.ts | 25 +++ src/types/shared.ts | 321 ----------------------------- src/types/websockets/wsAPI.ts | 13 +- 11 files changed, 384 insertions(+), 397 deletions(-) diff --git a/src/RestClient.ts b/src/RestClient.ts index d7f55f3..6a08f71 100644 --- a/src/RestClient.ts +++ b/src/RestClient.ts @@ -59,7 +59,7 @@ import { GetFuturesTradingHistoryReq, GetLiquidationHistoryReq, GetRiskLimitTiersReq, - submitFuturesBatchOrdersReq, + SubmitFuturesBatchOrdersReq, SubmitFuturesOrderReq, SubmitFuturesPriceTriggeredOrderReq, UpdateDualModePositionLeverageReq, @@ -107,11 +107,13 @@ import { GetBrokerTransactionHistoryReq, } from './types/request/rebate.js'; import { + CancelSpotBatchOrdersReq, DeleteSpotOrderReq, GetSpotAccountBookReq, GetSpotAutoOrdersReq, GetSpotCandlesticksReq, GetSpotOrderBookReq, + GetSpotOrderReq, GetSpotOrdersReq, GetSpotTradesReq, GetSpotTradingHistoryReq, @@ -185,6 +187,11 @@ import { } from './types/response/flashswap.js'; import { DeleteFuturesBatchOrdersResp, + FuturesContract, + FuturesDeliveryContract, + FuturesOrder, + FuturesPosition, + FuturesPriceTriggeredOrder, GetFuturesAccountResp, GetFuturesAutoDeleveragingHistoryResp, GetFuturesCandlesticksResp, @@ -199,7 +206,7 @@ import { GetLiquidationHistoryResp, GetPremiumIndexKLineResp, GetRiskLimitTiersResp, - ToggleFuturesDualModeResp, + UpdateFuturesDualModeResp, } from './types/response/futures.js'; import { GetCrossMarginAccountHistoryResp, @@ -249,6 +256,7 @@ import { GetBrokerCommissionHistoryResp, GetBrokerTransactionHistoryResp, } from './types/response/rebate.js'; +import { APIResponse } from './types/response/shared.types.js'; import { DeleteSpotBatchOrdersResp, GetSpotAccountBookResp, @@ -262,10 +270,13 @@ import { GetSpotTickerResp, GetSpotTradesResp, GetSpotTradingHistoryResp, + SpotOrder, + SpotPriceTriggeredOrder, SubmitSpotBatchOrdersResp, } from './types/response/spot.js'; import { CreateSubAccountApiKeyResp, + SubAccountKey, SubAccountResp, } from './types/response/subaccount.js'; import { @@ -278,7 +289,6 @@ import { PortfolioMarginCalculatorResp, } from './types/response/unified.js'; import { - APIResponse, CreateDepositAddressResp, GetBalancesResp, GetCurrencyChainsResp, @@ -292,20 +302,8 @@ import { SubAccountMarginBalancesResp, SubAccountTransferRecordResp, } from './types/response/wallet.js'; -import { - CancelBatchOrder, - Contract, - CurrencyPair, - DeliveryContract, - FuturesOrder, - FuturesPriceTriggeredOrder, - GetSingleOrderReq, - Order, - Position, - SpotPriceTriggeredOrder, - SubAccountKey, - Withdraw, -} from './types/shared.js'; +import { Withdrawal } from './types/response/withdrawal.js'; +import { CurrencyPair } from './types/shared.js'; /** * Unified REST API client for all of Gate's REST APIs @@ -340,7 +338,7 @@ export class RestClient extends BaseRestClient { * @param params Withdrawal parameters * @returns Promise> */ - submitWithdraw(params: SubmitWithdrawReq): Promise> { + submitWithdraw(params: SubmitWithdrawReq): Promise> { return this.postPrivate('/withdrawals', { query: params }); } @@ -352,7 +350,7 @@ export class RestClient extends BaseRestClient { */ cancelWithdrawal(params: { withdrawal_id: string; - }): Promise> { + }): Promise> { return this.deletePrivate(`/withdrawals/${params.withdrawal_id}`); } @@ -395,7 +393,7 @@ export class RestClient extends BaseRestClient { */ getWithdrawalRecords( params?: GetWithdrawalDepositRecordsReq, - ): Promise> { + ): Promise> { return this.getPrivate('/wallet/withdrawals', params); } @@ -409,7 +407,7 @@ export class RestClient extends BaseRestClient { */ getDepositRecords( params?: GetWithdrawalDepositRecordsReq, - ): Promise> { + ): Promise> { return this.getPrivate('/wallet/deposits', params); } @@ -935,7 +933,7 @@ export class RestClient extends BaseRestClient { * @param params Parameters for portfolio margin calculator * @returns Promise> */ - portfolioMarginCalculator( + portfolioMarginCalculate( params: PortfolioMarginCalculatorReq, ): Promise> { return this.post('/unified/portfolio_calculator', { body: params }); @@ -1116,7 +1114,7 @@ export class RestClient extends BaseRestClient { * @returns Promise> */ submitSpotBatchOrders( - params: Order[], + params: SpotOrder[], ): Promise> { return this.postPrivate('/spot/batch_orders', { body: params }); } @@ -1149,7 +1147,7 @@ export class RestClient extends BaseRestClient { */ submitSpotClosePosCrossDisabled( params: SubmitSpotClosePosCrossDisabledReq, - ): Promise> { + ): Promise> { return this.postPrivate('/spot/cross_liquidate_orders', { body: params }); } @@ -1161,7 +1159,7 @@ export class RestClient extends BaseRestClient { * @param params Parameters for creating an order * @returns Promise> */ - submitSpotOrder(params: SubmitSpotOrderReq): Promise> { + submitSpotOrder(params: SubmitSpotOrderReq): Promise> { return this.postPrivate('/spot/orders', { body: params }); } @@ -1173,7 +1171,7 @@ export class RestClient extends BaseRestClient { * @param params Parameters for listing orders * @returns Promise> */ - getSpotOrders(params: GetSpotOrdersReq): Promise> { + getSpotOrders(params: GetSpotOrdersReq): Promise> { return this.getPrivate('/spot/orders', params); } @@ -1191,7 +1189,7 @@ export class RestClient extends BaseRestClient { side?: 'buy' | 'sell'; account?: 'spot' | 'margin' | 'cross_margin' | 'unified'; action_mode?: 'ACK' | 'RESULT' | 'FULL'; - }): Promise> { + }): Promise> { return this.deletePrivate('/spot/orders', { query: params }); } @@ -1204,7 +1202,7 @@ export class RestClient extends BaseRestClient { * @returns Promise> */ deleteSpotBatchOrders( - params: CancelBatchOrder[], + params: CancelSpotBatchOrdersReq[], ): Promise> { return this.postPrivate('/spot/cancel_batch_orders', { body: params }); } @@ -1217,7 +1215,7 @@ export class RestClient extends BaseRestClient { * @param params Parameters for getting a single order * @returns Promise> */ - getSpotOrder(params: GetSingleOrderReq): Promise> { + getSpotOrder(params: GetSpotOrderReq): Promise> { const { order_id, ...query } = params; return this.getPrivate(`/spot/orders/${order_id}`, query); } @@ -1232,7 +1230,7 @@ export class RestClient extends BaseRestClient { * @param params Parameters for amending an order * @returns Promise> */ - updateSpotOrder(params: UpdateSpotOrderReq): Promise> { + updateSpotOrder(params: UpdateSpotOrderReq): Promise> { const { order_id, currency_pair, account, ...body } = params; const query = { @@ -1254,7 +1252,7 @@ export class RestClient extends BaseRestClient { * @param params Parameters for cancelling a single order * @returns Promise> */ - deleteSpotOrder(params: DeleteSpotOrderReq): Promise> { + deleteSpotOrder(params: DeleteSpotOrderReq): Promise> { const { order_id, ...query } = params; return this.deletePrivate(`/spot/orders/${order_id}`, { query: query, @@ -1323,7 +1321,7 @@ export class RestClient extends BaseRestClient { */ updateSpotBatchOrders( params: UpdateSpotBatchOrdersReq[], - ): Promise> { + ): Promise> { return this.postPrivate('/spot/amend_batch_orders', { body: params }); } @@ -1858,7 +1856,7 @@ export class RestClient extends BaseRestClient { settle: 'btc' | 'usdt' | 'usd'; limit?: number; offset?: number; - }): Promise> { + }): Promise> { const { settle, ...query } = params; return this.get(`/futures/${settle}/contracts`, query); } @@ -1872,7 +1870,7 @@ export class RestClient extends BaseRestClient { getFuturesContract(params: { settle: 'btc' | 'usdt' | 'usd'; contract: string; - }): Promise> { + }): Promise> { return this.get(`/futures/${params.settle}/contracts/${params.contract}`); } @@ -2094,7 +2092,7 @@ export class RestClient extends BaseRestClient { */ getFuturesPositions( params: GetFuturesPositionsReq, - ): Promise> { + ): Promise> { const { settle, ...query } = params; return this.getPrivate(`/futures/${settle}/positions`, query); } @@ -2107,7 +2105,7 @@ export class RestClient extends BaseRestClient { getFuturesPosition(params: { settle: 'btc' | 'usdt' | 'usd'; contract: string; - }): Promise> { + }): Promise> { return this.getPrivate( `/futures/${params.settle}/positions/${params.contract}`, ); @@ -2123,7 +2121,7 @@ export class RestClient extends BaseRestClient { settle: 'btc' | 'usdt' | 'usd'; contract: string; change: string; - }): Promise> { + }): Promise> { const { settle, contract, ...query } = params; return this.postPrivate(`/futures/${settle}/positions/${contract}/margin`, { query: query, @@ -2141,7 +2139,7 @@ export class RestClient extends BaseRestClient { contract: string; leverage: string; cross_leverage_limit?: string; - }): Promise> { + }): Promise> { const { settle, contract, ...query } = params; return this.postPrivate( `/futures/${settle}/positions/${contract}/leverage`, @@ -2159,7 +2157,7 @@ export class RestClient extends BaseRestClient { settle: 'btc' | 'usdt' | 'usd'; contract: string; risk_limit: string; - }): Promise> { + }): Promise> { const { settle, contract, ...query } = params; return this.postPrivate( `/futures/${settle}/positions/${contract}/risk_limit`, @@ -2178,7 +2176,7 @@ export class RestClient extends BaseRestClient { updateFuturesDualMode(params: { settle: 'btc' | 'usdt' | 'usd'; dual_mode: boolean; - }): Promise> { + }): Promise> { const { settle, ...query } = params; return this.postPrivate(`/futures/${settle}/dual_mode`, { query: query, @@ -2194,7 +2192,7 @@ export class RestClient extends BaseRestClient { getDualModePosition(params: { settle: 'btc' | 'usdt' | 'usd'; contract: string; - }): Promise> { + }): Promise> { return this.getPrivate( `/futures/${params.settle}/dual_comp/positions/${params.contract}`, ); @@ -2208,7 +2206,7 @@ export class RestClient extends BaseRestClient { */ updateDualModePositionMargin( params: UpdateDualModePositionMarginReq, - ): Promise> { + ): Promise> { const { settle, contract, ...query } = params; return this.postPrivate( `/futures/${settle}/dual_comp/positions/${contract}/margin`, @@ -2224,7 +2222,7 @@ export class RestClient extends BaseRestClient { */ updateDualModePositionLeverage( params: UpdateDualModePositionLeverageReq, - ): Promise> { + ): Promise> { const { settle, contract, ...query } = params; return this.postPrivate( `/futures/${settle}/dual_comp/positions/${contract}/leverage`, @@ -2242,7 +2240,7 @@ export class RestClient extends BaseRestClient { settle: 'btc' | 'usdt' | 'usd'; contract: string; risk_limit: string; - }): Promise> { + }): Promise> { const { settle, contract, ...query } = params; return this.postPrivate( `/futures/${settle}/dual_comp/positions/${contract}/risk_limit`, @@ -2331,7 +2329,7 @@ export class RestClient extends BaseRestClient { * @returns Promise> */ submitFuturesBatchOrders( - params: submitFuturesBatchOrdersReq, + params: SubmitFuturesBatchOrdersReq, ): Promise> { const { settle, ...body } = params; return this.postPrivate(`/futures/${settle}/batch_orders`, { body: body }); @@ -2577,7 +2575,7 @@ export class RestClient extends BaseRestClient { */ getAllDeliveryContracts(params: { settle: 'usdt'; - }): Promise> { + }): Promise> { return this.get(`/delivery/${params.settle}/contracts`); } @@ -2590,7 +2588,7 @@ export class RestClient extends BaseRestClient { getDeliveryContract(params: { settle: 'usdt'; contract: string; - }): Promise> { + }): Promise> { return this.get(`/delivery/${params.settle}/contracts/${params.contract}`); } @@ -2710,7 +2708,7 @@ export class RestClient extends BaseRestClient { */ getDeliveryPositions(params: { settle: 'usdt'; - }): Promise> { + }): Promise> { return this.getPrivate(`/delivery/${params.settle}/positions`); } @@ -2723,7 +2721,7 @@ export class RestClient extends BaseRestClient { getDeliveryPosition(params: { settle: 'usdt'; contract: string; - }): Promise> { + }): Promise> { return this.getPrivate( `/delivery/${params.settle}/positions/${params.contract}`, ); @@ -2739,7 +2737,7 @@ export class RestClient extends BaseRestClient { settle: 'usdt'; contract: string; change: string; - }): Promise> { + }): Promise> { const { settle, contract, ...query } = params; return this.postPrivate( `/delivery/${settle}/positions/${contract}/margin`, @@ -2757,7 +2755,7 @@ export class RestClient extends BaseRestClient { settle: 'usdt'; contract: string; leverage: string; - }): Promise> { + }): Promise> { const { settle, contract, ...query } = params; return this.postPrivate( `/delivery/${settle}/positions/${contract}/leverage`, @@ -2775,7 +2773,7 @@ export class RestClient extends BaseRestClient { settle: 'usdt'; contract: string; risk_limit: string; - }): Promise> { + }): Promise> { const { settle, contract, ...query } = params; return this.postPrivate( `/delivery/${settle}/positions/${contract}/risk_limit`, diff --git a/src/types/request/futures.ts b/src/types/request/futures.ts index fb81a52..fae1909 100644 --- a/src/types/request/futures.ts +++ b/src/types/request/futures.ts @@ -3,7 +3,7 @@ * ========================================================================================================================== */ -import { FuturesOrder, FuturesPriceTriggeredOrder } from '../shared'; +import { FuturesOrder, FuturesPriceTriggeredOrder } from '../response/futures'; export interface GetFuturesOrderBookReq { settle: 'btc' | 'usdt' | 'usd'; @@ -133,7 +133,7 @@ export interface GetFuturesOrdersByTimeRangeReq { offset?: number; } -export interface submitFuturesBatchOrdersReq extends FuturesOrder { +export interface SubmitFuturesBatchOrdersReq extends FuturesOrder { settle: 'btc' | 'usdt' | 'usd'; } diff --git a/src/types/request/spot.ts b/src/types/request/spot.ts index 29ad303..b4da7c1 100644 --- a/src/types/request/spot.ts +++ b/src/types/request/spot.ts @@ -67,6 +67,13 @@ export interface GetSpotOrdersReq { side?: 'buy' | 'sell'; } +export interface CancelSpotBatchOrdersReq { + currency_pair: string; + id: string; + account?: 'cross_margin'; + action_mode?: 'ACK' | 'RESULT' | 'FULL'; +} + export interface DeleteSpotOrderReq { order_id: string; currency_pair: string; @@ -74,6 +81,12 @@ export interface DeleteSpotOrderReq { action_mode?: 'ACK' | 'RESULT' | 'FULL'; } +export interface GetSpotOrderReq { + order_id: string; + currency_pair: string; + account?: 'spot' | 'margin' | 'cross_margin' | 'unified'; +} + export interface GetSpotTradingHistoryReq { currency_pair?: string; limit?: number; diff --git a/src/types/response/futures.ts b/src/types/response/futures.ts index 7ceee53..2c8503f 100644 --- a/src/types/response/futures.ts +++ b/src/types/response/futures.ts @@ -143,7 +143,7 @@ export interface GetFuturesAccountBookResp { trade_id: string; } -export interface ToggleFuturesDualModeResp { +export interface UpdateFuturesDualModeResp { total: string; unrealised_pnl: string; position_margin: string; @@ -171,6 +171,81 @@ export interface ToggleFuturesDualModeResp { }; } +export interface FuturesOrder { + id?: number; + user?: number; + create_time?: number; + finish_time?: number; + finish_as?: + | 'filled' + | 'cancelled' + | 'liquidated' + | 'ioc' + | 'auto_deleveraged' + | 'reduce_only' + | 'position_closed' + | 'stp'; + status?: 'open' | 'finished'; + contract: string; + size: number; + iceberg?: number; + price?: string; + close?: boolean; + is_close?: boolean; + reduce_only?: 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; + auto_size?: 'close_long' | 'close_short'; + stp_id?: number; + stp_act?: 'cn' | 'co' | 'cb' | '-'; + amend_text?: string; + biz_info?: string; +} + +export interface FuturesPosition { + user?: number; + contract?: string; + size?: number; + leverage?: string; + risk_limit?: string; + leverage_max?: string; + maintenance_rate?: string; + value?: string; + margin?: string; + entry_price?: string; + liq_price?: string; + mark_price?: string; + initial_margin?: string; + maintenance_margin?: string; + unrealised_pnl?: string; + realised_pnl?: string; + pnl_pnl?: string; + pnl_fund?: string; + pnl_fee?: string; + history_pnl?: string; + last_close_pnl?: string; + realised_point?: string; + history_point?: string; + adl_ranking?: number; + pending_orders?: number; + close_order?: { + id?: number; + price?: string; + is_liq?: boolean; + } | null; + mode?: 'single' | 'dual_long' | 'dual_short'; + cross_leverage_limit?: string; + update_time?: number; + open_time?: number; +} + export interface GetFuturesTradingHistoryResp { id: number; create_time: number; @@ -232,3 +307,121 @@ export interface DeleteFuturesBatchOrdersResp { succeeded: boolean; message: string; } + +export interface FuturesContract { + name?: string; + type?: 'inverse' | 'direct'; + quanto_multiplier?: string; + leverage_min?: string; + leverage_max?: string; + maintenance_rate?: string; + mark_type?: 'internal' | 'index'; + mark_price?: string; + index_price?: string; + last_price?: string; + maker_fee_rate?: string; + taker_fee_rate?: string; + order_price_round?: string; + mark_price_round?: string; + funding_rate?: string; + funding_interval?: number; + funding_next_apply?: number; + risk_limit_base?: string; + risk_limit_step?: string; + risk_limit_max?: string; + order_size_min?: number; + order_size_max?: number; + order_price_deviate?: string; + ref_discount_rate?: string; + ref_rebate_rate?: string; + orderbook_id?: number; + trade_id?: number; + trade_size?: number; + position_size?: number; + config_change_time?: number; + in_delisting?: boolean; + orders_limit?: number; + enable_bonus?: boolean; + enable_credit?: boolean; + create_time?: number; + funding_cap_ratio?: string; +} + +export interface FuturesPriceTriggeredOrder { + initial: { + contract: string; + size?: number; + price?: string; + close?: boolean; + tif?: 'gtc' | 'ioc'; + text?: string; + reduce_only?: boolean; + auto_size?: string; + is_reduce_only?: boolean; + is_close?: boolean; + }; + trigger: { + strategy_type?: 0 | 1; + price_type?: 0 | 1 | 2; + price?: string; + rule?: 1 | 2; + expiration?: number; + }; + id?: number; + user?: number; + create_time?: number; + finish_time?: number; + trade_id?: number; + status?: 'open' | 'finished' | 'inactive' | 'invalid'; + finish_as?: 'cancelled' | 'succeeded' | 'failed' | 'expired'; + reason?: string; + order_type?: + | 'close-long-order' + | 'close-short-order' + | 'close-long-position' + | 'close-short-position' + | 'plan-close-long-position' + | 'plan-close-short-position'; + me_order_id?: number; +} + +export interface FuturesDeliveryContract { + name?: string; + underlying?: string; + cycle?: 'WEEKLY' | 'BI-WEEKLY' | 'QUARTERLY' | 'BI-QUARTERLY'; + type?: 'inverse' | 'direct'; + quanto_multiplier?: string; + leverage_min?: string; + leverage_max?: string; + maintenance_rate?: string; + mark_type?: 'internal' | 'index'; + mark_price?: string; + index_price?: string; + last_price?: string; + maker_fee_rate?: string; + taker_fee_rate?: string; + order_price_round?: string; + mark_price_round?: string; + basis_rate?: string; + basis_value?: string; + basis_impact_value?: string; + settle_price?: string; + settle_price_interval?: number; + settle_price_duration?: number; + expire_time?: number; + risk_limit_base?: string; + risk_limit_step?: string; + risk_limit_max?: string; + order_size_min?: number; + order_size_max?: number; + order_price_deviate?: string; + ref_discount_rate?: string; + ref_rebate_rate?: string; + orderbook_id?: number; + trade_id?: number; + trade_size?: number; + position_size?: number; + config_change_time?: number; + in_delisting?: boolean; + orders_limit?: number; +} diff --git a/src/types/response/shared.types.ts b/src/types/response/shared.types.ts index fd40910..a1e0287 100644 --- a/src/types/response/shared.types.ts +++ b/src/types/response/shared.types.ts @@ -1,4 +1,5 @@ - - - - +export interface APIResponse { + success: boolean; + data: TData; + timestamp: number; +} diff --git a/src/types/response/spot.ts b/src/types/response/spot.ts index f814bf8..a9c67dd 100644 --- a/src/types/response/spot.ts +++ b/src/types/response/spot.ts @@ -3,8 +3,6 @@ * ========================================================================================================================== */ -import { Order } from '../shared'; - export interface GetSpotCurrenciesResp { currency: string; delisted: boolean; @@ -158,10 +156,74 @@ export interface SubmitSpotBatchOrdersResp { finish_as: 'open' | 'filled' | 'cancelled' | 'ioc' | 'stp'; } +export interface SpotOrder { + id?: string; + text?: string; + amend_text?: string; + create_time?: string; + update_time?: string; + create_time_ms?: number; + update_time_ms?: number; + status?: 'open' | 'closed' | 'cancelled'; + currency_pair: string; + type?: 'limit' | 'market'; + account?: 'spot' | 'margin' | 'cross_margin' | 'unified'; + side: 'buy' | 'sell'; + amount: string; + price?: string; + time_in_force?: 'gtc' | 'ioc' | 'poc' | 'fok'; + iceberg?: string; + auto_borrow?: boolean; + auto_repay?: boolean; + left?: string; + filled_amount?: string; + fill_price?: string; + filled_total?: string; + avg_deal_price?: string; + fee?: string; + fee_currency?: string; + point_fee?: string; + gt_fee?: string; + gt_maker_fee?: string; + gt_taker_fee?: string; + gt_discount?: boolean; + rebated_fee?: string; + rebated_fee_currency?: string; + stp_id?: number; + stp_act?: 'cn' | 'co' | 'cb' | '-'; + finish_as?: 'open' | 'filled' | 'cancelled' | 'ioc' | 'stp'; + action_mode?: 'ACK' | 'RESULT' | 'FULL'; +} + +export interface SpotPriceTriggeredOrder { + trigger: { + price: string; + rule: '>=' | '<='; + expiration: number; + }; + put: { + type?: 'limit' | 'market'; + side: 'buy' | 'sell'; + price: string; + amount: string; + account: 'normal' | 'margin' | 'cross_margin'; + time_in_force?: 'gtc' | 'ioc'; + text?: string; + }; + id?: number; + user?: number; + market: string; + ctime?: number; + ftime?: number; + fired_order_id?: number; + status?: 'open' | 'cancelled' | 'finish' | 'failed' | 'expired'; + reason?: string; +} + export interface GetSpotOpenOrdersResp { currency_pair: string; total: number; - orders: Order[]; + orders: SpotOrder[]; } export interface DeleteSpotBatchOrdersResp { diff --git a/src/types/response/subaccount.ts b/src/types/response/subaccount.ts index 3100eec..5ce3ffe 100644 --- a/src/types/response/subaccount.ts +++ b/src/types/response/subaccount.ts @@ -33,3 +33,28 @@ export interface CreateSubAccountApiKeyResp { updated_at: number; last_access: number; } + +export interface SubAccountKey { + user_id?: string; + mode?: number; + name?: string; + perms?: { + name?: + | 'wallet' + | 'spot' + | 'futures' + | 'delivery' + | 'earn' + | 'options' + | 'account' + | 'unified' + | 'loan'; + read_only?: boolean; + }[]; + ip_whitelist?: string[]; + key?: string; + state?: number; + created_at?: number; + updated_at?: number; + last_access?: number; +} diff --git a/src/types/response/wallet.ts b/src/types/response/wallet.ts index 0cdf34f..680fe7c 100644 --- a/src/types/response/wallet.ts +++ b/src/types/response/wallet.ts @@ -1,9 +1,3 @@ -export interface APIResponse { - success: boolean; - data: TData; - timestamp: number; -} - export interface GetCurrencyChainsResp { chain: string; name_cn: string; diff --git a/src/types/response/withdrawal.ts b/src/types/response/withdrawal.ts index e69de29..7c2d423 100644 --- a/src/types/response/withdrawal.ts +++ b/src/types/response/withdrawal.ts @@ -0,0 +1,25 @@ +export interface Withdrawal { + id: string; + txid: string; + withdraw_order_id: string; + timestamp: string; + amount: string; + currency: string; + address: string; + memo?: string; + status: + | 'DONE' + | 'CANCEL' + | 'REQUEST' + | 'MANUAL' + | 'BCODE' + | 'EXTPEND' + | 'FAIL' + | 'INVALID' + | 'VERIFY' + | 'PROCES' + | 'PEND' + | 'DMOVE' + | 'SPLITPEND'; + chain: string; +} diff --git a/src/types/shared.ts b/src/types/shared.ts index aa01bcc..f2d3440 100644 --- a/src/types/shared.ts +++ b/src/types/shared.ts @@ -5,31 +5,6 @@ export type GateBaseUrlKey = // interfaces -export interface SubAccountKey { - user_id?: string; - mode?: number; - name?: string; - perms?: { - name?: - | 'wallet' - | 'spot' - | 'futures' - | 'delivery' - | 'earn' - | 'options' - | 'account' - | 'unified' - | 'loan'; - read_only?: boolean; - }[]; - ip_whitelist?: string[]; - key?: string; - state?: number; - created_at?: number; - updated_at?: number; - last_access?: number; -} - export interface CurrencyPair { id?: string; base?: string; @@ -45,299 +20,3 @@ export interface CurrencyPair { sell_start?: number; buy_start?: number; } - -export interface Order { - id?: string; - text?: string; - amend_text?: string; - create_time?: string; - update_time?: string; - create_time_ms?: number; - update_time_ms?: number; - status?: 'open' | 'closed' | 'cancelled'; - currency_pair: string; - type?: 'limit' | 'market'; - account?: 'spot' | 'margin' | 'cross_margin' | 'unified'; - side: 'buy' | 'sell'; - amount: string; - price?: string; - time_in_force?: 'gtc' | 'ioc' | 'poc' | 'fok'; - iceberg?: string; - auto_borrow?: boolean; - auto_repay?: boolean; - left?: string; - filled_amount?: string; - fill_price?: string; - filled_total?: string; - avg_deal_price?: string; - fee?: string; - fee_currency?: string; - point_fee?: string; - gt_fee?: string; - gt_maker_fee?: string; - gt_taker_fee?: string; - gt_discount?: boolean; - rebated_fee?: string; - rebated_fee_currency?: string; - stp_id?: number; - stp_act?: 'cn' | 'co' | 'cb' | '-'; - finish_as?: 'open' | 'filled' | 'cancelled' | 'ioc' | 'stp'; - action_mode?: 'ACK' | 'RESULT' | 'FULL'; -} - -export interface GetSingleOrderReq { - order_id: string; - currency_pair: string; - account?: 'spot' | 'margin' | 'cross_margin' | 'unified'; -} - -export interface CancelBatchOrder { - currency_pair: string; - id: string; - account?: 'cross_margin'; - action_mode?: 'ACK' | 'RESULT' | 'FULL'; -} - -export interface SpotPriceTriggeredOrder { - trigger: { - price: string; - rule: '>=' | '<='; - expiration: number; - }; - put: { - type?: 'limit' | 'market'; - side: 'buy' | 'sell'; - price: string; - amount: string; - account: 'normal' | 'margin' | 'cross_margin'; - time_in_force?: 'gtc' | 'ioc'; - text?: string; - }; - id?: number; - user?: number; - market: string; - ctime?: number; - ftime?: number; - fired_order_id?: number; - status?: 'open' | 'cancelled' | 'finish' | 'failed' | 'expired'; - reason?: string; -} - -export interface Contract { - name?: string; - type?: 'inverse' | 'direct'; - quanto_multiplier?: string; - leverage_min?: string; - leverage_max?: string; - maintenance_rate?: string; - mark_type?: 'internal' | 'index'; - mark_price?: string; - index_price?: string; - last_price?: string; - maker_fee_rate?: string; - taker_fee_rate?: string; - order_price_round?: string; - mark_price_round?: string; - funding_rate?: string; - funding_interval?: number; - funding_next_apply?: number; - risk_limit_base?: string; - risk_limit_step?: string; - risk_limit_max?: string; - order_size_min?: number; - order_size_max?: number; - order_price_deviate?: string; - ref_discount_rate?: string; - ref_rebate_rate?: string; - orderbook_id?: number; - trade_id?: number; - trade_size?: number; - position_size?: number; - config_change_time?: number; - in_delisting?: boolean; - orders_limit?: number; - enable_bonus?: boolean; - enable_credit?: boolean; - create_time?: number; - funding_cap_ratio?: string; -} - -export interface Position { - user?: number; - contract?: string; - size?: number; - leverage?: string; - risk_limit?: string; - leverage_max?: string; - maintenance_rate?: string; - value?: string; - margin?: string; - entry_price?: string; - liq_price?: string; - mark_price?: string; - initial_margin?: string; - maintenance_margin?: string; - unrealised_pnl?: string; - realised_pnl?: string; - pnl_pnl?: string; - pnl_fund?: string; - pnl_fee?: string; - history_pnl?: string; - last_close_pnl?: string; - realised_point?: string; - history_point?: string; - adl_ranking?: number; - pending_orders?: number; - close_order?: { - id?: number; - price?: string; - is_liq?: boolean; - } | null; - mode?: 'single' | 'dual_long' | 'dual_short'; - cross_leverage_limit?: string; - update_time?: number; - open_time?: number; -} - -export interface FuturesOrder { - id?: number; - user?: number; - create_time?: number; - finish_time?: number; - finish_as?: - | 'filled' - | 'cancelled' - | 'liquidated' - | 'ioc' - | 'auto_deleveraged' - | 'reduce_only' - | 'position_closed' - | 'stp'; - status?: 'open' | 'finished'; - contract: string; - size: number; - iceberg?: number; - price?: string; - close?: boolean; - is_close?: boolean; - reduce_only?: 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; - auto_size?: 'close_long' | 'close_short'; - stp_id?: number; - stp_act?: 'cn' | 'co' | 'cb' | '-'; - amend_text?: string; - biz_info?: string; -} - -export interface FuturesPriceTriggeredOrder { - initial: { - contract: string; - size?: number; - price?: string; - close?: boolean; - tif?: 'gtc' | 'ioc'; - text?: string; - reduce_only?: boolean; - auto_size?: string; - is_reduce_only?: boolean; - is_close?: boolean; - }; - trigger: { - strategy_type?: 0 | 1; - price_type?: 0 | 1 | 2; - price?: string; - rule?: 1 | 2; - expiration?: number; - }; - id?: number; - user?: number; - create_time?: number; - finish_time?: number; - trade_id?: number; - status?: 'open' | 'finished' | 'inactive' | 'invalid'; - finish_as?: 'cancelled' | 'succeeded' | 'failed' | 'expired'; - reason?: string; - order_type?: - | 'close-long-order' - | 'close-short-order' - | 'close-long-position' - | 'close-short-position' - | 'plan-close-long-position' - | 'plan-close-short-position'; - me_order_id?: number; -} - -export interface DeliveryContract { - name?: string; - underlying?: string; - cycle?: 'WEEKLY' | 'BI-WEEKLY' | 'QUARTERLY' | 'BI-QUARTERLY'; - type?: 'inverse' | 'direct'; - quanto_multiplier?: string; - leverage_min?: string; - leverage_max?: string; - maintenance_rate?: string; - mark_type?: 'internal' | 'index'; - mark_price?: string; - index_price?: string; - last_price?: string; - maker_fee_rate?: string; - taker_fee_rate?: string; - order_price_round?: string; - mark_price_round?: string; - basis_rate?: string; - basis_value?: string; - basis_impact_value?: string; - settle_price?: string; - settle_price_interval?: number; - settle_price_duration?: number; - expire_time?: number; - risk_limit_base?: string; - risk_limit_step?: string; - risk_limit_max?: string; - order_size_min?: number; - order_size_max?: number; - order_price_deviate?: string; - ref_discount_rate?: string; - ref_rebate_rate?: string; - orderbook_id?: number; - trade_id?: number; - trade_size?: number; - position_size?: number; - config_change_time?: number; - in_delisting?: boolean; - orders_limit?: number; -} - -export interface Withdraw { - id: string; - txid: string; - withdraw_order_id: string; - timestamp: string; - amount: string; - currency: string; - address: string; - memo?: string; - status: - | 'DONE' - | 'CANCEL' - | 'REQUEST' - | 'MANUAL' - | 'BCODE' - | 'EXTPEND' - | 'FAIL' - | 'INVALID' - | 'VERIFY' - | 'PROCES' - | 'PEND' - | 'DMOVE' - | 'SPLITPEND'; - chain: string; -} diff --git a/src/types/websockets/wsAPI.ts b/src/types/websockets/wsAPI.ts index 2af8265..14950d1 100644 --- a/src/types/websockets/wsAPI.ts +++ b/src/types/websockets/wsAPI.ts @@ -9,7 +9,7 @@ import { SubmitSpotOrderReq, UpdateSpotOrderReq, } from '../request/spot'; -import { CancelBatchOrder, GetSingleOrderReq } from '../shared'; +import { CancelSpotBatchOrderReq, GetSpotOrderReq } from '../shared'; export type SpotWSAPITopic = | 'spot.login' @@ -48,10 +48,10 @@ export interface WsAPITopicRequestParamMap { 'spot.order_place': SubmitSpotOrderReq; 'spot.order_cancel': DeleteSpotOrderReq; - 'spot.order_cancel_ids': CancelBatchOrder[]; + 'spot.order_cancel_ids': CancelSpotBatchOrderReq[]; 'spot.order_cancel_cp': DeleteSpotOrderReq[]; 'spot.order_amend': UpdateSpotOrderReq; - 'spot.order_status': GetSingleOrderReq; + 'spot.order_status': GetSpotOrderReq; 'futures.order_place': Omit; // doesn't seem like "settle" is needed here 'futures.order_batch_place': Omit[]; 'futures.order_cancel': { @@ -117,7 +117,7 @@ export interface WsAPITopicResponseMap { 'futures.login': WSAPIResponse; 'spot.order_place': WSAPIResponse; - 'spot.order_cancel': WSAPIResponse; + 'spot.order_cancel': WSAPIResponse; 'spot.order_cancel_ids': WSAPIResponse< TResponseType, 'spot.order_cancel_ids' @@ -139,10 +139,7 @@ export interface WsAPITopicResponseMap { 'futures.order_cancel_cp' >; 'futures.order_amend': WSAPIResponse; - 'futures.order_list': WSAPIResponse< - WSAPILoginResponse[], - 'futures.order_list' - >; + 'futures.order_list': WSAPIResponse; 'futures.order_status': WSAPIResponse< WSAPIOrderStatusResponse, 'futures.order_status'