/* eslint-disable @typescript-eslint/no-explicit-any */ import { REST_CLIENT_TYPE_ENUM } from './util'; import { APIResponseWithTime, AssetExchangeRecordsReq, CoinParam, InverseActiveConditionalOrderRequest, InverseActiveOrdersRequest, InverseCancelConditionalOrderRequest, InverseCancelOrderRequest, InverseChangePositionMarginRequest, InverseConditionalOrderRequest, InverseGetClosedPnlRequest, InverseGetOrderRequest, InverseGetTradeRecordsRequest, InverseOrderRequest, InverseReplaceConditionalOrderRequest, InverseReplaceOrderRequest, InverseSetLeverageRequest, InverseSetMarginTypeRequest, InverseSetSlTpPositionModeRequest, InverseSetTradingStopRequest, SymbolInfo, SymbolIntervalFromLimitParam, SymbolLimitParam, SymbolParam, SymbolPeriodLimitParam, WalletFundRecordsReq, WithdrawRecordsReq, } from './types'; import BaseRestClient from './util/BaseRestClient'; /** * REST API client for Inverse Perpetual Futures APIs (v2) */ export class InverseClient extends BaseRestClient { getClientType() { return REST_CLIENT_TYPE_ENUM.inverse; } async fetchServerTime(): Promise { const res = await this.getServerTime(); return Number(res.time_now); } /** * * Market Data Endpoints * */ getOrderBook(params: SymbolParam): Promise> { return this.get('v2/public/orderBook/L2', params); } getKline( params: SymbolIntervalFromLimitParam ): Promise> { return this.get('v2/public/kline/list', params); } /** * Get latest information for symbol */ getTickers( params?: Partial ): Promise> { return this.get('v2/public/tickers', params); } getTrades(params: SymbolLimitParam): Promise> { return this.get('v2/public/trading-records', params); } getSymbols(): Promise> { return this.get('v2/public/symbols'); } getMarkPriceKline( params: SymbolIntervalFromLimitParam ): Promise> { return this.get('v2/public/mark-price-kline', params); } getIndexPriceKline( params: SymbolIntervalFromLimitParam ): Promise> { return this.get('v2/public/index-price-kline', params); } getPremiumIndexKline( params: SymbolIntervalFromLimitParam ): Promise> { return this.get('v2/public/premium-index-kline', params); } /** * * Market Data : Advanced * */ getOpenInterest( params: SymbolPeriodLimitParam ): Promise> { return this.get('v2/public/open-interest', params); } getLatestBigDeal( params: SymbolLimitParam ): Promise> { return this.get('v2/public/big-deal', params); } getLongShortRatio( params: SymbolPeriodLimitParam ): Promise> { return this.get('v2/public/account-ratio', params); } /** * * Account Data Endpoints * */ getApiKeyInfo(): Promise> { return this.getPrivate('v2/private/account/api-key'); } /** * * Wallet Data Endpoints * */ getWalletBalance( params?: Partial ): Promise> { return this.getPrivate('v2/private/wallet/balance', params); } getWalletFundRecords( params?: WalletFundRecordsReq ): Promise> { return this.getPrivate('v2/private/wallet/fund/records', params); } getWithdrawRecords( params?: WithdrawRecordsReq ): Promise> { return this.getPrivate('v2/private/wallet/withdraw/list', params); } getAssetExchangeRecords( params?: AssetExchangeRecordsReq ): Promise> { return this.getPrivate('v2/private/exchange-order/list', params); } /** * * API Data Endpoints * */ getServerTime(): Promise> { return this.get('v2/public/time'); } getApiAnnouncements(): Promise> { return this.get('v2/public/announcement'); } /** * * Account Data Endpoints * */ /** * Active orders */ placeActiveOrder( orderRequest: InverseOrderRequest ): Promise> { return this.postPrivate('v2/private/order/create', orderRequest); } getActiveOrderList( params: InverseActiveOrdersRequest ): Promise> { return this.getPrivate('v2/private/order/list', params); } cancelActiveOrder( params: InverseCancelOrderRequest ): Promise> { return this.postPrivate('v2/private/order/cancel', params); } cancelAllActiveOrders( params: SymbolParam ): Promise> { return this.postPrivate('v2/private/order/cancelAll', params); } replaceActiveOrder( params: InverseReplaceOrderRequest ): Promise> { return this.postPrivate('v2/private/order/replace', params); } queryActiveOrder( params: InverseGetOrderRequest ): Promise> { return this.getPrivate('v2/private/order', params); } /** * Conditional orders */ 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: InverseActiveConditionalOrderRequest ): Promise> { return this.getPrivate('v2/private/stop-order/list', params); } cancelConditionalOrder( params: InverseCancelConditionalOrderRequest ): Promise> { return this.postPrivate('v2/private/stop-order/cancel', params); } cancelAllConditionalOrders( params: SymbolParam ): Promise> { return this.postPrivate('v2/private/stop-order/cancelAll', params); } replaceConditionalOrder( params: InverseReplaceConditionalOrderRequest ): Promise> { return this.postPrivate('v2/private/stop-order/replace', params); } queryConditionalOrder( params: InverseGetOrderRequest ): Promise> { return this.getPrivate('v2/private/stop-order', params); } /** * Position */ getPosition( params?: Partial ): Promise> { return this.getPrivate('v2/private/position/list', params); } changePositionMargin( params: InverseChangePositionMarginRequest ): Promise> { return this.postPrivate('position/change-position-margin', params); } setTradingStop( params: InverseSetTradingStopRequest ): Promise> { return this.postPrivate('v2/private/position/trading-stop', params); } setUserLeverage( params: InverseSetLeverageRequest ): Promise> { return this.postPrivate('v2/private/position/leverage/save', params); } getTradeRecords( params: InverseGetTradeRecordsRequest ): Promise> { return this.getPrivate('v2/private/execution/list', params); } getClosedPnl( params: InverseGetClosedPnlRequest ): Promise> { return this.getPrivate('v2/private/trade/closed-pnl/list', params); } setSlTpPositionMode( params: InverseSetSlTpPositionModeRequest ): Promise> { return this.postPrivate('v2/private/tpsl/switch-mode', params); } setMarginType( params: InverseSetMarginTypeRequest ): Promise> { return this.postPrivate('v2/private/position/switch-isolated', params); } /** * Funding */ getLastFundingRate(params: SymbolParam): Promise> { return this.get('v2/public/funding/prev-funding-rate', params); } getMyLastFundingFee(params: SymbolParam): Promise> { return this.getPrivate('v2/private/funding/prev-funding', params); } getPredictedFunding(params: SymbolParam): Promise> { return this.getPrivate('v2/private/funding/predicted-funding', params); } /** * LCP Info */ getLcpInfo(params: SymbolParam): Promise> { return this.getPrivate('v2/private/account/lcp', params); } }