diff --git a/src/rest-client-v5.ts b/src/rest-client-v5.ts index df6988b..a04a488 100644 --- a/src/rest-client-v5.ts +++ b/src/rest-client-v5.ts @@ -18,7 +18,6 @@ import { GetRiskLimitParamsV5, GetTickersParamsV5, HistoricalVolatilityV5, - InstrumentInfoV5, InsuranceResponseV5, OpenInterestResponseV5, OrderbookResponseV5, @@ -47,8 +46,8 @@ import { AccountOrderV5, OptionDeliveryPriceV5, CategorySymbolListV5, - OHLCV5, - KlineV5, + OHLCKlineV5, + OHLCVKlineV5, TickerSpotV5, TickerOptionV5, TickerLinearInverseV5, @@ -123,6 +122,7 @@ import { RedeemSpotLeveragedTokenResultV5, GetSpotLeveragedTokenOrderHistoryParamsV5, SpotLeveragedTokenOrderHistoryV5, + InstrumentInfoResponseV5, } from './types'; import { REST_CLIENT_TYPE_ENUM } from './util'; import BaseRestClient from './util/BaseRestClient'; @@ -163,7 +163,7 @@ export class RestClientV5 extends BaseRestClient { params: GetKlineParamsV5 ): Promise< APIResponseV3WithTime< - CategorySymbolListV5 + CategorySymbolListV5 > > { return this.get(`/v5/market/kline`, params); @@ -177,7 +177,9 @@ export class RestClientV5 extends BaseRestClient { getMarkPriceKline( params: GetMarkPriceKlineParamsV5 ): Promise< - APIResponseV3WithTime> + APIResponseV3WithTime< + CategorySymbolListV5 + > > { return this.get(`/v5/market/mark-price-kline`, params); } @@ -190,7 +192,9 @@ export class RestClientV5 extends BaseRestClient { getIndexPriceKline( params: GetIndexPriceKlineParamsV5 ): Promise< - APIResponseV3WithTime> + APIResponseV3WithTime< + CategorySymbolListV5 + > > { return this.get(`/v5/market/index-price-kline`, params); } @@ -202,7 +206,9 @@ export class RestClientV5 extends BaseRestClient { */ getPremiumIndexPriceKline( params: GetPremiumIndexPriceKlineParams - ): Promise>> { + ): Promise< + APIResponseV3WithTime> + > { return this.get(`/v5/market/premium-index-price-kline`, params); } @@ -215,7 +221,7 @@ export class RestClientV5 extends BaseRestClient { */ getInstrumentsInfo( params: GetInstrumentsInfoParamsV5 - ): Promise>> { + ): Promise> { return this.get(`/v5/market/instruments-info`, params); } diff --git a/src/types/request/v5-market.ts b/src/types/request/v5-market.ts index c23ccdb..dd4e512 100644 --- a/src/types/request/v5-market.ts +++ b/src/types/request/v5-market.ts @@ -1,5 +1,5 @@ import { KlineIntervalV3 } from '../shared'; -import { CategoryV5 } from '../v5-shared'; +import { CategoryV5, OptionTypeV5 } from '../v5-shared'; export interface GetKlineParamsV5 { category: 'spot' | 'linear' | 'inverse'; @@ -66,13 +66,11 @@ export interface GetFundingRateHistoryParamsV5 { limit?: number; } -export type OptionType = 'Call' | 'Put'; - export interface GetPublicTradingHistoryParamsV5 { category: CategoryV5; symbol: string; baseCoin?: string; - optionType?: OptionType; + optionType?: OptionTypeV5; limit?: number; } diff --git a/src/types/request/v5-position.ts b/src/types/request/v5-position.ts index f378771..ae9f923 100644 --- a/src/types/request/v5-position.ts +++ b/src/types/request/v5-position.ts @@ -1,4 +1,4 @@ -import { CategoryV5, TPSLModeV5 } from '../v5-shared'; +import { CategoryV5, ExecTypeV5, PositionIdx, TPSLModeV5 } from '../v5-shared'; export interface PositionInfoParamsV5 { category: CategoryV5; @@ -41,7 +41,7 @@ export interface SetRiskLimitParamsV5 { category: 'linear' | 'inverse'; symbol: string; riskId: number; - positionIdx?: number; + positionIdx?: PositionIdx; } export interface SetTradingStopParamsV5 { @@ -55,14 +55,14 @@ export interface SetTradingStopParamsV5 { activePrice?: string; tpSize?: string; slSize?: string; - positionIdx: number; + positionIdx: PositionIdx; } export interface SetAutoAddMarginParamsV5 { category: 'linear'; symbol: string; autoAddMargin: 0 | 1; - positionIdx?: number; + positionIdx?: PositionIdx; } export interface GetExecutionListParamsV5 { @@ -73,7 +73,7 @@ export interface GetExecutionListParamsV5 { baseCoin?: string; startTime?: number; endTime?: number; - execType?: string; + execType?: ExecTypeV5; limit?: number; cursor?: string; } diff --git a/src/types/response/v5-account.ts b/src/types/response/v5-account.ts index 7e99ea0..33fa08b 100644 --- a/src/types/response/v5-account.ts +++ b/src/types/response/v5-account.ts @@ -1,4 +1,10 @@ -import { AccountTypeV5, CategoryV5, TransactionTypeV5 } from '../v5-shared'; +import { + AccountMarginModeV5, + AccountTypeV5, + CategoryV5, + TransactionTypeV5, + UnifiedUpdateStatusV5, +} from '../v5-shared'; export interface WalletBalanceV5Coin { coin: string; @@ -30,8 +36,6 @@ export interface WalletBalanceV5 { coin: WalletBalanceV5Coin[]; } -export type UnifiedUpdateStatusV5 = 'FAIL' | 'PROCESS' | 'SUCCESS'; - export interface UnifiedAccountUpgradeResultV5 { unifiedUpdateStatus: UnifiedUpdateStatusV5; unifiedUpdateMsg: { @@ -76,7 +80,7 @@ export interface FeeRateV5 { export interface AccountInfoV5 { unifiedMarginStatus: number; - marginMode: 'REGULAR_MARGIN' | 'PORTFOLIO_MARGIN'; + marginMode: AccountMarginModeV5; updatedTime: string; } diff --git a/src/types/response/v5-asset.ts b/src/types/response/v5-asset.ts index 2edbd5a..a56d166 100644 --- a/src/types/response/v5-asset.ts +++ b/src/types/response/v5-asset.ts @@ -1,4 +1,4 @@ -import { AccountTypeV5, OrderSideV5 } from '../v5-shared'; +import { AccountTypeV5, OrderSideV5, WithdrawalTypeV5 } from '../v5-shared'; export interface CoinExchangeRecordV5 { fromCoin: string; @@ -135,7 +135,7 @@ export interface CoinInfoV5 { export interface WithdrawalRecordV5 { withdrawId: string; txID: string; - withdrawType: string; + withdrawType: WithdrawalTypeV5; coin: string; chain: string; amount: string; diff --git a/src/types/response/v5-market.ts b/src/types/response/v5-market.ts index 5c00194..0cefd63 100644 --- a/src/types/response/v5-market.ts +++ b/src/types/response/v5-market.ts @@ -1,104 +1,121 @@ +import { + CategoryCursorListV5, + ContractTypeV5, + InstrumentStatusV5, + OptionTypeV5, + OrderSideV5, +} from '../v5-shared'; + /** * OHLCVT candle used by v5 APIs * - * > list[0]: startTime string Start time of the candle (ms) - * - * > list[1]: openPrice string Open price - * - * > list[2]: highPrice string Highest price - * - * > list[3]: lowPrice string Lowest price - * - * > list[4]: closePrice string Close price. Is the last traded price when the candle is not closed - * - * > list[5]: volume string Trade volume. Unit of contract: pieces of contract. Unit of spot: quantity of coins - * - * > list[6]: turnover string Turnover. Unit of figure: quantity of quota coin + * - list[0]: startTime string Start time of the candle (ms) + * - list[1]: openPrice string Open price + * - list[2]: highPrice string Highest price + * - list[3]: lowPrice string Lowest price + * - list[4]: closePrice string Close price. Is the last traded price when the candle is not closed + * - list[5]: volume string Trade volume. Unit of contract: pieces of contract. Unit of spot: quantity of coins + * - list[6]: turnover string Turnover. Unit of figure: quantity of quota coin */ -export type KlineV5 = [string, string, string, string, string, string, string]; +export type OHLCVKlineV5 = [ + string, + string, + string, + string, + string, + string, + string +]; /** * OHLC candle used by v5 APIs * - * > list[0]: startTime string Start time of the candle (ms) - * - * > list[1]: openPrice string Open price - * - * > list[2]: highPrice string Highest price - * - * > list[3]: lowPrice string Lowest price - * - * > list[4]: closePrice string Close price. Is the last traded price when the candle is not closed + * - list[0]: startTime string Start time of the candle (ms) + * - list[1]: openPrice string Open price + * - list[2]: highPrice string Highest price + * - list[3]: lowPrice string Lowest price + * - list[4]: closePrice string Close price. Is the last traded price when the candle is not closed */ -export type OHLCV5 = [string, string, string, string, string]; +export type OHLCKlineV5 = [string, string, string, string, string]; export interface LinearInverseInstrumentInfoV5 { - category: 'linear' | 'inverse'; symbol: string; - contractType: string; - status: string; + contractType: ContractTypeV5; + status: InstrumentStatusV5; baseCoin: string; quoteCoin: string; launchTime: string; - deliveryTime: string; - deliveryFeeRate: string; + deliveryTime?: string; + deliveryFeeRate?: string; priceScale: string; - maxLeverage: string; - minOrderValue: string; - minOrderVolume: string; - makerFeeRate: string; - takerFeeRate: string; + leverageFilter: { + minLeverage: string; + maxLeverage: string; + leverageStep: string; + }; + priceFilter: { + minPrice: string; + maxPrice: string; + tickSize: string; + }; + lotSizeFilter: { + maxOrderQty: string; + minOrderQty: string; + qtyStep: string; + postOnlyMaxOrderQty?: string; + }; + unifiedMarginTrade: boolean; + fundingInterval: number; + settleCoin: string; } export interface OptionInstrumentInfoV5 { - category: 'option'; symbol: string; - contractType: string; - status: string; + optionsType: OptionTypeV5; + status: InstrumentStatusV5; baseCoin: string; quoteCoin: string; + settleCoin: boolean; launchTime: string; deliveryTime: string; deliveryFeeRate: string; - priceScale: string; - maxLeverage: string; - minOrderValue: string; - minOrderVolume: string; - makerFeeRate: string; - takerFeeRate: string; - settlementCurrency: string; - settlementPrice: string; - deliveryMethod: string; - optionType: string; - exercisePrice: string; - expirationTime: string; - blockMarginRatio: string; - marginType: string; - strike: string; + priceFilter: { + minPrice: string; + maxPrice: string; + tickSize: string; + }; + lotSizeFilter: { + maxOrderQty: string; + minOrderQty: string; + qtyStep: string; + }; } export interface SpotInstrumentInfoV5 { - category: 'spot'; symbol: string; - contractType: string; - status: string; baseCoin: string; quoteCoin: string; - launchTime: string; - priceScale: string; - maxLeverage: string; - minOrderValue: string; - minOrderVolume: string; - makerFeeRate: string; - takerFeeRate: string; + innovation: '0' | '1'; + status: InstrumentStatusV5; + lotSizeFilter: { + basePrecision: string; + quotePrecision: string; + minOrderQty: string; + maxOrderQty: string; + minOrderAmt: string; + maxOrderAmt: string; + }; + priceFilter: { + tickSize: string; + }; } -export type InstrumentInfoV5 = - | LinearInverseInstrumentInfoV5 - | OptionInstrumentInfoV5 - | SpotInstrumentInfoV5; +export type InstrumentInfoResponseV5 = + | CategoryCursorListV5 + | CategoryCursorListV5 + | CategoryCursorListV5; -export interface OrderbookLevelV5 { +export default interface OrderbookLevelV5 { price: string; size: string; } @@ -192,16 +209,16 @@ export interface PublicTradeV5 { symbol: string; price: string; size: string; - side: 'Buy' | 'Sell'; + side: OrderSideV5; time: string; isBlockTrade: boolean; } /** -> openInterest string Open interest - -> timestamp string The timestamp (ms) -*/ + * + * - openInterest string Open interest + * - timestamp string The timestamp (ms) + */ export type OpenInterestV5 = [string, string]; export interface OpenInterestResponseV5 { diff --git a/src/types/response/v5-position.ts b/src/types/response/v5-position.ts index 768d226..7cedeec 100644 --- a/src/types/response/v5-position.ts +++ b/src/types/response/v5-position.ts @@ -1,8 +1,10 @@ import { CategoryV5, + ExecTypeV5, OrderSideV5, OrderTypeV5, PositionIdx, + StopOrderTypeV5, TPSLModeV5, TradeModeV5, } from '../v5-shared'; @@ -50,12 +52,12 @@ export interface ExecutionV5 { orderQty: string; leavesQty: string; orderType: OrderTypeV5; - stopOrderType?: string; + stopOrderType?: StopOrderTypeV5; execFee: string; execId: string; execPrice: string; execQty: string; - execType: string; + execType: ExecTypeV5; execValue: string; execTime: string; isMaker: boolean; @@ -74,8 +76,8 @@ export interface ClosedPnLV5 { side: string; qty: string; orderPrice: string; - orderType: string; - execType: string; + orderType: OrderTypeV5; + execType: ExecTypeV5; closedSize: string; cumEntryValue: string; avgEntryPrice: string; diff --git a/src/types/response/v5-trade.ts b/src/types/response/v5-trade.ts index 78f7fdf..c2f3289 100644 --- a/src/types/response/v5-trade.ts +++ b/src/types/response/v5-trade.ts @@ -1,10 +1,14 @@ import { CategoryV5, + OrderCancelTypeV5, + OrderRejectReasonV5, OrderSideV5, + OrderStatusV5, OrderTimeInForceV5, OrderTriggerByV5, OrderTypeV5, PositionIdx, + StopOrderTypeV5, } from '../v5-shared'; export interface OrderResultV5 { @@ -22,9 +26,9 @@ export interface AccountOrderV5 { side: OrderSideV5; isLeverage?: string; positionIdx?: PositionIdx; - orderStatus: string; - cancelType?: string; - rejectReason?: string; + orderStatus: OrderStatusV5; + cancelType?: OrderCancelTypeV5; + rejectReason?: OrderRejectReasonV5; avgPrice: string; leavesQty: string; leavesValue: string; @@ -33,7 +37,7 @@ export interface AccountOrderV5 { cumExecFee: string; timeInForce?: OrderTimeInForceV5; orderType?: OrderTypeV5; - stopOrderType?: string; + stopOrderType?: StopOrderTypeV5; orderIv?: string; triggerPrice?: string; takeProfit?: string; diff --git a/src/types/v5-shared.ts b/src/types/v5-shared.ts index 916bfa7..9896b12 100644 --- a/src/types/v5-shared.ts +++ b/src/types/v5-shared.ts @@ -1,17 +1,95 @@ export type CategoryV5 = 'spot' | 'linear' | 'inverse' | 'option'; +export type ContractTypeV5 = + | 'InversePerpetual' + | 'LinearPerpetual' + | 'InverseFutures'; + +export type InstrumentStatusV5 = 'Pending' | 'Trading' | 'Settling' | 'Closed'; export type OrderFilterV5 = 'Order' | 'tpslOrder'; export type OrderSideV5 = 'Buy' | 'Sell'; export type OrderTypeV5 = 'Market' | 'Limit'; export type OrderTimeInForceV5 = 'GTC' | 'IOC' | 'FOK' | 'PostOnly'; export type OrderTriggerByV5 = 'LastPrice' | 'IndexPrice' | 'MarkPrice'; -export type PositionIdx = 0 | 1 | 2; +export type OrderStatusV5 = + | 'Created' + | 'New' + | 'Rejected' + | 'PartiallyFilled' + | 'PartiallyFilledCanceled' + | 'Filled' + | 'Cancelled' + | 'Untriggered' + | 'Triggered' + | 'Deactivated' + | 'Active'; + +export type OrderCancelTypeV5 = + | 'CancelByUser' + | 'CancelByReduceOnly' + | 'CancelByPrepareLiq' + | 'CancelAllBeforeLiq' + | 'CancelByPrepareAdl' + | 'CancelAllBeforeAdl' + | 'CancelByAdmin' + | 'CancelByTpSlTsClear' + | 'CancelByPzSideCh'; + +export type OrderRejectReasonV5 = + | 'EC_NoError' + | 'EC_Others' + | 'EC_UnknownMessageType' + | 'EC_MissingClOrdID' + | 'EC_MissingOrigClOrdID' + | 'EC_ClOrdIDOrigClOrdIDAreTheSame' + | 'EC_DuplicatedClOrdID' + | 'EC_OrigClOrdIDDoesNotExist' + | 'EC_TooLateToCancel' + | 'EC_UnknownOrderType' + | 'EC_UnknownSide' + | 'EC_UnknownTimeInForce' + | 'EC_WronglyRouted' + | 'EC_MarketOrderPriceIsNotZero' + | 'EC_LimitOrderInvalidPrice' + | 'EC_NoEnoughQtyToFill' + | 'EC_NoImmediateQtyToFill' + | 'EC_PerCancelRequest' + | 'EC_MarketOrderCannotBePostOnly' + | 'EC_PostOnlyWillTakeLiquidity' + | 'EC_CancelReplaceOrder' + | 'EC_InvalidSymbolStatus'; + +export type StopOrderTypeV5 = + | 'TakeProfit' + | 'StopLoss' + | 'TrailingStop' + | 'Stop' + | 'PartialTakeProfit' + | 'PartialStopLoss' + | 'tpslOrder'; + /** - * Trade mode. 0: cross-margin, 1: isolated margin + * Position index. Used to identify positions in different position modes. + * + * - 0 one-way mode position + * - 1 Buy side of hedge-mode position + * - 2 Sell side of hedge-mode position + */ +export type PositionIdx = 0 | 1 | 2; + +export type OptionTypeV5 = 'Call' | 'Put'; + +/** + * Trade mode. + * + * - 0 cross-margin, + * - 1 isolated margin */ export type TradeModeV5 = 0 | 1; + export type TPSLModeV5 = 'Full' | 'Partial'; export type AccountMarginModeV5 = 'REGULAR_MARGIN' | 'PORTFOLIO_MARGIN'; +export type UnifiedUpdateStatusV5 = 'FAIL' | 'PROCESS' | 'SUCCESS'; export type AccountTypeV5 = | 'CONTRACT' @@ -68,6 +146,18 @@ export type LTOrderTypeV5 = '1' | '2'; */ export type LTOrderStatusV5 = '1' | '2' | '3'; +export type ExecTypeV5 = + | 'Trade' + | 'AdlTrade' + | 'Funding' + | 'BustTrade' + | 'Settle'; + +/** + * Withdraw type. 0(default): on chain. 1: off chain. 2: all. + */ +export type WithdrawalTypeV5 = '0' | '1' | '2'; + export interface PermissionsV5 { ContractTrade?: string[]; Spot?: string[]; @@ -78,8 +168,11 @@ export interface PermissionsV5 { NFT?: string[]; } -export interface CategoryCursorListV5 { - category: CategoryV5; +export interface CategoryCursorListV5< + T extends unknown[], + TCategory extends CategoryV5 = CategoryV5 +> { + category: TCategory; list: T; nextPageCursor?: string; }