v2.1.10: feat(#144): add missing endpoint for linear position mode. Type improvements & linting.
This commit is contained in:
4
.prettierrc
Normal file
4
.prettierrc
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"tabWidth": 2,
|
||||||
|
"singleQuote": true
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "bybit-api",
|
"name": "bybit-api",
|
||||||
"version": "2.1.9",
|
"version": "2.1.10",
|
||||||
"description": "Node.js connector for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.",
|
"description": "Node.js connector for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
|
|||||||
11
src/constants/enum.ts
Normal file
11
src/constants/enum.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
export const linearPositionModeEnum = {
|
||||||
|
OneWayMode: 'MergedSingle',
|
||||||
|
HedgeMode: 'BothSide',
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export const positionTpSlModeEnum = {
|
||||||
|
/** Full take profit/stop loss mode (a single TP order and a single SL order can be placed, covering the entire position) */
|
||||||
|
Full: 'Full',
|
||||||
|
/** Partial take profit/stop loss mode (multiple TP and SL orders can be placed, covering portions of the position) */
|
||||||
|
Partial: 'Partial',
|
||||||
|
} as const;
|
||||||
18
src/index.ts
18
src/index.ts
@@ -1,8 +1,10 @@
|
|||||||
export * from './inverse-client';
|
export * from "./inverse-client";
|
||||||
export * from './inverse-futures-client';
|
export * from "./inverse-futures-client";
|
||||||
export * from './linear-client';
|
export * from "./linear-client";
|
||||||
export * from './spot-client';
|
export * from "./spot-client";
|
||||||
export * from './websocket-client';
|
export * from "./websocket-client";
|
||||||
export * from './logger';
|
export * from "./logger";
|
||||||
export * from './types/shared';
|
export * from "./types/shared";
|
||||||
export * from './types/spot';
|
export * from "./types/spot";
|
||||||
|
export * from "./util/WsStore";
|
||||||
|
export * from "./constants/enum";
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
import { AxiosRequestConfig } from 'axios';
|
import { AxiosRequestConfig } from 'axios';
|
||||||
import { GenericAPIResponse, getRestBaseUrl, RestClientOptions } from './util/requestUtils';
|
import {
|
||||||
|
GenericAPIResponse,
|
||||||
|
getRestBaseUrl,
|
||||||
|
RestClientOptions,
|
||||||
|
} from './util/requestUtils';
|
||||||
import RequestWrapper from './util/requestWrapper';
|
import RequestWrapper from './util/requestWrapper';
|
||||||
import SharedEndpoints from './shared-endpoints';
|
import SharedEndpoints from './shared-endpoints';
|
||||||
import { SymbolIntervalFromLimitParam, SymbolLimitParam, SymbolParam } from '.';
|
import {
|
||||||
|
SymbolIntervalFromLimitParam,
|
||||||
|
SymbolLimitParam,
|
||||||
|
SymbolParam,
|
||||||
|
} from './types/shared';
|
||||||
|
import { linearPositionModeEnum, positionTpSlModeEnum } from './constants/enum';
|
||||||
|
|
||||||
export class LinearClient extends SharedEndpoints {
|
export class LinearClient extends SharedEndpoints {
|
||||||
protected requestWrapper: RequestWrapper;
|
protected requestWrapper: RequestWrapper;
|
||||||
@@ -46,11 +55,17 @@ export class LinearClient extends SharedEndpoints {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getTrades(params: SymbolLimitParam): GenericAPIResponse {
|
getTrades(params: SymbolLimitParam): GenericAPIResponse {
|
||||||
return this.requestWrapper.get('public/linear/recent-trading-records', params);
|
return this.requestWrapper.get(
|
||||||
|
'public/linear/recent-trading-records',
|
||||||
|
params
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getLastFundingRate(params: SymbolParam): GenericAPIResponse {
|
getLastFundingRate(params: SymbolParam): GenericAPIResponse {
|
||||||
return this.requestWrapper.get('public/linear/funding/prev-funding-rate', params);
|
return this.requestWrapper.get(
|
||||||
|
'public/linear/funding/prev-funding-rate',
|
||||||
|
params
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getMarkPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
|
getMarkPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
|
||||||
@@ -61,7 +76,9 @@ export class LinearClient extends SharedEndpoints {
|
|||||||
return this.requestWrapper.get('public/linear/index-price-kline', params);
|
return this.requestWrapper.get('public/linear/index-price-kline', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
getPremiumIndexKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
|
getPremiumIndexKline(
|
||||||
|
params: SymbolIntervalFromLimitParam
|
||||||
|
): GenericAPIResponse {
|
||||||
return this.requestWrapper.get('public/linear/premium-index-kline', params);
|
return this.requestWrapper.get('public/linear/premium-index-kline', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +199,10 @@ export class LinearClient extends SharedEndpoints {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cancelAllConditionalOrders(params: SymbolParam): GenericAPIResponse {
|
cancelAllConditionalOrders(params: SymbolParam): GenericAPIResponse {
|
||||||
return this.requestWrapper.post('private/linear/stop-order/cancel-all', params);
|
return this.requestWrapper.post(
|
||||||
|
'private/linear/stop-order/cancel-all',
|
||||||
|
params
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
replaceConditionalOrder(params: {
|
replaceConditionalOrder(params: {
|
||||||
@@ -197,7 +217,10 @@ export class LinearClient extends SharedEndpoints {
|
|||||||
tp_trigger_by?: string;
|
tp_trigger_by?: string;
|
||||||
sl_trigger_by?: string;
|
sl_trigger_by?: string;
|
||||||
}): GenericAPIResponse {
|
}): GenericAPIResponse {
|
||||||
return this.requestWrapper.post('private/linear/stop-order/replace', params);
|
return this.requestWrapper.post(
|
||||||
|
'private/linear/stop-order/replace',
|
||||||
|
params
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
queryConditionalOrder(params: {
|
queryConditionalOrder(params: {
|
||||||
@@ -221,7 +244,10 @@ export class LinearClient extends SharedEndpoints {
|
|||||||
side: string;
|
side: string;
|
||||||
auto_add_margin: boolean;
|
auto_add_margin: boolean;
|
||||||
}): GenericAPIResponse {
|
}): GenericAPIResponse {
|
||||||
return this.requestWrapper.post('private/linear/position/set-auto-add-margin', params);
|
return this.requestWrapper.post(
|
||||||
|
'private/linear/position/set-auto-add-margin',
|
||||||
|
params
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
setMarginSwitch(params?: {
|
setMarginSwitch(params?: {
|
||||||
@@ -230,12 +256,40 @@ export class LinearClient extends SharedEndpoints {
|
|||||||
buy_leverage: number;
|
buy_leverage: number;
|
||||||
sell_leverage: number;
|
sell_leverage: number;
|
||||||
}): GenericAPIResponse {
|
}): GenericAPIResponse {
|
||||||
return this.requestWrapper.post('private/linear/position/switch-isolated', params);
|
return this.requestWrapper.post(
|
||||||
|
'private/linear/position/switch-isolated',
|
||||||
|
params
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch between one-way vs hedge mode. Use `linearPositionModeEnum` for the mode parameter.
|
||||||
|
*/
|
||||||
|
setPositionMode(params: {
|
||||||
|
symbol: string;
|
||||||
|
mode: typeof linearPositionModeEnum[keyof typeof linearPositionModeEnum];
|
||||||
|
}): GenericAPIResponse {
|
||||||
|
return this.requestWrapper.post(
|
||||||
|
'private/linear/position/switch-mode',
|
||||||
|
params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @deprecated use setPositionTpSlMode() instead */
|
||||||
setSwitchMode(params?: {
|
setSwitchMode(params?: {
|
||||||
symbol: string;
|
symbol: string;
|
||||||
tp_sl_mode: string;
|
tp_sl_mode: typeof positionTpSlModeEnum[keyof typeof positionTpSlModeEnum];
|
||||||
|
}): GenericAPIResponse {
|
||||||
|
return this.requestWrapper.post('private/linear/tpsl/switch-mode', params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch TP/SL mode between full or partial. When set to Partial, TP/SL orders may have a quantity less than the position size.
|
||||||
|
* This is set with the setTradingStop() method. Use `positionTpSlModeEnum` for the tp_sl_mode parameter.
|
||||||
|
*/
|
||||||
|
setPositionTpSlMode(params: {
|
||||||
|
symbol: string;
|
||||||
|
tp_sl_mode: typeof positionTpSlModeEnum[keyof typeof positionTpSlModeEnum];
|
||||||
}): GenericAPIResponse {
|
}): GenericAPIResponse {
|
||||||
return this.requestWrapper.post('private/linear/tpsl/switch-mode', params);
|
return this.requestWrapper.post('private/linear/tpsl/switch-mode', params);
|
||||||
}
|
}
|
||||||
@@ -245,7 +299,10 @@ export class LinearClient extends SharedEndpoints {
|
|||||||
side: string;
|
side: string;
|
||||||
margin: number;
|
margin: number;
|
||||||
}): GenericAPIResponse {
|
}): GenericAPIResponse {
|
||||||
return this.requestWrapper.post('private/linear/position/add-margin', params);
|
return this.requestWrapper.post(
|
||||||
|
'private/linear/position/add-margin',
|
||||||
|
params
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
setUserLeverage(params: {
|
setUserLeverage(params: {
|
||||||
@@ -253,7 +310,10 @@ export class LinearClient extends SharedEndpoints {
|
|||||||
buy_leverage: number;
|
buy_leverage: number;
|
||||||
sell_leverage: number;
|
sell_leverage: number;
|
||||||
}): GenericAPIResponse {
|
}): GenericAPIResponse {
|
||||||
return this.requestWrapper.post('private/linear/position/set-leverage', params);
|
return this.requestWrapper.post(
|
||||||
|
'private/linear/position/set-leverage',
|
||||||
|
params
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTradingStop(params: {
|
setTradingStop(params: {
|
||||||
@@ -267,7 +327,10 @@ export class LinearClient extends SharedEndpoints {
|
|||||||
sl_size?: number;
|
sl_size?: number;
|
||||||
tp_size?: number;
|
tp_size?: number;
|
||||||
}): GenericAPIResponse {
|
}): GenericAPIResponse {
|
||||||
return this.requestWrapper.post('private/linear/position/trading-stop', params);
|
return this.requestWrapper.post(
|
||||||
|
'private/linear/position/trading-stop',
|
||||||
|
params
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTradeRecords(params: {
|
getTradeRecords(params: {
|
||||||
@@ -278,7 +341,10 @@ export class LinearClient extends SharedEndpoints {
|
|||||||
page?: number;
|
page?: number;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
}): GenericAPIResponse {
|
}): GenericAPIResponse {
|
||||||
return this.requestWrapper.get('private/linear/trade/execution/list', params);
|
return this.requestWrapper.get(
|
||||||
|
'private/linear/trade/execution/list',
|
||||||
|
params
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getClosedPnl(params: {
|
getClosedPnl(params: {
|
||||||
@@ -289,7 +355,10 @@ export class LinearClient extends SharedEndpoints {
|
|||||||
page?: number;
|
page?: number;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
}): GenericAPIResponse {
|
}): GenericAPIResponse {
|
||||||
return this.requestWrapper.get('private/linear/trade/closed-pnl/list', params);
|
return this.requestWrapper.get(
|
||||||
|
'private/linear/trade/closed-pnl/list',
|
||||||
|
params
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -313,10 +382,16 @@ export class LinearClient extends SharedEndpoints {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
getPredictedFundingFee(params: SymbolParam): GenericAPIResponse {
|
getPredictedFundingFee(params: SymbolParam): GenericAPIResponse {
|
||||||
return this.requestWrapper.get('private/linear/funding/predicted-funding', params);
|
return this.requestWrapper.get(
|
||||||
|
'private/linear/funding/predicted-funding',
|
||||||
|
params
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getLastFundingFee(params: SymbolParam): GenericAPIResponse {
|
getLastFundingFee(params: SymbolParam): GenericAPIResponse {
|
||||||
return this.requestWrapper.get('private/linear/funding/prev-funding', params);
|
return this.requestWrapper.get(
|
||||||
|
'private/linear/funding/prev-funding',
|
||||||
|
params
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user