fixing and tidying v5 request and response types

This commit is contained in:
tiagosiebler
2023-02-17 12:16:01 +00:00
parent 6d9e73bdda
commit 6a4e7c09ed
9 changed files with 231 additions and 107 deletions

View File

@@ -18,7 +18,6 @@ import {
GetRiskLimitParamsV5, GetRiskLimitParamsV5,
GetTickersParamsV5, GetTickersParamsV5,
HistoricalVolatilityV5, HistoricalVolatilityV5,
InstrumentInfoV5,
InsuranceResponseV5, InsuranceResponseV5,
OpenInterestResponseV5, OpenInterestResponseV5,
OrderbookResponseV5, OrderbookResponseV5,
@@ -47,8 +46,8 @@ import {
AccountOrderV5, AccountOrderV5,
OptionDeliveryPriceV5, OptionDeliveryPriceV5,
CategorySymbolListV5, CategorySymbolListV5,
OHLCV5, OHLCKlineV5,
KlineV5, OHLCVKlineV5,
TickerSpotV5, TickerSpotV5,
TickerOptionV5, TickerOptionV5,
TickerLinearInverseV5, TickerLinearInverseV5,
@@ -123,6 +122,7 @@ import {
RedeemSpotLeveragedTokenResultV5, RedeemSpotLeveragedTokenResultV5,
GetSpotLeveragedTokenOrderHistoryParamsV5, GetSpotLeveragedTokenOrderHistoryParamsV5,
SpotLeveragedTokenOrderHistoryV5, SpotLeveragedTokenOrderHistoryV5,
InstrumentInfoResponseV5,
} from './types'; } from './types';
import { REST_CLIENT_TYPE_ENUM } from './util'; import { REST_CLIENT_TYPE_ENUM } from './util';
import BaseRestClient from './util/BaseRestClient'; import BaseRestClient from './util/BaseRestClient';
@@ -163,7 +163,7 @@ export class RestClientV5 extends BaseRestClient {
params: GetKlineParamsV5 params: GetKlineParamsV5
): Promise< ): Promise<
APIResponseV3WithTime< APIResponseV3WithTime<
CategorySymbolListV5<KlineV5[], 'spot' | 'linear' | 'inverse'> CategorySymbolListV5<OHLCVKlineV5[], 'spot' | 'linear' | 'inverse'>
> >
> { > {
return this.get(`/v5/market/kline`, params); return this.get(`/v5/market/kline`, params);
@@ -177,7 +177,9 @@ export class RestClientV5 extends BaseRestClient {
getMarkPriceKline( getMarkPriceKline(
params: GetMarkPriceKlineParamsV5 params: GetMarkPriceKlineParamsV5
): Promise< ): Promise<
APIResponseV3WithTime<CategorySymbolListV5<OHLCV5[], 'linear' | 'inverse'>> APIResponseV3WithTime<
CategorySymbolListV5<OHLCKlineV5[], 'linear' | 'inverse'>
>
> { > {
return this.get(`/v5/market/mark-price-kline`, params); return this.get(`/v5/market/mark-price-kline`, params);
} }
@@ -190,7 +192,9 @@ export class RestClientV5 extends BaseRestClient {
getIndexPriceKline( getIndexPriceKline(
params: GetIndexPriceKlineParamsV5 params: GetIndexPriceKlineParamsV5
): Promise< ): Promise<
APIResponseV3WithTime<CategorySymbolListV5<OHLCV5[], 'linear' | 'inverse'>> APIResponseV3WithTime<
CategorySymbolListV5<OHLCKlineV5[], 'linear' | 'inverse'>
>
> { > {
return this.get(`/v5/market/index-price-kline`, params); return this.get(`/v5/market/index-price-kline`, params);
} }
@@ -202,7 +206,9 @@ export class RestClientV5 extends BaseRestClient {
*/ */
getPremiumIndexPriceKline( getPremiumIndexPriceKline(
params: GetPremiumIndexPriceKlineParams params: GetPremiumIndexPriceKlineParams
): Promise<APIResponseV3WithTime<CategorySymbolListV5<OHLCV5[], 'linear'>>> { ): Promise<
APIResponseV3WithTime<CategorySymbolListV5<OHLCKlineV5[], 'linear'>>
> {
return this.get(`/v5/market/premium-index-price-kline`, params); return this.get(`/v5/market/premium-index-price-kline`, params);
} }
@@ -215,7 +221,7 @@ export class RestClientV5 extends BaseRestClient {
*/ */
getInstrumentsInfo( getInstrumentsInfo(
params: GetInstrumentsInfoParamsV5 params: GetInstrumentsInfoParamsV5
): Promise<APIResponseV3WithTime<CursorListV5<InstrumentInfoV5[]>>> { ): Promise<APIResponseV3WithTime<InstrumentInfoResponseV5>> {
return this.get(`/v5/market/instruments-info`, params); return this.get(`/v5/market/instruments-info`, params);
} }

View File

@@ -1,5 +1,5 @@
import { KlineIntervalV3 } from '../shared'; import { KlineIntervalV3 } from '../shared';
import { CategoryV5 } from '../v5-shared'; import { CategoryV5, OptionTypeV5 } from '../v5-shared';
export interface GetKlineParamsV5 { export interface GetKlineParamsV5 {
category: 'spot' | 'linear' | 'inverse'; category: 'spot' | 'linear' | 'inverse';
@@ -66,13 +66,11 @@ export interface GetFundingRateHistoryParamsV5 {
limit?: number; limit?: number;
} }
export type OptionType = 'Call' | 'Put';
export interface GetPublicTradingHistoryParamsV5 { export interface GetPublicTradingHistoryParamsV5 {
category: CategoryV5; category: CategoryV5;
symbol: string; symbol: string;
baseCoin?: string; baseCoin?: string;
optionType?: OptionType; optionType?: OptionTypeV5;
limit?: number; limit?: number;
} }

View File

@@ -1,4 +1,4 @@
import { CategoryV5, TPSLModeV5 } from '../v5-shared'; import { CategoryV5, ExecTypeV5, PositionIdx, TPSLModeV5 } from '../v5-shared';
export interface PositionInfoParamsV5 { export interface PositionInfoParamsV5 {
category: CategoryV5; category: CategoryV5;
@@ -41,7 +41,7 @@ export interface SetRiskLimitParamsV5 {
category: 'linear' | 'inverse'; category: 'linear' | 'inverse';
symbol: string; symbol: string;
riskId: number; riskId: number;
positionIdx?: number; positionIdx?: PositionIdx;
} }
export interface SetTradingStopParamsV5 { export interface SetTradingStopParamsV5 {
@@ -55,14 +55,14 @@ export interface SetTradingStopParamsV5 {
activePrice?: string; activePrice?: string;
tpSize?: string; tpSize?: string;
slSize?: string; slSize?: string;
positionIdx: number; positionIdx: PositionIdx;
} }
export interface SetAutoAddMarginParamsV5 { export interface SetAutoAddMarginParamsV5 {
category: 'linear'; category: 'linear';
symbol: string; symbol: string;
autoAddMargin: 0 | 1; autoAddMargin: 0 | 1;
positionIdx?: number; positionIdx?: PositionIdx;
} }
export interface GetExecutionListParamsV5 { export interface GetExecutionListParamsV5 {
@@ -73,7 +73,7 @@ export interface GetExecutionListParamsV5 {
baseCoin?: string; baseCoin?: string;
startTime?: number; startTime?: number;
endTime?: number; endTime?: number;
execType?: string; execType?: ExecTypeV5;
limit?: number; limit?: number;
cursor?: string; cursor?: string;
} }

View File

@@ -1,4 +1,10 @@
import { AccountTypeV5, CategoryV5, TransactionTypeV5 } from '../v5-shared'; import {
AccountMarginModeV5,
AccountTypeV5,
CategoryV5,
TransactionTypeV5,
UnifiedUpdateStatusV5,
} from '../v5-shared';
export interface WalletBalanceV5Coin { export interface WalletBalanceV5Coin {
coin: string; coin: string;
@@ -30,8 +36,6 @@ export interface WalletBalanceV5 {
coin: WalletBalanceV5Coin[]; coin: WalletBalanceV5Coin[];
} }
export type UnifiedUpdateStatusV5 = 'FAIL' | 'PROCESS' | 'SUCCESS';
export interface UnifiedAccountUpgradeResultV5 { export interface UnifiedAccountUpgradeResultV5 {
unifiedUpdateStatus: UnifiedUpdateStatusV5; unifiedUpdateStatus: UnifiedUpdateStatusV5;
unifiedUpdateMsg: { unifiedUpdateMsg: {
@@ -76,7 +80,7 @@ export interface FeeRateV5 {
export interface AccountInfoV5 { export interface AccountInfoV5 {
unifiedMarginStatus: number; unifiedMarginStatus: number;
marginMode: 'REGULAR_MARGIN' | 'PORTFOLIO_MARGIN'; marginMode: AccountMarginModeV5;
updatedTime: string; updatedTime: string;
} }

View File

@@ -1,4 +1,4 @@
import { AccountTypeV5, OrderSideV5 } from '../v5-shared'; import { AccountTypeV5, OrderSideV5, WithdrawalTypeV5 } from '../v5-shared';
export interface CoinExchangeRecordV5 { export interface CoinExchangeRecordV5 {
fromCoin: string; fromCoin: string;
@@ -135,7 +135,7 @@ export interface CoinInfoV5 {
export interface WithdrawalRecordV5 { export interface WithdrawalRecordV5 {
withdrawId: string; withdrawId: string;
txID: string; txID: string;
withdrawType: string; withdrawType: WithdrawalTypeV5;
coin: string; coin: string;
chain: string; chain: string;
amount: string; amount: string;

View File

@@ -1,104 +1,121 @@
import {
CategoryCursorListV5,
ContractTypeV5,
InstrumentStatusV5,
OptionTypeV5,
OrderSideV5,
} from '../v5-shared';
/** /**
* OHLCVT candle used by v5 APIs * OHLCVT candle used by v5 APIs
* *
* > list[0]: startTime string Start time of the candle (ms) * - list[0]: startTime string Start time of the candle (ms)
* * - list[1]: openPrice string Open price
* > list[1]: openPrice string Open price * - list[2]: highPrice string Highest price
* * - list[3]: lowPrice string Lowest price
* > list[2]: highPrice string Highest 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[3]: lowPrice string Lowest price * - list[6]: turnover string Turnover. Unit of figure: quantity of quota coin
*
* > 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 * OHLC candle used by v5 APIs
* *
* > list[0]: startTime string Start time of the candle (ms) * - list[0]: startTime string Start time of the candle (ms)
* * - list[1]: openPrice string Open price
* > list[1]: openPrice string Open price * - list[2]: highPrice string Highest price
* * - list[3]: lowPrice string Lowest price
* > list[2]: highPrice string Highest price * - list[4]: closePrice string Close price. Is the last traded price when the candle is not closed
*
* > 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 { export interface LinearInverseInstrumentInfoV5 {
category: 'linear' | 'inverse';
symbol: string; symbol: string;
contractType: string; contractType: ContractTypeV5;
status: string; status: InstrumentStatusV5;
baseCoin: string; baseCoin: string;
quoteCoin: string; quoteCoin: string;
launchTime: string; launchTime: string;
deliveryTime: string; deliveryTime?: string;
deliveryFeeRate: string; deliveryFeeRate?: string;
priceScale: string; priceScale: string;
leverageFilter: {
minLeverage: string;
maxLeverage: string; maxLeverage: string;
minOrderValue: string; leverageStep: string;
minOrderVolume: string; };
makerFeeRate: string; priceFilter: {
takerFeeRate: string; minPrice: string;
maxPrice: string;
tickSize: string;
};
lotSizeFilter: {
maxOrderQty: string;
minOrderQty: string;
qtyStep: string;
postOnlyMaxOrderQty?: string;
};
unifiedMarginTrade: boolean;
fundingInterval: number;
settleCoin: string;
} }
export interface OptionInstrumentInfoV5 { export interface OptionInstrumentInfoV5 {
category: 'option';
symbol: string; symbol: string;
contractType: string; optionsType: OptionTypeV5;
status: string; status: InstrumentStatusV5;
baseCoin: string; baseCoin: string;
quoteCoin: string; quoteCoin: string;
settleCoin: boolean;
launchTime: string; launchTime: string;
deliveryTime: string; deliveryTime: string;
deliveryFeeRate: string; deliveryFeeRate: string;
priceScale: string; priceFilter: {
maxLeverage: string; minPrice: string;
minOrderValue: string; maxPrice: string;
minOrderVolume: string; tickSize: string;
makerFeeRate: string; };
takerFeeRate: string; lotSizeFilter: {
settlementCurrency: string; maxOrderQty: string;
settlementPrice: string; minOrderQty: string;
deliveryMethod: string; qtyStep: string;
optionType: string; };
exercisePrice: string;
expirationTime: string;
blockMarginRatio: string;
marginType: string;
strike: string;
} }
export interface SpotInstrumentInfoV5 { export interface SpotInstrumentInfoV5 {
category: 'spot';
symbol: string; symbol: string;
contractType: string;
status: string;
baseCoin: string; baseCoin: string;
quoteCoin: string; quoteCoin: string;
launchTime: string; innovation: '0' | '1';
priceScale: string; status: InstrumentStatusV5;
maxLeverage: string; lotSizeFilter: {
minOrderValue: string; basePrecision: string;
minOrderVolume: string; quotePrecision: string;
makerFeeRate: string; minOrderQty: string;
takerFeeRate: string; maxOrderQty: string;
minOrderAmt: string;
maxOrderAmt: string;
};
priceFilter: {
tickSize: string;
};
} }
export type InstrumentInfoV5 = export type InstrumentInfoResponseV5 =
| LinearInverseInstrumentInfoV5 | CategoryCursorListV5<LinearInverseInstrumentInfoV5[], 'linear' | 'inverse'>
| OptionInstrumentInfoV5 | CategoryCursorListV5<OptionInstrumentInfoV5[], 'option'>
| SpotInstrumentInfoV5; | CategoryCursorListV5<SpotInstrumentInfoV5[], 'spot'>;
export interface OrderbookLevelV5 { export default interface OrderbookLevelV5 {
price: string; price: string;
size: string; size: string;
} }
@@ -192,15 +209,15 @@ export interface PublicTradeV5 {
symbol: string; symbol: string;
price: string; price: string;
size: string; size: string;
side: 'Buy' | 'Sell'; side: OrderSideV5;
time: string; time: string;
isBlockTrade: boolean; isBlockTrade: boolean;
} }
/** /**
> openInterest string Open interest *
* - openInterest string Open interest
> timestamp string The timestamp (ms) * - timestamp string The timestamp (ms)
*/ */
export type OpenInterestV5 = [string, string]; export type OpenInterestV5 = [string, string];

View File

@@ -1,8 +1,10 @@
import { import {
CategoryV5, CategoryV5,
ExecTypeV5,
OrderSideV5, OrderSideV5,
OrderTypeV5, OrderTypeV5,
PositionIdx, PositionIdx,
StopOrderTypeV5,
TPSLModeV5, TPSLModeV5,
TradeModeV5, TradeModeV5,
} from '../v5-shared'; } from '../v5-shared';
@@ -50,12 +52,12 @@ export interface ExecutionV5 {
orderQty: string; orderQty: string;
leavesQty: string; leavesQty: string;
orderType: OrderTypeV5; orderType: OrderTypeV5;
stopOrderType?: string; stopOrderType?: StopOrderTypeV5;
execFee: string; execFee: string;
execId: string; execId: string;
execPrice: string; execPrice: string;
execQty: string; execQty: string;
execType: string; execType: ExecTypeV5;
execValue: string; execValue: string;
execTime: string; execTime: string;
isMaker: boolean; isMaker: boolean;
@@ -74,8 +76,8 @@ export interface ClosedPnLV5 {
side: string; side: string;
qty: string; qty: string;
orderPrice: string; orderPrice: string;
orderType: string; orderType: OrderTypeV5;
execType: string; execType: ExecTypeV5;
closedSize: string; closedSize: string;
cumEntryValue: string; cumEntryValue: string;
avgEntryPrice: string; avgEntryPrice: string;

View File

@@ -1,10 +1,14 @@
import { import {
CategoryV5, CategoryV5,
OrderCancelTypeV5,
OrderRejectReasonV5,
OrderSideV5, OrderSideV5,
OrderStatusV5,
OrderTimeInForceV5, OrderTimeInForceV5,
OrderTriggerByV5, OrderTriggerByV5,
OrderTypeV5, OrderTypeV5,
PositionIdx, PositionIdx,
StopOrderTypeV5,
} from '../v5-shared'; } from '../v5-shared';
export interface OrderResultV5 { export interface OrderResultV5 {
@@ -22,9 +26,9 @@ export interface AccountOrderV5 {
side: OrderSideV5; side: OrderSideV5;
isLeverage?: string; isLeverage?: string;
positionIdx?: PositionIdx; positionIdx?: PositionIdx;
orderStatus: string; orderStatus: OrderStatusV5;
cancelType?: string; cancelType?: OrderCancelTypeV5;
rejectReason?: string; rejectReason?: OrderRejectReasonV5;
avgPrice: string; avgPrice: string;
leavesQty: string; leavesQty: string;
leavesValue: string; leavesValue: string;
@@ -33,7 +37,7 @@ export interface AccountOrderV5 {
cumExecFee: string; cumExecFee: string;
timeInForce?: OrderTimeInForceV5; timeInForce?: OrderTimeInForceV5;
orderType?: OrderTypeV5; orderType?: OrderTypeV5;
stopOrderType?: string; stopOrderType?: StopOrderTypeV5;
orderIv?: string; orderIv?: string;
triggerPrice?: string; triggerPrice?: string;
takeProfit?: string; takeProfit?: string;

View File

@@ -1,17 +1,95 @@
export type CategoryV5 = 'spot' | 'linear' | 'inverse' | 'option'; 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 OrderFilterV5 = 'Order' | 'tpslOrder';
export type OrderSideV5 = 'Buy' | 'Sell'; export type OrderSideV5 = 'Buy' | 'Sell';
export type OrderTypeV5 = 'Market' | 'Limit'; export type OrderTypeV5 = 'Market' | 'Limit';
export type OrderTimeInForceV5 = 'GTC' | 'IOC' | 'FOK' | 'PostOnly'; export type OrderTimeInForceV5 = 'GTC' | 'IOC' | 'FOK' | 'PostOnly';
export type OrderTriggerByV5 = 'LastPrice' | 'IndexPrice' | 'MarkPrice'; 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.
*
* - 0one-way mode position
* - 1Buy side of hedge-mode position
* - 2Sell 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 TradeModeV5 = 0 | 1;
export type TPSLModeV5 = 'Full' | 'Partial'; export type TPSLModeV5 = 'Full' | 'Partial';
export type AccountMarginModeV5 = 'REGULAR_MARGIN' | 'PORTFOLIO_MARGIN'; export type AccountMarginModeV5 = 'REGULAR_MARGIN' | 'PORTFOLIO_MARGIN';
export type UnifiedUpdateStatusV5 = 'FAIL' | 'PROCESS' | 'SUCCESS';
export type AccountTypeV5 = export type AccountTypeV5 =
| 'CONTRACT' | 'CONTRACT'
@@ -68,6 +146,18 @@ export type LTOrderTypeV5 = '1' | '2';
*/ */
export type LTOrderStatusV5 = '1' | '2' | '3'; 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 { export interface PermissionsV5 {
ContractTrade?: string[]; ContractTrade?: string[];
Spot?: string[]; Spot?: string[];
@@ -78,8 +168,11 @@ export interface PermissionsV5 {
NFT?: string[]; NFT?: string[];
} }
export interface CategoryCursorListV5<T extends unknown[]> { export interface CategoryCursorListV5<
category: CategoryV5; T extends unknown[],
TCategory extends CategoryV5 = CategoryV5
> {
category: TCategory;
list: T; list: T;
nextPageCursor?: string; nextPageCursor?: string;
} }