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

@@ -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;
}

View File

@@ -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;
}

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 {
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;
}

View File

@@ -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;

View File

@@ -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<LinearInverseInstrumentInfoV5[], 'linear' | 'inverse'>
| CategoryCursorListV5<OptionInstrumentInfoV5[], 'option'>
| CategoryCursorListV5<SpotInstrumentInfoV5[], 'spot'>;
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 {

View File

@@ -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;

View File

@@ -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;

View File

@@ -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.
*
* - 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 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<T extends unknown[]> {
category: CategoryV5;
export interface CategoryCursorListV5<
T extends unknown[],
TCategory extends CategoryV5 = CategoryV5
> {
category: TCategory;
list: T;
nextPageCursor?: string;
}