diff --git a/src/inverse-client.ts b/src/inverse-client.ts index 1d3354f..1f9ebee 100644 --- a/src/inverse-client.ts +++ b/src/inverse-client.ts @@ -3,6 +3,22 @@ import { APIResponseWithTime, AssetExchangeRecordsReq, CoinParam, + InverseActiveConditionalOrderRequest, + InverseActiveOrdersRequest, + InverseCancelConditionalOrderRequest, + InverseCancelOrderRequest, + InverseChangePositionMarginRequest, + InverseConditionalOrderRequest, + InverseGetClosedPnlRequest, + InverseGetOrderRequest, + InverseGetTradeRecordsRequest, + InverseOrderRequest, + InverseReplaceConditionalOrderRequest, + InverseReplaceOrderRequest, + InverseSetLeverageRequest, + InverseSetMarginTypeRequest, + InverseSetSlTpPositionModeRequest, + InverseSetTradingStopRequest, SymbolInfo, SymbolIntervalFromLimitParam, SymbolLimitParam, @@ -165,39 +181,21 @@ export class InverseClient extends BaseRestClient { * Active orders */ - placeActiveOrder(orderRequest: { - side: string; - symbol: string; - order_type: string; - qty: number; - price?: number; - time_in_force: string; - take_profit?: number; - stop_loss?: number; - reduce_only?: boolean; - tp_trigger_by?: 'LastPrice' | 'MarkPrice' | 'IndexPrice'; - sl_trigger_by?: 'LastPrice' | 'MarkPrice' | 'IndexPrice'; - close_on_trigger?: boolean; - order_link_id?: string; - }): Promise> { + placeActiveOrder( + orderRequest: InverseOrderRequest + ): Promise> { return this.postPrivate('v2/private/order/create', orderRequest); } - getActiveOrderList(params: { - symbol: string; - order_status?: string; - direction?: string; - limit?: number; - cursor?: string; - }): Promise> { + getActiveOrderList( + params: InverseActiveOrdersRequest + ): Promise> { return this.getPrivate('v2/private/order/list', params); } - cancelActiveOrder(params: { - symbol: string; - order_id?: string; - order_link_id?: string; - }): Promise> { + cancelActiveOrder( + params: InverseCancelOrderRequest + ): Promise> { return this.postPrivate('v2/private/order/cancel', params); } @@ -207,25 +205,15 @@ export class InverseClient extends BaseRestClient { return this.postPrivate('v2/private/order/cancelAll', params); } - replaceActiveOrder(params: { - order_id?: string; - order_link_id?: string; - symbol: string; - p_r_qty?: number; - p_r_price?: string; - take_profit?: number; - stop_loss?: number; - tp_trigger_by?: string; - sl_trigger_by?: string; - }): Promise> { + replaceActiveOrder( + params: InverseReplaceOrderRequest + ): Promise> { return this.postPrivate('v2/private/order/replace', params); } - queryActiveOrder(params: { - order_id?: string; - order_link_id?: string; - symbol: string; - }): Promise> { + queryActiveOrder( + params: InverseGetOrderRequest + ): Promise> { return this.getPrivate('v2/private/order', params); } @@ -233,38 +221,22 @@ export class InverseClient extends BaseRestClient { * Conditional orders */ - placeConditionalOrder(params: { - side: string; - symbol: string; - order_type: string; - qty: string; - price?: string; - base_price: string; - stop_px: string; - time_in_force: string; - trigger_by?: string; - close_on_trigger?: boolean; - order_link_id?: string; - }): Promise> { + placeConditionalOrder( + params: InverseConditionalOrderRequest + ): Promise> { return this.postPrivate('v2/private/stop-order/create', params); } /** get conditional order list. This may see delays, use queryConditionalOrder() for real-time queries */ - getConditionalOrder(params: { - symbol: string; - stop_order_status?: string; - direction?: string; - limit?: number; - cursor?: string; - }): Promise> { + getConditionalOrder( + params: InverseActiveConditionalOrderRequest + ): Promise> { return this.getPrivate('v2/private/stop-order/list', params); } - cancelConditionalOrder(params: { - symbol: string; - stop_order_id?: string; - order_link_id?: string; - }): Promise> { + cancelConditionalOrder( + params: InverseCancelConditionalOrderRequest + ): Promise> { return this.postPrivate('v2/private/stop-order/cancel', params); } @@ -274,22 +246,15 @@ export class InverseClient extends BaseRestClient { return this.postPrivate('v2/private/stop-order/cancelAll', params); } - replaceConditionalOrder(params: { - stop_order_id?: string; - order_link_id?: string; - symbol: string; - p_r_qty?: number; - p_r_price?: string; - p_r_trigger_price?: string; - }): Promise> { + replaceConditionalOrder( + params: InverseReplaceConditionalOrderRequest + ): Promise> { return this.postPrivate('v2/private/stop-order/replace', params); } - queryConditionalOrder(params: { - symbol: string; - stop_order_id?: string; - order_link_id?: string; - }): Promise> { + queryConditionalOrder( + params: InverseGetOrderRequest + ): Promise> { return this.getPrivate('v2/private/stop-order', params); } @@ -303,68 +268,45 @@ export class InverseClient extends BaseRestClient { return this.getPrivate('v2/private/position/list', params); } - changePositionMargin(params: { - symbol: string; - margin: string; - }): Promise> { + changePositionMargin( + params: InverseChangePositionMarginRequest + ): Promise> { return this.postPrivate('position/change-position-margin', params); } - setTradingStop(params: { - symbol: string; - take_profit?: number; - stop_loss?: number; - trailing_stop?: number; - tp_trigger_by?: string; - sl_trigger_by?: string; - new_trailing_active?: number; - }): Promise> { + setTradingStop( + params: InverseSetTradingStopRequest + ): Promise> { return this.postPrivate('v2/private/position/trading-stop', params); } - setUserLeverage(params: { - symbol: string; - leverage: number; - leverage_only?: boolean; - }): Promise> { + setUserLeverage( + params: InverseSetLeverageRequest + ): Promise> { return this.postPrivate('v2/private/position/leverage/save', params); } - getTradeRecords(params: { - order_id?: string; - symbol: string; - start_time?: number; - page?: number; - limit?: number; - order?: string; - }): Promise> { + getTradeRecords( + params: InverseGetTradeRecordsRequest + ): Promise> { return this.getPrivate('v2/private/execution/list', params); } - getClosedPnl(params: { - symbol: string; - start_time?: number; - end_time?: number; - exec_type?: string; - page?: number; - limit?: number; - }): Promise> { + getClosedPnl( + params: InverseGetClosedPnlRequest + ): Promise> { return this.getPrivate('v2/private/trade/closed-pnl/list', params); } - setSlTpPositionMode(params: { - symbol: string; - tp_sl_mode: 'Full' | 'Partial'; - }): Promise> { + setSlTpPositionMode( + params: InverseSetSlTpPositionModeRequest + ): Promise> { return this.postPrivate('v2/private/tpsl/switch-mode', params); } - setMarginType(params: { - symbol: string; - is_isolated: boolean; - buy_leverage: number; - sell_leverage: number; - }): Promise> { + setMarginType( + params: InverseSetMarginTypeRequest + ): Promise> { return this.postPrivate('v2/private/position/switch-isolated', params); } diff --git a/src/types/request/index.ts b/src/types/request/index.ts index 8ee5bfd..88721cd 100644 --- a/src/types/request/index.ts +++ b/src/types/request/index.ts @@ -1,5 +1,6 @@ export * from './account-asset'; export * from './copy-trading'; +export * from './inverse'; export * from './spot'; export * from './usdt-perp'; export * from './usdc-perp'; diff --git a/src/types/request/inverse.ts b/src/types/request/inverse.ts new file mode 100644 index 0000000..c3e453c --- /dev/null +++ b/src/types/request/inverse.ts @@ -0,0 +1,135 @@ +export interface InverseOrderRequest { + side: string; + symbol: string; + order_type: string; + qty: number; + price?: number; + time_in_force: string; + take_profit?: number; + stop_loss?: number; + reduce_only?: boolean; + tp_trigger_by?: 'LastPrice' | 'MarkPrice' | 'IndexPrice'; + sl_trigger_by?: 'LastPrice' | 'MarkPrice' | 'IndexPrice'; + close_on_trigger?: boolean; + order_link_id?: string; +} + +export interface InverseActiveOrdersRequest { + symbol: string; + order_status?: string; + direction?: string; + limit?: number; + cursor?: string; +} + +export interface InverseCancelOrderRequest { + symbol: string; + order_id?: string; + order_link_id?: string; +} + +export interface InverseReplaceOrderRequest { + order_id?: string; + order_link_id?: string; + symbol: string; + p_r_qty?: number; + p_r_price?: string; + take_profit?: number; + stop_loss?: number; + tp_trigger_by?: string; + sl_trigger_by?: string; +} + +export interface InverseGetOrderRequest { + order_id?: string; + order_link_id?: string; + symbol: string; +} + +export interface InverseConditionalOrderRequest { + side: string; + symbol: string; + order_type: string; + qty: string; + price?: string; + base_price: string; + stop_px: string; + time_in_force: string; + trigger_by?: string; + close_on_trigger?: boolean; + order_link_id?: string; +} + +export interface InverseActiveConditionalOrderRequest { + symbol: string; + stop_order_status?: string; + direction?: string; + limit?: number; + cursor?: string; +} + +export interface InverseCancelConditionalOrderRequest { + symbol: string; + stop_order_id?: string; + order_link_id?: string; +} + +export interface InverseReplaceConditionalOrderRequest { + stop_order_id?: string; + order_link_id?: string; + symbol: string; + p_r_qty?: number; + p_r_price?: string; + p_r_trigger_price?: string; +} + +export interface InverseChangePositionMarginRequest { + symbol: string; + margin: string; +} + +export interface InverseSetTradingStopRequest { + symbol: string; + take_profit?: number; + stop_loss?: number; + trailing_stop?: number; + tp_trigger_by?: string; + sl_trigger_by?: string; + new_trailing_active?: number; +} + +export interface InverseSetLeverageRequest { + symbol: string; + leverage: number; + leverage_only?: boolean; +} + +export interface InverseGetTradeRecordsRequest { + order_id?: string; + symbol: string; + start_time?: number; + page?: number; + limit?: number; + order?: string; +} + +export interface InverseGetClosedPnlRequest { + symbol: string; + start_time?: number; + end_time?: number; + exec_type?: string; + page?: number; + limit?: number; +} + +export interface InverseSetSlTpPositionModeRequest { + symbol: string; + tp_sl_mode: 'Full' | 'Partial'; +} + +export interface InverseSetMarginTypeRequest { + symbol: string; + is_isolated: boolean; + buy_leverage: number; + sell_leverage: number; +}