chore(): tidying, consolidate repetitive types
This commit is contained in:
@@ -18,23 +18,14 @@ import {
|
||||
GetRiskLimitParamsV5,
|
||||
GetTickersParamsV5,
|
||||
HistoricalVolatilityV5,
|
||||
IndexPriceKlineResponseV5,
|
||||
InstrumentInfoV5,
|
||||
InsuranceResponseV5,
|
||||
KlineResponseV5,
|
||||
MarkPriceKlineResponseV5,
|
||||
AccountOrdersResultV5,
|
||||
OpenInterestResponseV5,
|
||||
OptionDeliveryPriceResponseV5,
|
||||
OrderbookResponseV5,
|
||||
OrderParamsV5,
|
||||
PaginatedListV5,
|
||||
PremiumIndexPriceKlineResponse,
|
||||
CursorListV5,
|
||||
PublicTradeV5,
|
||||
RiskLimitV5,
|
||||
TickersLinearInverseResponseV5,
|
||||
TickersOptionResponseV5,
|
||||
TickersSpotResponseV5,
|
||||
AmendOrderParamsV5,
|
||||
CancelOrderParamsV5,
|
||||
GetAccountOrdersParams,
|
||||
@@ -50,12 +41,24 @@ import {
|
||||
OrderSideV5,
|
||||
SpotBorrowCheckResult,
|
||||
APIResponseV3,
|
||||
PositionInfoParamsV5,
|
||||
CategoryCursorListV5,
|
||||
PositionV5,
|
||||
AccountOrderV5,
|
||||
OptionDeliveryPriceV5,
|
||||
CategorySymbolListV5,
|
||||
OHLCV5,
|
||||
KlineV5,
|
||||
TickerSpotV5,
|
||||
TickerOptionV5,
|
||||
TickerLinearInverseV5,
|
||||
} from './types';
|
||||
import { REST_CLIENT_TYPE_ENUM } from './util';
|
||||
import BaseRestClient from './util/BaseRestClient';
|
||||
|
||||
/**
|
||||
* REST API client for V5 REST APIs
|
||||
*
|
||||
* https://bybit-exchange.github.io/docs/v5/intro
|
||||
*/
|
||||
export class RestClientV5 extends BaseRestClient {
|
||||
@@ -82,57 +85,72 @@ export class RestClientV5 extends BaseRestClient {
|
||||
|
||||
/**
|
||||
* Query the kline data. Charts are returned in groups based on the requested interval.
|
||||
*
|
||||
* Covers: Spot / Linear contract / Inverse contract
|
||||
*/
|
||||
getKline(
|
||||
params: GetKlineParamsV5
|
||||
): Promise<APIResponseV3WithTime<KlineResponseV5>> {
|
||||
): Promise<
|
||||
APIResponseV3WithTime<
|
||||
CategorySymbolListV5<KlineV5[], 'spot' | 'linear' | 'inverse'>
|
||||
>
|
||||
> {
|
||||
return this.get(`/v5/market/kline`, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the mark price kline data. Charts are returned in groups based on the requested interval.
|
||||
*
|
||||
* Covers: Linear contract / Inverse contract
|
||||
*/
|
||||
getMarkPriceKline(
|
||||
params: GetMarkPriceKlineParamsV5
|
||||
): Promise<APIResponseV3WithTime<MarkPriceKlineResponseV5>> {
|
||||
): Promise<
|
||||
APIResponseV3WithTime<CategorySymbolListV5<OHLCV5[], 'linear' | 'inverse'>>
|
||||
> {
|
||||
return this.get(`/v5/market/mark-price-kline`, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the index price kline data. Charts are returned in groups based on the requested interval.
|
||||
*
|
||||
* Covers: Linear contract / Inverse contract
|
||||
*/
|
||||
getIndexPriceKline(
|
||||
params: GetIndexPriceKlineParamsV5
|
||||
): Promise<APIResponseV3WithTime<IndexPriceKlineResponseV5>> {
|
||||
): Promise<
|
||||
APIResponseV3WithTime<CategorySymbolListV5<OHLCV5[], 'linear' | 'inverse'>>
|
||||
> {
|
||||
return this.get(`/v5/market/index-price-kline`, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the premium index price kline data. Charts are returned in groups based on the requested interval.
|
||||
*
|
||||
* Covers: Linear contract
|
||||
*/
|
||||
getPremiumIndexPriceKline(
|
||||
params: GetPremiumIndexPriceKlineParams
|
||||
): Promise<APIResponseV3WithTime<PremiumIndexPriceKlineResponse>> {
|
||||
): Promise<APIResponseV3WithTime<CategorySymbolListV5<OHLCV5[], 'linear'>>> {
|
||||
return this.get(`/v5/market/premium-index-price-kline`, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query a list of instruments of online trading pair.
|
||||
*
|
||||
* Covers: Spot / Linear contract / Inverse contract / Option
|
||||
*
|
||||
* Note: Spot does not support pagination, so limit & cursor are invalid.
|
||||
*/
|
||||
getInstrumentsInfo(
|
||||
params: GetInstrumentsInfoParamsV5
|
||||
): Promise<APIResponseV3WithTime<PaginatedListV5<InstrumentInfoV5>>> {
|
||||
): Promise<APIResponseV3WithTime<CursorListV5<InstrumentInfoV5[]>>> {
|
||||
return this.get(`/v5/market/instruments-info`, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query orderbook data
|
||||
*
|
||||
* Covers: Spot / Linear contract / Inverse contract / Option
|
||||
*/
|
||||
getOrderbook(
|
||||
@@ -143,15 +161,16 @@ export class RestClientV5 extends BaseRestClient {
|
||||
|
||||
/**
|
||||
* Query the latest price snapshot, best bid/ask price, and trading volume in the last 24 hours.
|
||||
*
|
||||
* Covers: Spot / Linear contract / Inverse contract / Option
|
||||
*/
|
||||
getTickers(
|
||||
params: GetTickersParamsV5
|
||||
): Promise<
|
||||
APIResponseV3WithTime<
|
||||
| TickersLinearInverseResponseV5
|
||||
| TickersOptionResponseV5
|
||||
| TickersSpotResponseV5
|
||||
| CategoryListV5<TickerLinearInverseV5[], 'linear' | 'inverse'>
|
||||
| CategoryListV5<TickerOptionV5[], 'option'>
|
||||
| CategoryListV5<TickerSpotV5[], 'spot'>
|
||||
>
|
||||
> {
|
||||
return this.get(`/v5/market/tickers`, params);
|
||||
@@ -159,13 +178,14 @@ export class RestClientV5 extends BaseRestClient {
|
||||
|
||||
/**
|
||||
* Query historical funding rate. Each symbol has a different funding interval.
|
||||
*
|
||||
* Covers: Linear contract / Inverse perpetual
|
||||
*/
|
||||
getFundingRateHistory(
|
||||
params: GetFundingRateHistoryParamsV5
|
||||
): Promise<
|
||||
APIResponseV3WithTime<
|
||||
CategoryListV5<FundingRateHistoryResponseV5, 'linear' | 'inverse'>
|
||||
CategoryListV5<FundingRateHistoryResponseV5[], 'linear' | 'inverse'>
|
||||
>
|
||||
> {
|
||||
return this.get(`/v5/market/funding/history`, params);
|
||||
@@ -173,16 +193,20 @@ export class RestClientV5 extends BaseRestClient {
|
||||
|
||||
/**
|
||||
* Query recent public trading data in Bybit.
|
||||
*
|
||||
* Covers: Spot / Linear contract / Inverse contract / Option
|
||||
*/
|
||||
getPublicTradingHistory(
|
||||
params: GetPublicTradingHistoryParamsV5
|
||||
): Promise<APIResponseV3WithTime<CategoryListV5<PublicTradeV5, CategoryV5>>> {
|
||||
): Promise<
|
||||
APIResponseV3WithTime<CategoryListV5<PublicTradeV5[], CategoryV5>>
|
||||
> {
|
||||
return this.get(`/v5/market/recent-trade`, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get open interest of each symbol.
|
||||
*
|
||||
* Covers: Linear contract / Inverse contract
|
||||
*/
|
||||
getOpenInterest(
|
||||
@@ -198,7 +222,7 @@ export class RestClientV5 extends BaseRestClient {
|
||||
getHistoricalVolatility(
|
||||
params: GetHistoricalVolatilityParamsV5
|
||||
): Promise<
|
||||
APIResponseV3WithTime<CategoryListV5<HistoricalVolatilityV5, 'option'>>
|
||||
APIResponseV3WithTime<CategoryListV5<HistoricalVolatilityV5[], 'option'>>
|
||||
> {
|
||||
return this.get(`/v5/market/historical-volatility`, params);
|
||||
}
|
||||
@@ -214,23 +238,27 @@ export class RestClientV5 extends BaseRestClient {
|
||||
|
||||
/**
|
||||
* Query risk limit of futures
|
||||
*
|
||||
* Covers: Linear contract / Inverse contract
|
||||
*/
|
||||
getRiskLimit(
|
||||
params?: GetRiskLimitParamsV5
|
||||
): Promise<
|
||||
APIResponseV3WithTime<CategoryListV5<RiskLimitV5, 'inverse' | 'linear'>>
|
||||
APIResponseV3WithTime<CategoryListV5<RiskLimitV5[], 'inverse' | 'linear'>>
|
||||
> {
|
||||
return this.get(`/v5/market/risk-limit`, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the delivery price for option
|
||||
*
|
||||
* Covers: Option
|
||||
*/
|
||||
getOptionDeliveryPrice(
|
||||
params: GetOptionDeliveryPriceParamsV5
|
||||
): Promise<APIResponseV3WithTime<OptionDeliveryPriceResponseV5>> {
|
||||
): Promise<
|
||||
APIResponseV3WithTime<CategoryCursorListV5<OptionDeliveryPriceV5[]>>
|
||||
> {
|
||||
return this.get(`/v5/market/delivery-price`, params);
|
||||
}
|
||||
|
||||
@@ -263,7 +291,7 @@ export class RestClientV5 extends BaseRestClient {
|
||||
*/
|
||||
getActiveOrders(
|
||||
params: GetAccountOrdersParams
|
||||
): Promise<APIResponseV3WithTime<AccountOrdersResultV5>> {
|
||||
): Promise<APIResponseV3WithTime<CategoryCursorListV5<AccountOrderV5[]>>> {
|
||||
return this.getPrivate('/v5/order/realtime', params);
|
||||
}
|
||||
|
||||
@@ -275,17 +303,20 @@ export class RestClientV5 extends BaseRestClient {
|
||||
|
||||
/**
|
||||
* Query order history. As order creation/cancellation is asynchronous, the data returned from this endpoint may delay.
|
||||
*
|
||||
* If you want to get real-time order information, you could query this endpoint or rely on the websocket stream (recommended).
|
||||
*/
|
||||
getHistoricOrders(
|
||||
params: GetAccountOrdersParams
|
||||
): Promise<APIResponseV3WithTime<AccountOrdersResultV5>> {
|
||||
): Promise<APIResponseV3WithTime<CategoryCursorListV5<AccountOrderV5[]>>> {
|
||||
return this.getPrivate(`/v5/order/history`, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* This endpoint allows you to place more than one order in a single request. Covers: option (unified account).
|
||||
*
|
||||
* Make sure you have sufficient funds in your account when placing an order. Once an order is placed, according to the funds required by the order, the funds in your account will be frozen by the corresponding amount during the life cycle of the order.
|
||||
*
|
||||
* A maximum of 20 orders can be placed per request. The returned data list is divided into two lists. The first list indicates whether or not the order creation was successful and the second list details the created order information. The structure of the two lists are completely consistent.
|
||||
*/
|
||||
batchSubmitOrders(
|
||||
@@ -300,7 +331,9 @@ export class RestClientV5 extends BaseRestClient {
|
||||
|
||||
/**
|
||||
* This endpoint allows you to amend more than one open order in a single request. Covers: option (unified account).
|
||||
*
|
||||
* You can modify unfilled or partially filled orders. Conditional orders are not supported.
|
||||
*
|
||||
* A maximum of 20 orders can be amended per request.
|
||||
*/
|
||||
batchAmendOrders(
|
||||
@@ -317,7 +350,9 @@ export class RestClientV5 extends BaseRestClient {
|
||||
|
||||
/**
|
||||
* This endpoint allows you to cancel more than one open order in a single request. Covers: option (unified account).
|
||||
*
|
||||
* You must specify orderId or orderLinkId. If orderId and orderLinkId is not matched, the system will process orderId first.
|
||||
*
|
||||
* You can cancel unfilled or partially filled orders. A maximum of 20 orders can be cancelled per request.
|
||||
*/
|
||||
batchCancelOrders(
|
||||
@@ -334,6 +369,7 @@ export class RestClientV5 extends BaseRestClient {
|
||||
|
||||
/**
|
||||
* Query the qty and amount of borrowable coins in spot account.
|
||||
*
|
||||
* Covers: Spot (Unified Account)
|
||||
*/
|
||||
getSpotBorrowCheck(
|
||||
@@ -349,6 +385,7 @@ export class RestClientV5 extends BaseRestClient {
|
||||
|
||||
/**
|
||||
* This endpoint allows you to set the disconnection protect time window. Covers: option (unified account).
|
||||
*
|
||||
* If you need to turn it on/off, you can contact your client manager for consultation and application. The default time window is 10 seconds.
|
||||
*/
|
||||
setDisconnectCancelAllWindow(
|
||||
@@ -361,6 +398,25 @@ export class RestClientV5 extends BaseRestClient {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Position APIs
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Query real-time position data, such as position size, cumulative realizedPNL.
|
||||
*
|
||||
* Unified account covers: Linear contract / Options
|
||||
*
|
||||
* Normal account covers: USDT perpetual / Inverse perpetual / Inverse futures
|
||||
*/
|
||||
getPositionInfo(
|
||||
params: PositionInfoParamsV5
|
||||
): Promise<APIResponseV3WithTime<CategoryCursorListV5<PositionV5[]>>> {
|
||||
return this.getPrivate('/v5/position/list', params);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user