diff --git a/src/contract-client.ts b/src/contract-client.ts index 6878194..6844b1c 100644 --- a/src/contract-client.ts +++ b/src/contract-client.ts @@ -1,27 +1,26 @@ import { APIResponseWithTime, APIResponseV3, - InternalTransferRequest, - UM7DayTradingHistoryRequest, - UMBorrowHistoryRequest, UMCandlesRequest, UMCategory, - UMExchangeCoinsRequest, UMFundingRateHistoryRequest, UMInstrumentInfoRequest, UMOpenInterestRequest, UMOptionDeliveryPriceRequest, - UMOptionsSettlementHistoryRequest, - UMPerpSettlementHistoryRequest, UMPublicTradesRequest, - UMSetTPSLRequest, - UMTransactionLogRequest, ContractOrderRequest, ContractHistoricOrdersRequest, ContractCancelOrderRequest, ContractModifyOrderRequest, ContractActiveOrdersRequest, ContractPositionsRequest, + ContractSetAutoAddMarginRequest, + ContractSetMarginSwitchRequest, + ContractSetPositionModeRequest, + ContractSetTPSLRequest, + ContractUserExecutionHistoryRequest, + ContractClosedPNLRequest, + ContractWalletFundRecordRequest, } from './types'; import { REST_CLIENT_TYPE_ENUM } from './util'; import BaseRestClient from './util/BaseRestClient'; @@ -192,12 +191,9 @@ export class ContractClient extends BaseRestClient { } /** Set auto add margin, or Auto-Margin Replenishment. */ - setAuthAddMargin(params: { - symbol: string; - side: string; - autoAddMargin: 1 | 0; - positionIdx?: 0 | 1 | 2; - }): Promise> { + setAutoAddMargin( + params: ContractSetAutoAddMarginRequest + ): Promise> { return this.postPrivate( '/contract/v3/private/position/set-auto-add-margin', params @@ -205,12 +201,9 @@ export class ContractClient extends BaseRestClient { } /** Switch cross margin mode/isolated margin mode */ - setMarginSwitch(params: { - symbol: string; - tradeMode: 0 | 1; - buyLeverage: string; - sellLeverage: string; - }): Promise> { + setMarginSwitch( + params: ContractSetMarginSwitchRequest + ): Promise> { return this.postPrivate( '/contract/v3/private/position/switch-isolated', params @@ -218,11 +211,9 @@ export class ContractClient extends BaseRestClient { } /** Supports switching between One-Way Mode and Hedge Mode at the coin level. */ - setPositionMode(params: { - symbol?: string; - coin?: string; - mode: 0 | 3; - }): Promise> { + setPositionMode( + params: ContractSetPositionModeRequest + ): Promise> { return this.postPrivate( '/contract/v3/private/position/switch-mode', params @@ -259,19 +250,7 @@ export class ContractClient extends BaseRestClient { * Set take profit, stop loss, and trailing stop for your open position. * If using partial mode, TP/SL/TS orders will not close your entire position. */ - setTPSL(params: { - symbol: string; - takeProfit?: string; - stopLoss?: string; - activePrice?: string; - trailingStop?: string; - tpTriggerBy?: string; - slTriggerBy?: string; - slSize?: string; - tpSize?: string; - /** 0-one-way, 1-buy side, 2-sell side */ - positionIdx?: 0 | 1 | 2; - }): Promise> { + setTPSL(params: ContractSetTPSLRequest): Promise> { return this.postPrivate( '/contract/v3/private/position/trading-stop', params @@ -296,15 +275,9 @@ export class ContractClient extends BaseRestClient { * Get user's trading records. * The results are ordered in descending order (the first item is the latest). Returns records up to 2 years old. */ - getUserExecutionHistory(params: { - symbol: string; - orderId?: string; - startTime?: number; - endTime?: number; - execType?: 'Trade' | 'AdlTrade' | 'Funding' | 'BustTrade'; - limit?: number; - cursor?: string; - }): Promise> { + getUserExecutionHistory( + params: ContractUserExecutionHistoryRequest + ): Promise> { return this.getPrivate('/contract/v3/private/execution/list', params); } @@ -312,13 +285,9 @@ export class ContractClient extends BaseRestClient { * Get user's closed profit and loss records. * The results are ordered in descending order (the first item is the latest). */ - getClosedProfitAndLoss(params: { - symbol: string; - startTime?: number; - endTime?: number; - limit?: number; - cursor?: string; - }): Promise> { + getClosedProfitAndLoss( + params: ContractClosedPNLRequest + ): Promise> { return this.getPrivate('/contract/v3/private/position/closed-pnl', params); } @@ -351,14 +320,9 @@ export class ContractClient extends BaseRestClient { * This endpoint returns incomplete information for transfers involving the derivatives wallet. * Use the account asset API for creating and querying internal transfers. */ - getWalletFundRecords(params?: { - startTime?: string; - endTime?: string; - coin?: string; - walletFundType?: string; - limit?: string; - cursor?: string; - }): Promise> { + getWalletFundRecords( + params?: ContractWalletFundRecordRequest + ): Promise> { return this.getPrivate( '/contract/v3/private/account/wallet/fund-records', params diff --git a/src/types/request/contract.ts b/src/types/request/contract.ts index 7b4ce52..88828c5 100644 --- a/src/types/request/contract.ts +++ b/src/types/request/contract.ts @@ -65,3 +65,64 @@ export interface ContractPositionsRequest { settleCoin?: string; dataFilter?: string; } + +export interface ContractSetAutoAddMarginRequest { + symbol: string; + side: string; + autoAddMargin: 1 | 0; + positionIdx?: 0 | 1 | 2; +} + +export interface ContractSetMarginSwitchRequest { + symbol: string; + tradeMode: 0 | 1; + buyLeverage: string; + sellLeverage: string; +} + +export interface ContractSetPositionModeRequest { + symbol?: string; + coin?: string; + mode: 0 | 3; +} + +export interface ContractSetTPSLRequest { + symbol: string; + takeProfit?: string; + stopLoss?: string; + activePrice?: string; + trailingStop?: string; + tpTriggerBy?: string; + slTriggerBy?: string; + slSize?: string; + tpSize?: string; + /** 0-one-way, 1-buy side, 2-sell side */ + positionIdx?: 0 | 1 | 2; +} + +export interface ContractUserExecutionHistoryRequest { + symbol: string; + orderId?: string; + startTime?: number; + endTime?: number; + execType?: 'Trade' | 'AdlTrade' | 'Funding' | 'BustTrade'; + limit?: number; + cursor?: string; +} + +export interface ContractClosedPNLRequest { + symbol: string; + startTime?: number; + endTime?: number; + limit?: number; + cursor?: string; +} + +export interface ContractWalletFundRecordRequest { + startTime?: string; + endTime?: string; + coin?: string; + walletFundType?: string; + limit?: string; + cursor?: string; +}