Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bybit-api

Package Overview
Dependencies
Maintainers
1
Versions
126
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bybit-api - npm Package Compare versions

Comparing version 2.1.10 to 2.2.0-beta.1

30

lib/constants/enum.d.ts

@@ -11,1 +11,31 @@ export declare const linearPositionModeEnum: {

};
export declare const API_ERROR_CODE: {
readonly BALANCE_INSUFFICIENT_SPOT: -1131;
readonly ORDER_NOT_FOUND_OR_TOO_LATE_SPOT: -2013;
/** This could mean bad request, incorrect value types or even incorrect/missing values */
readonly PARAMS_MISSING_OR_WRONG: 10001;
readonly ORDER_NOT_FOUND_OR_TOO_LATE: 20001;
readonly POSITION_STATUS_NOT_NORMAL: 30013;
readonly CANNOT_SET_TRADING_STOP_FOR_ZERO_POS: 30024;
/** Seen when placing an order */
readonly INSUFFICIENT_BALANCE_FOR_ORDER_COST: 30031;
readonly POSITION_IDX_NOT_MATCH_POSITION_MODE: 30041;
/** Seen if a conditional order is too large */
readonly INSUFFICIENT_BALANCE: 30042;
/** E.g. trying to change position margin while on cross */
readonly POSITION_IS_CROSS_MARGIN: 30056;
readonly POSITION_MODE_NOT_MODIFIED: 30083;
readonly ISOLATED_NOT_MODIFIED: 30084;
readonly RISK_LIMIT_NOT_EXISTS: 30090;
readonly LEVERAGE_NOT_MODIFIED: 34036;
readonly SAME_SLTP_MODE: 37002;
readonly ORDER_NOT_FOUND_OR_TOO_LATE_LINEAR: 130010;
readonly ORDER_COST_NOT_AVAILABLE: 130021;
readonly CANNOT_SET_LINEAR_TRADING_STOP_FOR_ZERO_POS: 130024;
readonly ISOLATED_NOT_MODIFIED_LINEAR: 130056;
readonly POSITION_SIZE_IS_ZERO: 130057;
readonly AUTO_ADD_MARGIN_NOT_MODIFIED: 130060;
readonly INSUFFICIENT_BALANCE_FOR_ORDER_COST_LINEAR: 130080;
readonly SAME_SLTP_MODE_LINEAR: 130150;
readonly RISK_ID_NOT_MODIFIED: 134026;
};

32

lib/constants/enum.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.positionTpSlModeEnum = exports.linearPositionModeEnum = void 0;
exports.API_ERROR_CODE = exports.positionTpSlModeEnum = exports.linearPositionModeEnum = void 0;
exports.linearPositionModeEnum = {

@@ -14,2 +14,32 @@ OneWayMode: 'MergedSingle',

};
exports.API_ERROR_CODE = {
BALANCE_INSUFFICIENT_SPOT: -1131,
ORDER_NOT_FOUND_OR_TOO_LATE_SPOT: -2013,
/** This could mean bad request, incorrect value types or even incorrect/missing values */
PARAMS_MISSING_OR_WRONG: 10001,
ORDER_NOT_FOUND_OR_TOO_LATE: 20001,
POSITION_STATUS_NOT_NORMAL: 30013,
CANNOT_SET_TRADING_STOP_FOR_ZERO_POS: 30024,
/** Seen when placing an order */
INSUFFICIENT_BALANCE_FOR_ORDER_COST: 30031,
POSITION_IDX_NOT_MATCH_POSITION_MODE: 30041,
/** Seen if a conditional order is too large */
INSUFFICIENT_BALANCE: 30042,
/** E.g. trying to change position margin while on cross */
POSITION_IS_CROSS_MARGIN: 30056,
POSITION_MODE_NOT_MODIFIED: 30083,
ISOLATED_NOT_MODIFIED: 30084,
RISK_LIMIT_NOT_EXISTS: 30090,
LEVERAGE_NOT_MODIFIED: 34036,
SAME_SLTP_MODE: 37002,
ORDER_NOT_FOUND_OR_TOO_LATE_LINEAR: 130010,
ORDER_COST_NOT_AVAILABLE: 130021,
CANNOT_SET_LINEAR_TRADING_STOP_FOR_ZERO_POS: 130024,
ISOLATED_NOT_MODIFIED_LINEAR: 130056,
POSITION_SIZE_IS_ZERO: 130057,
AUTO_ADD_MARGIN_NOT_MODIFIED: 130060,
INSUFFICIENT_BALANCE_FOR_ORDER_COST_LINEAR: 130080,
SAME_SLTP_MODE_LINEAR: 130150,
RISK_ID_NOT_MODIFIED: 134026,
};
//# sourceMappingURL=enum.js.map

20

lib/index.d.ts

@@ -1,10 +0,10 @@

export * from "./inverse-client";
export * from "./inverse-futures-client";
export * from "./linear-client";
export * from "./spot-client";
export * from "./websocket-client";
export * from "./logger";
export * from "./types/shared";
export * from "./types/spot";
export * from "./util/WsStore";
export * from "./constants/enum";
export * from './inverse-client';
export * from './inverse-futures-client';
export * from './linear-client';
export * from './spot-client';
export * from './websocket-client';
export * from './logger';
export * from './types/shared';
export * from './types/spot';
export * from './util/WsStore';
export * from './constants/enum';
import { AxiosRequestConfig } from 'axios';
import { GenericAPIResponse, RestClientOptions } from './util/requestUtils';
import RequestWrapper from './util/requestWrapper';
import SharedEndpoints from './shared-endpoints';
import { SymbolFromLimitParam, SymbolIntervalFromLimitParam, SymbolParam } from './types/shared';
export declare class InverseClient extends SharedEndpoints {
protected requestWrapper: RequestWrapper;
import { RestClientOptions } from './util/requestUtils';
import { APIResponseWithTime, AssetExchangeRecordsReq, CoinParam, SymbolInfo, SymbolIntervalFromLimitParam, SymbolLimitParam, SymbolParam, SymbolPeriodLimitParam, WalletFundRecordsReq, WithdrawRecordsReq } from './types/shared';
import BaseRestClient from './util/BaseRestClient';
export declare class InverseClient extends BaseRestClient {
/**

@@ -18,2 +16,3 @@ * @public Creates an instance of the inverse REST API client.

constructor(key?: string | undefined, secret?: string | undefined, useLivenet?: boolean, restClientOptions?: RestClientOptions, requestOptions?: AxiosRequestConfig);
fetchServerTime(): Promise<number>;
/**

@@ -24,15 +23,21 @@ *

*/
getKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse;
getOrderBook(params: SymbolParam): Promise<APIResponseWithTime<any[]>>;
getKline(params: SymbolIntervalFromLimitParam): Promise<APIResponseWithTime<any[]>>;
/**
* @deprecated use getTickers() instead
* Get latest information for symbol
*/
getLatestInformation(params?: Partial<SymbolParam>): GenericAPIResponse;
getTickers(params?: Partial<SymbolParam>): Promise<APIResponseWithTime<any[]>>;
getTrades(params: SymbolLimitParam): Promise<APIResponseWithTime<any[]>>;
getSymbols(): Promise<APIResponseWithTime<SymbolInfo[]>>;
getMarkPriceKline(params: SymbolIntervalFromLimitParam): Promise<APIResponseWithTime<any[]>>;
getIndexPriceKline(params: SymbolIntervalFromLimitParam): Promise<APIResponseWithTime<any[]>>;
getPremiumIndexKline(params: SymbolIntervalFromLimitParam): Promise<APIResponseWithTime<any[]>>;
/**
* @deprecated use getTrades() instead
*
* Market Data : Advanced
*
*/
getPublicTradingRecords(params: SymbolFromLimitParam): GenericAPIResponse;
getTrades(params: SymbolFromLimitParam): GenericAPIResponse;
getMarkPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse;
getIndexPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse;
getPremiumIndexKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse;
getOpenInterest(params: SymbolPeriodLimitParam): Promise<APIResponseWithTime<any[]>>;
getLatestBigDeal(params: SymbolLimitParam): Promise<APIResponseWithTime<any[]>>;
getLongShortRatio(params: SymbolPeriodLimitParam): Promise<APIResponseWithTime<any[]>>;
/**

@@ -43,3 +48,25 @@ *

*/
getApiKeyInfo(): Promise<APIResponseWithTime<any>>;
/**
*
* Wallet Data Endpoints
*
*/
getWalletBalance(params?: Partial<CoinParam>): Promise<APIResponseWithTime<any>>;
getWalletFundRecords(params?: WalletFundRecordsReq): Promise<APIResponseWithTime<any>>;
getWithdrawRecords(params?: WithdrawRecordsReq): Promise<APIResponseWithTime<any>>;
getAssetExchangeRecords(params?: AssetExchangeRecordsReq): Promise<APIResponseWithTime<any>>;
/**
*
* API Data Endpoints
*
*/
getServerTime(): Promise<APIResponseWithTime<{}>>;
getApiAnnouncements(): Promise<APIResponseWithTime<any[]>>;
/**
*
* Account Data Endpoints
*
*/
/**
* Active orders

@@ -61,3 +88,3 @@ */

order_link_id?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
getActiveOrderList(params: {

@@ -69,3 +96,3 @@ symbol: string;

cursor?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
cancelActiveOrder(params: {

@@ -75,4 +102,4 @@ symbol: string;

order_link_id?: string;
}): GenericAPIResponse;
cancelAllActiveOrders(params: SymbolParam): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
cancelAllActiveOrders(params: SymbolParam): Promise<APIResponseWithTime<any>>;
replaceActiveOrder(params: {

@@ -88,3 +115,3 @@ order_id?: string;

sl_trigger_by?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
queryActiveOrder(params: {

@@ -94,3 +121,3 @@ order_id?: string;

symbol: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/**

@@ -111,3 +138,4 @@ * Conditional orders

order_link_id?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/** get conditional order list. This may see delays, use queryConditionalOrder() for real-time queries */
getConditionalOrder(params: {

@@ -119,3 +147,3 @@ symbol: string;

cursor?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
cancelConditionalOrder(params: {

@@ -125,4 +153,4 @@ symbol: string;

order_link_id?: string;
}): GenericAPIResponse;
cancelAllConditionalOrders(params: SymbolParam): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
cancelAllConditionalOrders(params: SymbolParam): Promise<APIResponseWithTime<any>>;
replaceConditionalOrder(params: {

@@ -135,3 +163,3 @@ stop_order_id?: string;

p_r_trigger_price?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
queryConditionalOrder(params: {

@@ -141,19 +169,11 @@ symbol: string;

order_link_id?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/**
* Position
*/
/**
* @deprecated use getPosition() instead
*/
getUserLeverage(): GenericAPIResponse;
getPosition(params?: Partial<SymbolParam>): GenericAPIResponse;
/**
* @deprecated use getPosition() instead
*/
getPositions(): GenericAPIResponse;
getPosition(params?: Partial<SymbolParam>): Promise<APIResponseWithTime<any>>;
changePositionMargin(params: {
symbol: string;
margin: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
setTradingStop(params: {

@@ -167,3 +187,3 @@ symbol: string;

new_trailing_active?: number;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
setUserLeverage(params: {

@@ -173,7 +193,3 @@ symbol: string;

leverage_only?: boolean;
}): GenericAPIResponse;
/**
* @deprecated use setUserLeverage() instead
*/
changeUserLeverage(params: any): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
getTradeRecords(params: {

@@ -186,3 +202,3 @@ order_id?: string;

order?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
getClosedPnl(params: {

@@ -195,11 +211,7 @@ symbol: string;

limit?: number;
}): GenericAPIResponse;
setPositionMode(params: {
symbol: string;
mode: 0 | 3;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
setSlTpPositionMode(params: {
symbol: string;
tp_sl_mode: 'Full' | 'Partial';
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
setMarginType(params: {

@@ -210,22 +222,21 @@ symbol: string;

sell_leverage: number;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/**
* Risk Limit
*/
getRiskLimitList(): GenericAPIResponse;
getRiskLimitList(): Promise<APIResponseWithTime<any>>;
setRiskLimit(params: {
symbol: string;
risk_id: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/**
* Funding
*/
getLastFundingRate(params: SymbolParam): GenericAPIResponse;
getMyLastFundingFee(params: SymbolParam): GenericAPIResponse;
getPredictedFunding(params: SymbolParam): GenericAPIResponse;
getLastFundingRate(params: SymbolParam): Promise<APIResponseWithTime<any>>;
getMyLastFundingFee(params: SymbolParam): Promise<APIResponseWithTime<any>>;
getPredictedFunding(params: SymbolParam): Promise<APIResponseWithTime<any>>;
/**
* LCP Info
*/
getLcpInfo(params: SymbolParam): GenericAPIResponse;
getAPIKeyInfo(): GenericAPIResponse;
getLcpInfo(params: SymbolParam): Promise<APIResponseWithTime<any>>;
}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -8,5 +17,4 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const requestUtils_1 = require("./util/requestUtils");
const requestWrapper_1 = __importDefault(require("./util/requestWrapper"));
const shared_endpoints_1 = __importDefault(require("./shared-endpoints"));
class InverseClient extends shared_endpoints_1.default {
const BaseRestClient_1 = __importDefault(require("./util/BaseRestClient"));
class InverseClient extends BaseRestClient_1.default {
/**

@@ -22,6 +30,11 @@ * @public Creates an instance of the inverse REST API client.

constructor(key, secret, useLivenet = false, restClientOptions = {}, requestOptions = {}) {
super();
this.requestWrapper = new requestWrapper_1.default(key, secret, requestUtils_1.getRestBaseUrl(useLivenet, restClientOptions), restClientOptions, requestOptions);
super(key, secret, requestUtils_1.getRestBaseUrl(useLivenet, restClientOptions), restClientOptions, requestOptions, requestUtils_1.REST_CLIENT_TYPE_ENUM.inverse);
return this;
}
fetchServerTime() {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.getServerTime();
return Number(res.time_now);
});
}
/**

@@ -32,54 +45,104 @@ *

*/
getOrderBook(params) {
return this.get('v2/public/orderBook/L2', params);
}
getKline(params) {
return this.requestWrapper.get('v2/public/kline/list', params);
return this.get('v2/public/kline/list', params);
}
/**
* @deprecated use getTickers() instead
* Get latest information for symbol
*/
getLatestInformation(params) {
return this.getTickers(params);
getTickers(params) {
return this.get('v2/public/tickers', params);
}
/**
* @deprecated use getTrades() instead
*/
getPublicTradingRecords(params) {
return this.getTrades(params);
}
getTrades(params) {
return this.requestWrapper.get('v2/public/trading-records', params);
return this.get('v2/public/trading-records', params);
}
getSymbols() {
return this.get('v2/public/symbols');
}
getMarkPriceKline(params) {
return this.requestWrapper.get('v2/public/mark-price-kline', params);
return this.get('v2/public/mark-price-kline', params);
}
getIndexPriceKline(params) {
return this.requestWrapper.get('v2/public/index-price-kline', params);
return this.get('v2/public/index-price-kline', params);
}
getPremiumIndexKline(params) {
return this.requestWrapper.get('v2/public/premium-index-kline', params);
return this.get('v2/public/premium-index-kline', params);
}
/**
*
* Market Data : Advanced
*
*/
getOpenInterest(params) {
return this.get('v2/public/open-interest', params);
}
getLatestBigDeal(params) {
return this.get('v2/public/big-deal', params);
}
getLongShortRatio(params) {
return this.get('v2/public/account-ratio', params);
}
/**
*
* Account Data Endpoints
*
*/
getApiKeyInfo() {
return this.getPrivate('v2/private/account/api-key');
}
/**
*
* Wallet Data Endpoints
*
*/
getWalletBalance(params) {
return this.getPrivate('v2/private/wallet/balance', params);
}
getWalletFundRecords(params) {
return this.getPrivate('v2/private/wallet/fund/records', params);
}
getWithdrawRecords(params) {
return this.getPrivate('v2/private/wallet/withdraw/list', params);
}
getAssetExchangeRecords(params) {
return this.getPrivate('v2/private/exchange-order/list', params);
}
/**
*
* API Data Endpoints
*
*/
getServerTime() {
return this.get('v2/public/time');
}
getApiAnnouncements() {
return this.get('v2/public/announcement');
}
/**
*
* Account Data Endpoints
*
*/
/**
* Active orders
*/
placeActiveOrder(orderRequest) {
return this.requestWrapper.post('v2/private/order/create', orderRequest);
return this.postPrivate('v2/private/order/create', orderRequest);
}
getActiveOrderList(params) {
return this.requestWrapper.get('v2/private/order/list', params);
return this.getPrivate('v2/private/order/list', params);
}
cancelActiveOrder(params) {
return this.requestWrapper.post('v2/private/order/cancel', params);
return this.postPrivate('v2/private/order/cancel', params);
}
cancelAllActiveOrders(params) {
return this.requestWrapper.post('v2/private/order/cancelAll', params);
return this.postPrivate('v2/private/order/cancelAll', params);
}
replaceActiveOrder(params) {
return this.requestWrapper.post('v2/private/order/replace', params);
return this.postPrivate('v2/private/order/replace', params);
}
queryActiveOrder(params) {
return this.requestWrapper.get('v2/private/order', params);
return this.getPrivate('v2/private/order', params);
}

@@ -90,18 +153,19 @@ /**

placeConditionalOrder(params) {
return this.requestWrapper.post('v2/private/stop-order/create', params);
return this.postPrivate('v2/private/stop-order/create', params);
}
/** get conditional order list. This may see delays, use queryConditionalOrder() for real-time queries */
getConditionalOrder(params) {
return this.requestWrapper.get('v2/private/stop-order/list', params);
return this.getPrivate('v2/private/stop-order/list', params);
}
cancelConditionalOrder(params) {
return this.requestWrapper.post('v2/private/stop-order/cancel', params);
return this.postPrivate('v2/private/stop-order/cancel', params);
}
cancelAllConditionalOrders(params) {
return this.requestWrapper.post('v2/private/stop-order/cancelAll', params);
return this.postPrivate('v2/private/stop-order/cancelAll', params);
}
replaceConditionalOrder(params) {
return this.requestWrapper.post('v2/private/stop-order/replace', params);
return this.postPrivate('v2/private/stop-order/replace', params);
}
queryConditionalOrder(params) {
return this.requestWrapper.get('v2/private/stop-order', params);
return this.getPrivate('v2/private/stop-order', params);
}

@@ -111,46 +175,25 @@ /**

*/
/**
* @deprecated use getPosition() instead
*/
getUserLeverage() {
return this.requestWrapper.get('user/leverage');
}
getPosition(params) {
return this.requestWrapper.get('v2/private/position/list', params);
return this.getPrivate('v2/private/position/list', params);
}
/**
* @deprecated use getPosition() instead
*/
getPositions() {
return this.requestWrapper.get('position/list');
}
changePositionMargin(params) {
return this.requestWrapper.post('position/change-position-margin', params);
return this.postPrivate('position/change-position-margin', params);
}
setTradingStop(params) {
return this.requestWrapper.post('v2/private/position/trading-stop', params);
return this.postPrivate('v2/private/position/trading-stop', params);
}
setUserLeverage(params) {
return this.requestWrapper.post('v2/private/position/leverage/save', params);
return this.postPrivate('v2/private/position/leverage/save', params);
}
/**
* @deprecated use setUserLeverage() instead
*/
changeUserLeverage(params) {
return this.setUserLeverage(params);
}
getTradeRecords(params) {
return this.requestWrapper.get('v2/private/execution/list', params);
return this.getPrivate('v2/private/execution/list', params);
}
getClosedPnl(params) {
return this.requestWrapper.get('v2/private/trade/closed-pnl/list', params);
return this.getPrivate('v2/private/trade/closed-pnl/list', params);
}
setPositionMode(params) {
return this.requestWrapper.post('v2/private/position/switch-mode', params);
}
setSlTpPositionMode(params) {
return this.requestWrapper.post('v2/private/tpsl/switch-mode', params);
return this.postPrivate('v2/private/tpsl/switch-mode', params);
}
setMarginType(params) {
return this.requestWrapper.post('v2/private/position/switch-isolated', params);
return this.postPrivate('v2/private/position/switch-isolated', params);
}

@@ -161,6 +204,6 @@ /**

getRiskLimitList() {
return this.requestWrapper.get('open-api/wallet/risk-limit/list');
return this.getPrivate('open-api/wallet/risk-limit/list');
}
setRiskLimit(params) {
return this.requestWrapper.post('open-api/wallet/risk-limit', params);
return this.postPrivate('open-api/wallet/risk-limit', params);
}

@@ -171,9 +214,9 @@ /**

getLastFundingRate(params) {
return this.requestWrapper.get('v2/public/funding/prev-funding-rate', params);
return this.get('v2/public/funding/prev-funding-rate', params);
}
getMyLastFundingFee(params) {
return this.requestWrapper.get('v2/private/funding/prev-funding', params);
return this.getPrivate('v2/private/funding/prev-funding', params);
}
getPredictedFunding(params) {
return this.requestWrapper.get('v2/private/funding/predicted-funding', params);
return this.getPrivate('v2/private/funding/predicted-funding', params);
}

@@ -184,11 +227,6 @@ /**

getLcpInfo(params) {
return this.requestWrapper.get('v2/private/account/lcp', params);
return this.getPrivate('v2/private/account/lcp', params);
}
//API Key Info
getAPIKeyInfo() {
return this.requestWrapper.get('v2/private/account/api-key');
}
}
exports.InverseClient = InverseClient;
;
//# sourceMappingURL=inverse-client.js.map
import { AxiosRequestConfig } from 'axios';
import { GenericAPIResponse, RestClientOptions } from './util/requestUtils';
import RequestWrapper from './util/requestWrapper';
import SharedEndpoints from './shared-endpoints';
import { SymbolFromLimitParam, SymbolIntervalFromLimitParam, SymbolParam } from './types/shared';
export declare class InverseFuturesClient extends SharedEndpoints {
protected requestWrapper: RequestWrapper;
import { RestClientOptions } from './util/requestUtils';
import { APIResponseWithTime, AssetExchangeRecordsReq, CoinParam, SymbolInfo, SymbolIntervalFromLimitParam, SymbolLimitParam, SymbolParam, SymbolPeriodLimitParam, WalletFundRecordsReq, WithdrawRecordsReq } from './types/shared';
import BaseRestClient from './util/BaseRestClient';
export declare class InverseFuturesClient extends BaseRestClient {
/**

@@ -18,23 +16,60 @@ * @public Creates an instance of the inverse futures REST API client.

constructor(key?: string | undefined, secret?: string | undefined, useLivenet?: boolean, restClientOptions?: RestClientOptions, requestOptions?: AxiosRequestConfig);
fetchServerTime(): Promise<number>;
/**
*
* Market Data Endpoints
* Note: These are currently the same as the inverse client
*
*/
getKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse;
getOrderBook(params: SymbolParam): Promise<APIResponseWithTime<any[]>>;
getKline(params: SymbolIntervalFromLimitParam): Promise<APIResponseWithTime<any[]>>;
/**
* Get latest information for symbol
*/
getTickers(params?: Partial<SymbolParam>): Promise<APIResponseWithTime<any[]>>;
/**
* Public trading records
*/
getTrades(params: SymbolFromLimitParam): GenericAPIResponse;
getMarkPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse;
getIndexPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse;
getPremiumIndexKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse;
getTrades(params: SymbolLimitParam): Promise<APIResponseWithTime<any[]>>;
getSymbols(): Promise<APIResponseWithTime<SymbolInfo[]>>;
getMarkPriceKline(params: SymbolIntervalFromLimitParam): Promise<APIResponseWithTime<any[]>>;
getIndexPriceKline(params: SymbolIntervalFromLimitParam): Promise<APIResponseWithTime<any[]>>;
getPremiumIndexKline(params: SymbolIntervalFromLimitParam): Promise<APIResponseWithTime<any[]>>;
/**
*
* Market Data : Advanced
*
*/
getOpenInterest(params: SymbolPeriodLimitParam): Promise<APIResponseWithTime<any[]>>;
getLatestBigDeal(params: SymbolLimitParam): Promise<APIResponseWithTime<any[]>>;
getLongShortRatio(params: SymbolPeriodLimitParam): Promise<APIResponseWithTime<any[]>>;
/**
*
* Account Data Endpoints
*
*/
getApiKeyInfo(): Promise<APIResponseWithTime<any>>;
/**
* Active orders
*/
*
* Wallet Data Endpoints
*
*/
getWalletBalance(params?: Partial<CoinParam>): Promise<APIResponseWithTime<any>>;
getWalletFundRecords(params?: WalletFundRecordsReq): Promise<APIResponseWithTime<any>>;
getWithdrawRecords(params?: WithdrawRecordsReq): Promise<APIResponseWithTime<any>>;
getAssetExchangeRecords(params?: AssetExchangeRecordsReq): Promise<APIResponseWithTime<any>>;
/**
*
* API Data Endpoints
*
*/
getServerTime(): Promise<APIResponseWithTime<{}>>;
getApiAnnouncements(): Promise<APIResponseWithTime<any>>;
/**
*
* Account Data Endpoints
*
*/
/**
* Active orders
*/
placeActiveOrder(orderRequest: {

@@ -52,3 +87,3 @@ side: string;

order_link_id?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
getActiveOrderList(params: {

@@ -60,3 +95,3 @@ symbol: string;

cursor?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
cancelActiveOrder(params: {

@@ -66,4 +101,4 @@ symbol: string;

order_link_id?: string;
}): GenericAPIResponse;
cancelAllActiveOrders(params: SymbolParam): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
cancelAllActiveOrders(params: SymbolParam): Promise<APIResponseWithTime<any>>;
replaceActiveOrder(params: {

@@ -75,3 +110,3 @@ order_id?: string;

p_r_price?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
queryActiveOrder(params: {

@@ -81,6 +116,6 @@ order_id?: string;

symbol: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/**
* Conditional orders
*/
* Conditional orders
*/
placeConditionalOrder(params: {

@@ -98,3 +133,3 @@ side: string;

order_link_id?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
getConditionalOrder(params: {

@@ -106,3 +141,3 @@ symbol: string;

cursor?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
cancelConditionalOrder(params: {

@@ -112,4 +147,4 @@ symbol: string;

order_link_id?: string;
}): GenericAPIResponse;
cancelAllConditionalOrders(params: SymbolParam): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
cancelAllConditionalOrders(params: SymbolParam): Promise<APIResponseWithTime<any>>;
replaceConditionalOrder(params: {

@@ -122,3 +157,3 @@ stop_order_id?: string;

p_r_trigger_price?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
queryConditionalOrder(params: {

@@ -128,14 +163,14 @@ symbol: string;

order_link_id?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/**
* Position
*/
* Position
*/
/**
* Get position list
*/
getPosition(params?: Partial<SymbolParam>): GenericAPIResponse;
getPosition(params?: Partial<SymbolParam>): Promise<APIResponseWithTime<any>>;
changePositionMargin(params: {
symbol: string;
margin: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
setTradingStop(params: {

@@ -149,3 +184,3 @@ symbol: string;

new_trailing_active?: number;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
setUserLeverage(params: {

@@ -155,3 +190,3 @@ symbol: string;

sell_leverage: number;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/**

@@ -163,3 +198,3 @@ * Position mode switch

mode: number;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/**

@@ -173,3 +208,3 @@ * Cross/Isolated margin switch. Must set leverage value when switching.

sell_leverage: number;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
getTradeRecords(params: {

@@ -182,3 +217,3 @@ order_id?: string;

order?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
getClosedPnl(params: {

@@ -191,3 +226,3 @@ symbol: string;

limit?: number;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/**

@@ -197,19 +232,19 @@ **** The following are all the same as the inverse client ****

/**
* Risk Limit
*/
getRiskLimitList(): GenericAPIResponse;
* Risk Limit
*/
getRiskLimitList(): Promise<APIResponseWithTime<any>>;
setRiskLimit(params: {
symbol: string;
risk_id: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/**
* Funding
*/
getLastFundingRate(params: SymbolParam): GenericAPIResponse;
getMyLastFundingFee(params: SymbolParam): GenericAPIResponse;
getPredictedFunding(params: SymbolParam): GenericAPIResponse;
* Funding
*/
getLastFundingRate(params: SymbolParam): Promise<APIResponseWithTime<any>>;
getMyLastFundingFee(params: SymbolParam): Promise<APIResponseWithTime<any>>;
getPredictedFunding(params: SymbolParam): Promise<APIResponseWithTime<any>>;
/**
* LCP Info
*/
getLcpInfo(params: SymbolParam): GenericAPIResponse;
* LCP Info
*/
getLcpInfo(params: SymbolParam): Promise<APIResponseWithTime<any>>;
}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -8,5 +17,4 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const requestUtils_1 = require("./util/requestUtils");
const requestWrapper_1 = __importDefault(require("./util/requestWrapper"));
const shared_endpoints_1 = __importDefault(require("./shared-endpoints"));
class InverseFuturesClient extends shared_endpoints_1.default {
const BaseRestClient_1 = __importDefault(require("./util/BaseRestClient"));
class InverseFuturesClient extends BaseRestClient_1.default {
/**

@@ -22,79 +30,146 @@ * @public Creates an instance of the inverse futures REST API client.

constructor(key, secret, useLivenet = false, restClientOptions = {}, requestOptions = {}) {
super();
this.requestWrapper = new requestWrapper_1.default(key, secret, requestUtils_1.getRestBaseUrl(useLivenet, restClientOptions), restClientOptions, requestOptions);
super(key, secret, requestUtils_1.getRestBaseUrl(useLivenet, restClientOptions), restClientOptions, requestOptions, requestUtils_1.REST_CLIENT_TYPE_ENUM.inverseFutures);
return this;
}
fetchServerTime() {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.getServerTime();
return Number(res.time_now);
});
}
/**
*
* Market Data Endpoints
* Note: These are currently the same as the inverse client
*
*/
getOrderBook(params) {
return this.get('v2/public/orderBook/L2', params);
}
getKline(params) {
return this.requestWrapper.get('v2/public/kline/list', params);
return this.get('v2/public/kline/list', params);
}
/**
* Get latest information for symbol
*/
getTickers(params) {
return this.get('v2/public/tickers', params);
}
/**
* Public trading records
*/
getTrades(params) {
return this.requestWrapper.get('v2/public/trading-records', params);
return this.get('v2/public/trading-records', params);
}
getSymbols() {
return this.get('v2/public/symbols');
}
getMarkPriceKline(params) {
return this.requestWrapper.get('v2/public/mark-price-kline', params);
return this.get('v2/public/mark-price-kline', params);
}
getIndexPriceKline(params) {
return this.requestWrapper.get('v2/public/index-price-kline', params);
return this.get('v2/public/index-price-kline', params);
}
getPremiumIndexKline(params) {
return this.requestWrapper.get('v2/public/premium-index-kline', params);
return this.get('v2/public/premium-index-kline', params);
}
/**
*
* Market Data : Advanced
*
*/
getOpenInterest(params) {
return this.get('v2/public/open-interest', params);
}
getLatestBigDeal(params) {
return this.get('v2/public/big-deal', params);
}
getLongShortRatio(params) {
return this.get('v2/public/account-ratio', params);
}
/**
*
* Account Data Endpoints
*
*/
getApiKeyInfo() {
return this.getPrivate('v2/private/account/api-key');
}
/**
* Active orders
*/
*
* Wallet Data Endpoints
*
*/
getWalletBalance(params) {
return this.getPrivate('v2/private/wallet/balance', params);
}
getWalletFundRecords(params) {
return this.getPrivate('v2/private/wallet/fund/records', params);
}
getWithdrawRecords(params) {
return this.getPrivate('v2/private/wallet/withdraw/list', params);
}
getAssetExchangeRecords(params) {
return this.getPrivate('v2/private/exchange-order/list', params);
}
/**
*
* API Data Endpoints
*
*/
getServerTime() {
return this.get('v2/public/time');
}
getApiAnnouncements() {
return this.get('v2/public/announcement');
}
/**
*
* Account Data Endpoints
*
*/
/**
* Active orders
*/
placeActiveOrder(orderRequest) {
return this.requestWrapper.post('futures/private/order/create', orderRequest);
return this.postPrivate('futures/private/order/create', orderRequest);
}
getActiveOrderList(params) {
return this.requestWrapper.get('futures/private/order/list', params);
return this.getPrivate('futures/private/order/list', params);
}
cancelActiveOrder(params) {
return this.requestWrapper.post('futures/private/order/cancel', params);
return this.postPrivate('futures/private/order/cancel', params);
}
cancelAllActiveOrders(params) {
return this.requestWrapper.post('futures/private/order/cancelAll', params);
return this.postPrivate('futures/private/order/cancelAll', params);
}
replaceActiveOrder(params) {
return this.requestWrapper.post('futures/private/order/replace', params);
return this.postPrivate('futures/private/order/replace', params);
}
queryActiveOrder(params) {
return this.requestWrapper.get('futures/private/order', params);
return this.getPrivate('futures/private/order', params);
}
/**
* Conditional orders
*/
* Conditional orders
*/
placeConditionalOrder(params) {
return this.requestWrapper.post('futures/private/stop-order/create', params);
return this.postPrivate('futures/private/stop-order/create', params);
}
getConditionalOrder(params) {
return this.requestWrapper.get('futures/private/stop-order/list', params);
return this.getPrivate('futures/private/stop-order/list', params);
}
cancelConditionalOrder(params) {
return this.requestWrapper.post('futures/private/stop-order/cancel', params);
return this.postPrivate('futures/private/stop-order/cancel', params);
}
cancelAllConditionalOrders(params) {
return this.requestWrapper.post('futures/private/stop-order/cancelAll', params);
return this.postPrivate('futures/private/stop-order/cancelAll', params);
}
replaceConditionalOrder(params) {
return this.requestWrapper.post('futures/private/stop-order/replace', params);
return this.postPrivate('futures/private/stop-order/replace', params);
}
queryConditionalOrder(params) {
return this.requestWrapper.get('futures/private/stop-order', params);
return this.getPrivate('futures/private/stop-order', params);
}
/**
* Position
*/
* Position
*/
/**

@@ -104,12 +179,12 @@ * Get position list

getPosition(params) {
return this.requestWrapper.get('futures/private/position/list', params);
return this.getPrivate('futures/private/position/list', params);
}
changePositionMargin(params) {
return this.requestWrapper.post('futures/private/position/change-position-margin', params);
return this.postPrivate('futures/private/position/change-position-margin', params);
}
setTradingStop(params) {
return this.requestWrapper.post('futures/private/position/trading-stop', params);
return this.postPrivate('futures/private/position/trading-stop', params);
}
setUserLeverage(params) {
return this.requestWrapper.post('futures/private/position/leverage/save', params);
return this.postPrivate('futures/private/position/leverage/save', params);
}

@@ -120,3 +195,3 @@ /**

setPositionMode(params) {
return this.requestWrapper.post('futures/private/position/switch-mode', params);
return this.postPrivate('futures/private/position/switch-mode', params);
}

@@ -127,9 +202,9 @@ /**

setMarginType(params) {
return this.requestWrapper.post('futures/private/position/switch-isolated', params);
return this.postPrivate('futures/private/position/switch-isolated', params);
}
getTradeRecords(params) {
return this.requestWrapper.get('futures/private/execution/list', params);
return this.getPrivate('futures/private/execution/list', params);
}
getClosedPnl(params) {
return this.requestWrapper.get('futures/private/trade/closed-pnl/list', params);
return this.getPrivate('futures/private/trade/closed-pnl/list', params);
}

@@ -140,31 +215,30 @@ /**

/**
* Risk Limit
*/
* Risk Limit
*/
getRiskLimitList() {
return this.requestWrapper.get('open-api/wallet/risk-limit/list');
return this.getPrivate('open-api/wallet/risk-limit/list');
}
setRiskLimit(params) {
return this.requestWrapper.post('open-api/wallet/risk-limit', params);
return this.postPrivate('open-api/wallet/risk-limit', params);
}
/**
* Funding
*/
* Funding
*/
getLastFundingRate(params) {
return this.requestWrapper.get('v2/public/funding/prev-funding-rate', params);
return this.get('v2/public/funding/prev-funding-rate', params);
}
getMyLastFundingFee(params) {
return this.requestWrapper.get('v2/private/funding/prev-funding', params);
return this.getPrivate('v2/private/funding/prev-funding', params);
}
getPredictedFunding(params) {
return this.requestWrapper.get('v2/private/funding/predicted-funding', params);
return this.getPrivate('v2/private/funding/predicted-funding', params);
}
/**
* LCP Info
*/
* LCP Info
*/
getLcpInfo(params) {
return this.requestWrapper.get('v2/private/account/lcp', params);
return this.getPrivate('v2/private/account/lcp', params);
}
}
exports.InverseFuturesClient = InverseFuturesClient;
;
//# sourceMappingURL=inverse-futures-client.js.map
import { AxiosRequestConfig } from 'axios';
import { GenericAPIResponse, RestClientOptions } from './util/requestUtils';
import RequestWrapper from './util/requestWrapper';
import SharedEndpoints from './shared-endpoints';
import { SymbolIntervalFromLimitParam, SymbolLimitParam, SymbolParam } from './types/shared';
import { RestClientOptions } from './util/requestUtils';
import { APIResponse, APIResponseWithTime, AssetExchangeRecordsReq, CoinParam, SymbolInfo, SymbolIntervalFromLimitParam, SymbolLimitParam, SymbolParam, SymbolPeriodLimitParam, WalletFundRecordsReq, WithdrawRecordsReq } from './types/shared';
import { linearPositionModeEnum, positionTpSlModeEnum } from './constants/enum';
export declare class LinearClient extends SharedEndpoints {
protected requestWrapper: RequestWrapper;
import BaseRestClient from './util/BaseRestClient';
export declare class LinearClient extends BaseRestClient {
/**
* @public Creates an instance of the linear REST API client.
* @public Creates an instance of the linear (USD Perps) REST API client.
*

@@ -19,2 +17,3 @@ * @param {string} key - your API key

constructor(key?: string | undefined, secret?: string | undefined, useLivenet?: boolean, restClientOptions?: RestClientOptions, requestOptions?: AxiosRequestConfig);
fetchServerTime(): Promise<number>;
/**

@@ -25,13 +24,49 @@ *

*/
getKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse;
getTrades(params: SymbolLimitParam): GenericAPIResponse;
getLastFundingRate(params: SymbolParam): GenericAPIResponse;
getMarkPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse;
getIndexPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse;
getPremiumIndexKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse;
getOrderBook(params: SymbolParam): Promise<APIResponseWithTime<any[]>>;
getKline(params: SymbolIntervalFromLimitParam): Promise<APIResponseWithTime<any[]>>;
/**
* Get latest information for symbol
*/
getTickers(params?: Partial<SymbolParam>): Promise<APIResponseWithTime<any[]>>;
getTrades(params: SymbolLimitParam): Promise<APIResponseWithTime<any[]>>;
getSymbols(): Promise<APIResponse<SymbolInfo[]>>;
getLastFundingRate(params: SymbolParam): Promise<APIResponseWithTime<any[]>>;
getMarkPriceKline(params: SymbolIntervalFromLimitParam): Promise<APIResponseWithTime<any[]>>;
getIndexPriceKline(params: SymbolIntervalFromLimitParam): Promise<APIResponseWithTime<any[]>>;
getPremiumIndexKline(params: SymbolIntervalFromLimitParam): Promise<APIResponseWithTime<any[]>>;
/**
*
* Market Data : Advanced
*
*/
getOpenInterest(params: SymbolPeriodLimitParam): Promise<APIResponseWithTime<any[]>>;
getLatestBigDeal(params: SymbolLimitParam): Promise<APIResponseWithTime<any[]>>;
getLongShortRatio(params: SymbolPeriodLimitParam): Promise<APIResponseWithTime<any[]>>;
/**
*
* Account Data Endpoints
*
*/
getApiKeyInfo(): Promise<APIResponseWithTime<any>>;
/**
*
* Wallet Data Endpoints
*
*/
getWalletBalance(params?: Partial<CoinParam>): Promise<APIResponseWithTime<any>>;
getWalletFundRecords(params?: WalletFundRecordsReq): Promise<APIResponseWithTime<any>>;
getWithdrawRecords(params?: WithdrawRecordsReq): Promise<APIResponseWithTime<any>>;
getAssetExchangeRecords(params?: AssetExchangeRecordsReq): Promise<APIResponseWithTime<any>>;
/**
*
* API Data Endpoints
*
*/
getServerTime(): Promise<APIResponseWithTime<{}>>;
getApiAnnouncements(): Promise<APIResponseWithTime<any>>;
/**
*
* Account Data Endpoints
*
*/
placeActiveOrder(params: {

@@ -52,3 +87,3 @@ side: string;

position_idx?: number;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
getActiveOrderList(params: {

@@ -62,3 +97,3 @@ order_id?: string;

order_status?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
cancelActiveOrder(params: {

@@ -68,4 +103,4 @@ symbol: string;

order_link_id?: string;
}): GenericAPIResponse;
cancelAllActiveOrders(params: SymbolParam): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
cancelAllActiveOrders(params: SymbolParam): Promise<APIResponseWithTime<any>>;
replaceActiveOrder(params: {

@@ -81,3 +116,3 @@ order_id?: string;

sl_trigger_by?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
queryActiveOrder(params: {

@@ -87,3 +122,3 @@ order_id?: string;

symbol: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/**

@@ -109,3 +144,3 @@ * Conditional orders

sl_trigger_by?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
getConditionalOrder(params: {

@@ -119,3 +154,3 @@ stop_order_id?: string;

limit?: number;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
cancelConditionalOrder(params: {

@@ -125,4 +160,4 @@ symbol: string;

order_link_id?: string;
}): GenericAPIResponse;
cancelAllConditionalOrders(params: SymbolParam): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
cancelAllConditionalOrders(params: SymbolParam): Promise<APIResponseWithTime<any>>;
replaceConditionalOrder(params: {

@@ -139,3 +174,3 @@ stop_order_id?: string;

sl_trigger_by?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
queryConditionalOrder(params: {

@@ -145,7 +180,7 @@ symbol: string;

order_link_id?: string;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/**
* Position
*/
getPosition(params?: Partial<SymbolParam>): GenericAPIResponse;
getPosition(params?: Partial<SymbolParam>): Promise<APIResponseWithTime<any>>;
setAutoAddMargin(params?: {

@@ -155,3 +190,3 @@ symbol: string;

auto_add_margin: boolean;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
setMarginSwitch(params?: {

@@ -162,3 +197,3 @@ symbol: string;

sell_leverage: number;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/**

@@ -170,8 +205,3 @@ * Switch between one-way vs hedge mode. Use `linearPositionModeEnum` for the mode parameter.

mode: typeof linearPositionModeEnum[keyof typeof linearPositionModeEnum];
}): GenericAPIResponse;
/** @deprecated use setPositionTpSlMode() instead */
setSwitchMode(params?: {
symbol: string;
tp_sl_mode: typeof positionTpSlModeEnum[keyof typeof positionTpSlModeEnum];
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/**

@@ -184,3 +214,3 @@ * Switch TP/SL mode between full or partial. When set to Partial, TP/SL orders may have a quantity less than the position size.

tp_sl_mode: typeof positionTpSlModeEnum[keyof typeof positionTpSlModeEnum];
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
setAddReduceMargin(params?: {

@@ -190,3 +220,3 @@ symbol: string;

margin: number;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
setUserLeverage(params: {

@@ -196,3 +226,3 @@ symbol: string;

sell_leverage: number;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
setTradingStop(params: {

@@ -208,3 +238,3 @@ symbol: string;

tp_size?: number;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
getTradeRecords(params: {

@@ -217,3 +247,3 @@ symbol: string;

limit?: number;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
getClosedPnl(params: {

@@ -226,17 +256,17 @@ symbol: string;

limit?: number;
}): GenericAPIResponse;
}): Promise<APIResponseWithTime<any>>;
/**
* Risk Limit
*/
getRiskLimitList(params: SymbolParam): GenericAPIResponse;
getRiskLimitList(params: SymbolParam): Promise<APIResponseWithTime<any>>;
setRiskLimit(params: {
symbol: string;
side: string;
risk_id: string;
}): GenericAPIResponse;
risk_id: number;
}): Promise<APIResponseWithTime<any>>;
/**
* Funding
*/
getPredictedFundingFee(params: SymbolParam): GenericAPIResponse;
getLastFundingFee(params: SymbolParam): GenericAPIResponse;
getPredictedFundingFee(params: SymbolParam): Promise<APIResponseWithTime<any>>;
getLastFundingFee(params: SymbolParam): Promise<APIResponseWithTime<any>>;
}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -8,7 +17,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const requestUtils_1 = require("./util/requestUtils");
const requestWrapper_1 = __importDefault(require("./util/requestWrapper"));
const shared_endpoints_1 = __importDefault(require("./shared-endpoints"));
class LinearClient extends shared_endpoints_1.default {
const BaseRestClient_1 = __importDefault(require("./util/BaseRestClient"));
class LinearClient extends BaseRestClient_1.default {
/**
* @public Creates an instance of the linear REST API client.
* @public Creates an instance of the linear (USD Perps) REST API client.
*

@@ -22,6 +30,11 @@ * @param {string} key - your API key

constructor(key, secret, useLivenet = false, restClientOptions = {}, requestOptions = {}) {
super();
this.requestWrapper = new requestWrapper_1.default(key, secret, requestUtils_1.getRestBaseUrl(useLivenet, restClientOptions), restClientOptions, requestOptions);
super(key, secret, requestUtils_1.getRestBaseUrl(useLivenet, restClientOptions), restClientOptions, requestOptions, requestUtils_1.REST_CLIENT_TYPE_ENUM.linear);
return this;
}
fetchServerTime() {
return __awaiter(this, void 0, void 0, function* () {
const timeRes = yield this.getServerTime();
return Number(timeRes.time_now);
});
}
/**

@@ -32,42 +45,104 @@ *

*/
getOrderBook(params) {
return this.get('v2/public/orderBook/L2', params);
}
getKline(params) {
return this.requestWrapper.get('public/linear/kline', params);
return this.get('public/linear/kline', params);
}
/**
* Get latest information for symbol
*/
getTickers(params) {
return this.get('v2/public/tickers', params);
}
getTrades(params) {
return this.requestWrapper.get('public/linear/recent-trading-records', params);
return this.get('public/linear/recent-trading-records', params);
}
getSymbols() {
return this.get('v2/public/symbols');
}
getLastFundingRate(params) {
return this.requestWrapper.get('public/linear/funding/prev-funding-rate', params);
return this.get('public/linear/funding/prev-funding-rate', params);
}
getMarkPriceKline(params) {
return this.requestWrapper.get('public/linear/mark-price-kline', params);
return this.get('public/linear/mark-price-kline', params);
}
getIndexPriceKline(params) {
return this.requestWrapper.get('public/linear/index-price-kline', params);
return this.get('public/linear/index-price-kline', params);
}
getPremiumIndexKline(params) {
return this.requestWrapper.get('public/linear/premium-index-kline', params);
return this.get('public/linear/premium-index-kline', params);
}
/**
*
* Market Data : Advanced
*
*/
getOpenInterest(params) {
return this.get('v2/public/open-interest', params);
}
getLatestBigDeal(params) {
return this.get('v2/public/big-deal', params);
}
getLongShortRatio(params) {
return this.get('v2/public/account-ratio', params);
}
/**
*
* Account Data Endpoints
*
*/
getApiKeyInfo() {
return this.getPrivate('v2/private/account/api-key');
}
/**
*
* Wallet Data Endpoints
*
*/
getWalletBalance(params) {
return this.getPrivate('v2/private/wallet/balance', params);
}
getWalletFundRecords(params) {
return this.getPrivate('v2/private/wallet/fund/records', params);
}
getWithdrawRecords(params) {
return this.getPrivate('v2/private/wallet/withdraw/list', params);
}
getAssetExchangeRecords(params) {
return this.getPrivate('v2/private/exchange-order/list', params);
}
/**
*
* API Data Endpoints
*
*/
getServerTime() {
return this.get('v2/public/time');
}
getApiAnnouncements() {
return this.get('v2/public/announcement');
}
/**
*
* Account Data Endpoints
*
*/
placeActiveOrder(params) {
return this.requestWrapper.post('private/linear/order/create', params);
return this.postPrivate('private/linear/order/create', params);
}
getActiveOrderList(params) {
return this.requestWrapper.get('private/linear/order/list', params);
return this.getPrivate('private/linear/order/list', params);
}
cancelActiveOrder(params) {
return this.requestWrapper.post('private/linear/order/cancel', params);
return this.postPrivate('private/linear/order/cancel', params);
}
cancelAllActiveOrders(params) {
return this.requestWrapper.post('private/linear/order/cancel-all', params);
return this.postPrivate('private/linear/order/cancel-all', params);
}
replaceActiveOrder(params) {
return this.requestWrapper.post('private/linear/order/replace', params);
return this.postPrivate('private/linear/order/replace', params);
}
queryActiveOrder(params) {
return this.requestWrapper.get('private/linear/order/search', params);
return this.getPrivate('private/linear/order/search', params);
}

@@ -78,18 +153,18 @@ /**

placeConditionalOrder(params) {
return this.requestWrapper.post('private/linear/stop-order/create', params);
return this.postPrivate('private/linear/stop-order/create', params);
}
getConditionalOrder(params) {
return this.requestWrapper.get('private/linear/stop-order/list', params);
return this.getPrivate('private/linear/stop-order/list', params);
}
cancelConditionalOrder(params) {
return this.requestWrapper.post('private/linear/stop-order/cancel', params);
return this.postPrivate('private/linear/stop-order/cancel', params);
}
cancelAllConditionalOrders(params) {
return this.requestWrapper.post('private/linear/stop-order/cancel-all', params);
return this.postPrivate('private/linear/stop-order/cancel-all', params);
}
replaceConditionalOrder(params) {
return this.requestWrapper.post('private/linear/stop-order/replace', params);
return this.postPrivate('private/linear/stop-order/replace', params);
}
queryConditionalOrder(params) {
return this.requestWrapper.get('private/linear/stop-order/search', params);
return this.getPrivate('private/linear/stop-order/search', params);
}

@@ -100,9 +175,9 @@ /**

getPosition(params) {
return this.requestWrapper.get('private/linear/position/list', params);
return this.getPrivate('private/linear/position/list', params);
}
setAutoAddMargin(params) {
return this.requestWrapper.post('private/linear/position/set-auto-add-margin', params);
return this.postPrivate('private/linear/position/set-auto-add-margin', params);
}
setMarginSwitch(params) {
return this.requestWrapper.post('private/linear/position/switch-isolated', params);
return this.postPrivate('private/linear/position/switch-isolated', params);
}

@@ -113,8 +188,4 @@ /**

setPositionMode(params) {
return this.requestWrapper.post('private/linear/position/switch-mode', params);
return this.postPrivate('private/linear/position/switch-mode', params);
}
/** @deprecated use setPositionTpSlMode() instead */
setSwitchMode(params) {
return this.requestWrapper.post('private/linear/tpsl/switch-mode', params);
}
/**

@@ -125,18 +196,18 @@ * Switch TP/SL mode between full or partial. When set to Partial, TP/SL orders may have a quantity less than the position size.

setPositionTpSlMode(params) {
return this.requestWrapper.post('private/linear/tpsl/switch-mode', params);
return this.postPrivate('private/linear/tpsl/switch-mode', params);
}
setAddReduceMargin(params) {
return this.requestWrapper.post('private/linear/position/add-margin', params);
return this.postPrivate('private/linear/position/add-margin', params);
}
setUserLeverage(params) {
return this.requestWrapper.post('private/linear/position/set-leverage', params);
return this.postPrivate('private/linear/position/set-leverage', params);
}
setTradingStop(params) {
return this.requestWrapper.post('private/linear/position/trading-stop', params);
return this.postPrivate('private/linear/position/trading-stop', params);
}
getTradeRecords(params) {
return this.requestWrapper.get('private/linear/trade/execution/list', params);
return this.getPrivate('private/linear/trade/execution/list', params);
}
getClosedPnl(params) {
return this.requestWrapper.get('private/linear/trade/closed-pnl/list', params);
return this.getPrivate('private/linear/trade/closed-pnl/list', params);
}

@@ -147,6 +218,6 @@ /**

getRiskLimitList(params) {
return this.requestWrapper.get('public/linear/risk-limit', params);
return this.getPrivate('public/linear/risk-limit', params);
}
setRiskLimit(params) {
return this.requestWrapper.get('private/linear/position/set-risk', params);
return this.postPrivate('private/linear/position/set-risk', params);
}

@@ -157,6 +228,6 @@ /**

getPredictedFundingFee(params) {
return this.requestWrapper.get('private/linear/funding/predicted-funding', params);
return this.getPrivate('private/linear/funding/predicted-funding', params);
}
getLastFundingFee(params) {
return this.requestWrapper.get('private/linear/funding/prev-funding', params);
return this.getPrivate('private/linear/funding/prev-funding', params);
}

@@ -163,0 +234,0 @@ }

@@ -22,4 +22,4 @@ "use strict";

console.error(params);
}
},
};
//# sourceMappingURL=logger.js.map
import { AxiosRequestConfig } from 'axios';
import { KlineInterval } from './types/shared';
import { NewSpotOrder, OrderSide, OrderTypeSpot, SpotOrderQueryById } from './types/spot';
import { APIResponse, KlineInterval } from './types/shared';
import { NewSpotOrder, OrderSide, OrderTypeSpot, SpotOrderQueryById, SpotSymbolInfo } from './types/spot';
import BaseRestClient from './util/BaseRestClient';
import { GenericAPIResponse, RestClientOptions } from './util/requestUtils';
import RequestWrapper from './util/requestWrapper';
import { RestClientOptions } from './util/requestUtils';
export declare class SpotClient extends BaseRestClient {
protected requestWrapper: RequestWrapper;
/**

@@ -19,3 +17,4 @@ * @public Creates an instance of the Spot REST API client.

constructor(key?: string | undefined, secret?: string | undefined, useLivenet?: boolean, restClientOptions?: RestClientOptions, requestOptions?: AxiosRequestConfig);
getServerTime(urlKeyOverride?: string): Promise<number>;
fetchServerTime(): Promise<number>;
getServerTime(): Promise<number>;
/**

@@ -25,17 +24,17 @@ *

*
**/
getSymbols(): GenericAPIResponse;
getOrderBook(symbol: string, limit?: number): GenericAPIResponse;
getMergedOrderBook(symbol: string, scale?: number, limit?: number): GenericAPIResponse;
getTrades(symbol: string, limit?: number): GenericAPIResponse;
getCandles(symbol: string, interval: KlineInterval, limit?: number, startTime?: number, endTime?: number): GenericAPIResponse;
get24hrTicker(symbol?: string): GenericAPIResponse;
getLastTradedPrice(symbol?: string): GenericAPIResponse;
getBestBidAskPrice(symbol?: string): GenericAPIResponse;
**/
getSymbols(): Promise<APIResponse<SpotSymbolInfo[]>>;
getOrderBook(symbol: string, limit?: number): Promise<APIResponse<any>>;
getMergedOrderBook(symbol: string, scale?: number, limit?: number): Promise<APIResponse<any>>;
getTrades(symbol: string, limit?: number): Promise<APIResponse<any[]>>;
getCandles(symbol: string, interval: KlineInterval, limit?: number, startTime?: number, endTime?: number): Promise<APIResponse<any[]>>;
get24hrTicker(symbol?: string): Promise<APIResponse<any>>;
getLastTradedPrice(symbol?: string): Promise<APIResponse<any>>;
getBestBidAskPrice(symbol?: string): Promise<APIResponse<any>>;
/**
* Account Data Endpoints
*/
submitOrder(params: NewSpotOrder): GenericAPIResponse;
getOrder(params: SpotOrderQueryById): GenericAPIResponse;
cancelOrder(params: SpotOrderQueryById): GenericAPIResponse;
submitOrder(params: NewSpotOrder): Promise<APIResponse<any>>;
getOrder(params: SpotOrderQueryById): Promise<APIResponse<any>>;
cancelOrder(params: SpotOrderQueryById): Promise<APIResponse<any>>;
cancelOrderBatch(params: {

@@ -45,10 +44,10 @@ symbol: string;

orderTypes: OrderTypeSpot[];
}): GenericAPIResponse;
getOpenOrders(symbol?: string, orderId?: string, limit?: number): GenericAPIResponse;
getPastOrders(symbol?: string, orderId?: string, limit?: number): GenericAPIResponse;
getMyTrades(symbol?: string, limit?: number, fromId?: number, toId?: number): GenericAPIResponse;
}): Promise<APIResponse<any>>;
getOpenOrders(symbol?: string, orderId?: string, limit?: number): Promise<APIResponse<any>>;
getPastOrders(symbol?: string, orderId?: string, limit?: number): Promise<APIResponse<any>>;
getMyTrades(symbol?: string, limit?: number, fromId?: number, toId?: number): Promise<APIResponse<any>>;
/**
* Wallet Data Endpoints
*/
getBalances(): GenericAPIResponse;
getBalances(): Promise<APIResponse<any>>;
}

@@ -29,16 +29,12 @@ "use strict";

constructor(key, secret, useLivenet = false, restClientOptions = {}, requestOptions = {}) {
super(key, secret, requestUtils_1.getRestBaseUrl(useLivenet, restClientOptions), restClientOptions, requestOptions);
// this.requestWrapper = new RequestWrapper(
// key,
// secret,
// getRestBaseUrl(useLivenet, restClientOptions),
// restClientOptions,
// requestOptions
// );
super(key, secret, requestUtils_1.getRestBaseUrl(useLivenet, restClientOptions), restClientOptions, requestOptions, requestUtils_1.REST_CLIENT_TYPE_ENUM.spot);
return this;
}
getServerTime(urlKeyOverride) {
fetchServerTime() {
return this.getServerTime();
}
getServerTime() {
return __awaiter(this, void 0, void 0, function* () {
const result = yield this.get('/spot/v1/time');
return result.serverTime;
const res = yield this.get('/spot/v1/time');
return res.result.serverTime;
});

@@ -50,3 +46,3 @@ }

*
**/
**/
getSymbols() {

@@ -57,3 +53,4 @@ return this.get('/spot/v1/symbols');

return this.get('/spot/quote/v1/depth', {
symbol, limit
symbol,
limit,
});

@@ -69,3 +66,3 @@ }

getTrades(symbol, limit) {
return this.get('/spot/v1/trades', {
return this.get('/spot/quote/v1/trades', {
symbol,

@@ -97,3 +94,3 @@ limit,

submitOrder(params) {
return this.postPrivate('/spot/v1/order', params);
return this.postPrivate('/spot/v1/order', Object.assign(Object.assign({}, params), { agentSource: requestUtils_1.agentSource }));
}

@@ -107,3 +104,5 @@ getOrder(params) {

cancelOrderBatch(params) {
const orderTypes = params.orderTypes ? params.orderTypes.join(',') : undefined;
const orderTypes = params.orderTypes
? params.orderTypes.join(',')
: undefined;
return this.deletePrivate('/spot/order/batch-cancel', Object.assign(Object.assign({}, params), { orderTypes }));

@@ -110,0 +109,0 @@ }

@@ -5,7 +5,11 @@ export declare type KlineInterval = '1m' | '3m' | '5m' | '15m' | '30m' | '1h' | '2h' | '4h' | '6h' | '12h' | '1d' | '1w' | '1M';

ret_code: number;
ret_msg: "OK" | string;
ext_code: string;
ext_info: string;
ret_msg: 'OK' | string;
ext_code: string | null;
ext_info: string | null;
result: T;
}
export interface APIResponseWithTime<T> extends APIResponse<T> {
/** UTC timestamp */
time_now: numberInString;
}
/**

@@ -12,0 +16,0 @@ * Request Parameter Types

@@ -0,1 +1,2 @@

import { numberInString } from './shared';
export declare type OrderSide = 'Buy' | 'Sell';

@@ -17,1 +18,15 @@ export declare type OrderTypeSpot = 'LIMIT' | 'MARKET' | 'LIMIT_MAKER';

}
export interface SpotSymbolInfo {
name: string;
alias: string;
baseCurrency: string;
quoteCurrency: string;
basePrecision: numberInString;
quotePrecision: numberInString;
minTradeQuantity: numberInString;
minTradeAmount: numberInString;
minPricePrecision: numberInString;
maxTradeQuantity: numberInString;
maxTradeAmount: numberInString;
category: numberInString;
}
import { AxiosRequestConfig } from 'axios';
import { RestClientOptions, GenericAPIResponse } from './requestUtils';
import { RestClientOptions, RestClientType } from './requestUtils';
export default abstract class BaseRestClient {

@@ -11,8 +11,13 @@ private timeOffset;

private secret;
constructor(key: string | undefined, secret: string | undefined, baseUrl: string, options?: RestClientOptions, requestOptions?: AxiosRequestConfig);
get(endpoint: string, params?: any): GenericAPIResponse;
post(endpoint: string, params?: any): GenericAPIResponse;
getPrivate(endpoint: string, params?: any): GenericAPIResponse;
postPrivate(endpoint: string, params?: any): GenericAPIResponse;
deletePrivate(endpoint: string, params?: any): GenericAPIResponse;
private clientType;
/** Function that calls exchange API to query & resolve server time, used by time sync */
abstract fetchServerTime(): Promise<number>;
constructor(key: string | undefined, secret: string | undefined, baseUrl: string, options: RestClientOptions | undefined, requestOptions: AxiosRequestConfig | undefined, clientType: RestClientType);
private isSpotClient;
get(endpoint: string, params?: any): Promise<any>;
post(endpoint: string, params?: any): Promise<any>;
getPrivate(endpoint: string, params?: any): Promise<any>;
postPrivate(endpoint: string, params?: any): Promise<any>;
deletePrivate(endpoint: string, params?: any): Promise<any>;
private prepareSignParams;
/**

@@ -29,3 +34,3 @@ * @private Make a HTTP request to a specific endpoint. Private endpoints are automatically signed.

*/
signRequest(data: any): Promise<any>;
private signRequest;
/**

@@ -35,3 +40,2 @@ * Trigger time sync and store promise

private syncTime;
abstract getServerTime(baseUrlKeyOverride?: string): Promise<number>;
/**

@@ -38,0 +42,0 @@ * Estimate drift based on client<->server latency

@@ -19,5 +19,6 @@ "use strict";

class BaseRestClient {
constructor(key, secret, baseUrl, options = {}, requestOptions = {}) {
constructor(key, secret, baseUrl, options = {}, requestOptions = {}, clientType) {
this.timeOffset = null;
this.syncTimePromise = null;
this.clientType = clientType;
this.options = Object.assign({ recv_window: 5000,

@@ -31,3 +32,3 @@ // how often to sync time drift with bybit servers

timeout: 1000 * 60 * 5 }, requestOptions), { headers: {
'x-referer': 'bybitapinode'
'x-referer': 'bybitapinode',
} });

@@ -45,2 +46,5 @@ this.baseUrl = baseUrl;

}
isSpotClient() {
return this.clientType === requestUtils_1.REST_CLIENT_TYPE_ENUM.spot;
}
get(endpoint, params) {

@@ -61,2 +65,19 @@ return this._call('GET', endpoint, params, true);

}
prepareSignParams(params, isPublicApi) {
return __awaiter(this, void 0, void 0, function* () {
if (isPublicApi) {
return {
originalParams: params,
paramsWithSign: params,
};
}
if (!this.key || !this.secret) {
throw new Error('Private endpoints require api and private keys set');
}
if (this.timeOffset === null) {
yield this.syncTime();
}
return this.signRequest(params);
});
}
/**

@@ -66,20 +87,24 @@ * @private Make a HTTP request to a specific endpoint. Private endpoints are automatically signed.

_call(method, endpoint, params, isPublicApi) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (!isPublicApi) {
if (!this.key || !this.secret) {
throw new Error('Private endpoints require api and private keys set');
const options = Object.assign(Object.assign({}, this.globalRequestOptions), { url: [this.baseUrl, endpoint].join(endpoint.startsWith('/') ? '' : '/'), method: method, json: true });
for (const key in params) {
if (typeof params[key] === 'undefined') {
delete params[key];
}
if (this.timeOffset === null) {
yield this.syncTime();
}
const signResult = yield this.prepareSignParams(params, isPublicApi);
if (method === 'GET' || this.isSpotClient()) {
options.params = signResult.paramsWithSign;
if ((_a = options.params) === null || _a === void 0 ? void 0 : _a.agentSource) {
options.data = {
agentSource: requestUtils_1.agentSource,
};
}
params = yield this.signRequest(params);
}
const options = Object.assign(Object.assign({}, this.globalRequestOptions), { url: [this.baseUrl, endpoint].join(endpoint.startsWith('/') ? '' : '/'), method: method, json: true });
if (method === 'GET') {
options.params = params;
}
else {
options.data = params;
options.data = signResult.paramsWithSign;
}
return axios_1.default(options).then(response => {
return axios_1.default(options)
.then((response) => {
if (response.status == 200) {

@@ -89,3 +114,4 @@ return response.data;

throw response;
}).catch(e => this.parseException(e));
})
.catch((e) => this.parseException(e));
});

@@ -116,3 +142,3 @@ }

headers: response.headers,
requestOptions: this.options
requestOptions: this.options,
};

@@ -125,12 +151,21 @@ }

return __awaiter(this, void 0, void 0, function* () {
const params = Object.assign(Object.assign({}, data), { api_key: this.key, timestamp: Date.now() + (this.timeOffset || 0) });
const res = {
originalParams: Object.assign(Object.assign({}, data), { api_key: this.key, timestamp: Date.now() + (this.timeOffset || 0) }),
sign: '',
};
// Optional, set to 5000 by default. Increase if timestamp/recv_window errors are seen.
if (this.options.recv_window && !params.recv_window) {
params.recv_window = this.options.recv_window;
if (this.options.recv_window && !res.originalParams.recv_window) {
if (this.isSpotClient()) {
res.originalParams.recvWindow = this.options.recv_window;
}
else {
res.originalParams.recv_window = this.options.recv_window;
}
}
if (this.key && this.secret) {
const serializedParams = requestUtils_1.serializeParams(params, this.options.strict_param_validation);
params.sign = yield node_support_1.signMessage(serializedParams, this.secret);
const serializedParams = requestUtils_1.serializeParams(res.originalParams, this.options.strict_param_validation);
res.sign = yield node_support_1.signMessage(serializedParams, this.secret);
res.paramsWithSign = Object.assign(Object.assign({}, res.originalParams), { sign: res.sign });
}
return params;
return res;
});

@@ -148,3 +183,3 @@ }

}
this.syncTimePromise = this.fetchTimeOffset().then(offset => {
this.syncTimePromise = this.fetchTimeOffset().then((offset) => {
this.timeOffset = offset;

@@ -162,5 +197,8 @@ this.syncTimePromise = null;

const start = Date.now();
const serverTime = yield this.getServerTime();
const serverTime = yield this.fetchServerTime();
if (!serverTime || isNaN(serverTime)) {
throw new Error(`fetchServerTime() returned non-number: "${serverTime}" typeof(${typeof serverTime})`);
}
const end = Date.now();
const avgDrift = ((end - start) / 2);
const avgDrift = (end - start) / 2;
return Math.ceil(serverTime - end + avgDrift);

@@ -176,3 +214,2 @@ }

exports.default = BaseRestClient;
;
//# sourceMappingURL=BaseRestClient.js.map

@@ -18,7 +18,8 @@ "use strict";

const signature = yield window.crypto.subtle.sign('HMAC', key, encoder.encode(message));
return Array.prototype.map.call(new Uint8Array(signature), (x) => ('00' + x.toString(16)).slice(-2)).join('');
return Array.prototype.map
.call(new Uint8Array(signature), (x) => ('00' + x.toString(16)).slice(-2))
.join('');
});
}
exports.signMessage = signMessage;
;
//# sourceMappingURL=browser-support.js.map

@@ -16,9 +16,6 @@ "use strict";

return __awaiter(this, void 0, void 0, function* () {
return crypto_1.createHmac('sha256', secret)
.update(message)
.digest('hex');
return crypto_1.createHmac('sha256', secret).update(message).digest('hex');
});
}
exports.signMessage = signMessage;
;
//# sourceMappingURL=node-support.js.map

@@ -9,3 +9,2 @@ export interface RestClientOptions {

}
export declare type GenericAPIResponse = Promise<any>;
export declare function serializeParams(params?: object, strict_validation?: boolean): string;

@@ -15,1 +14,9 @@ export declare function getRestBaseUrl(useLivenet: boolean, restInverseOptions: RestClientOptions): string;

export declare function isWsPong(response: any): any;
export declare const agentSource = "bybitapinode";
export declare const REST_CLIENT_TYPE_ENUM: {
readonly inverse: "inverse";
readonly inverseFutures: "inverseFutures";
readonly linear: "linear";
readonly spot: "spot";
};
export declare type RestClientType = typeof REST_CLIENT_TYPE_ENUM[keyof typeof REST_CLIENT_TYPE_ENUM];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isWsPong = exports.isPublicEndpoint = exports.getRestBaseUrl = exports.serializeParams = void 0;
exports.REST_CLIENT_TYPE_ENUM = exports.agentSource = exports.isWsPong = exports.isPublicEndpoint = exports.getRestBaseUrl = exports.serializeParams = void 0;
function serializeParams(params = {}, strict_validation = false) {
return Object.keys(params)
.sort()
.map(key => {
.map((key) => {
const value = params[key];

@@ -17,7 +17,6 @@ if (strict_validation === true && typeof value === 'undefined') {

exports.serializeParams = serializeParams;
;
function getRestBaseUrl(useLivenet, restInverseOptions) {
const baseUrlsInverse = {
livenet: 'https://api.bybit.com',
testnet: 'https://api-testnet.bybit.com'
testnet: 'https://api-testnet.bybit.com',
};

@@ -34,8 +33,14 @@ if (restInverseOptions.baseUrl) {

function isPublicEndpoint(endpoint) {
if (endpoint.startsWith('v2/public')) {
return true;
const publicPrefixes = [
'v2/public',
'public/linear',
'spot/quote/v1',
'spot/v1/symbols',
'spot/v1/time',
];
for (const prefix of publicPrefixes) {
if (endpoint.startsWith(prefix)) {
return true;
}
}
if (endpoint.startsWith('public/linear')) {
return true;
}
return false;

@@ -45,3 +50,3 @@ }

function isWsPong(response) {
if (response.pong) {
if (response.pong || response.ping) {
return true;

@@ -55,2 +60,9 @@ }

exports.isWsPong = isWsPong;
exports.agentSource = 'bybitapinode';
exports.REST_CLIENT_TYPE_ENUM = {
inverse: 'inverse',
inverseFutures: 'inverseFutures',
linear: 'linear',
spot: 'spot',
};
//# sourceMappingURL=requestUtils.js.map

@@ -1,2 +0,1 @@

/// <reference types="node" />
import { WsConnectionState } from '../websocket-client';

@@ -10,4 +9,4 @@ import { DefaultLogger } from '../logger';

connectionState?: WsConnectionState;
activePingTimer?: NodeJS.Timeout | undefined;
activePongTimer?: NodeJS.Timeout | undefined;
activePingTimer?: ReturnType<typeof setTimeout> | undefined;
activePongTimer?: ReturnType<typeof setTimeout> | undefined;
subscribedTopics: WsTopicList;

@@ -14,0 +13,0 @@ }

@@ -5,3 +5,2 @@ "use strict";

const logger_1 = require("../logger");
;
class WsStore {

@@ -29,3 +28,3 @@ constructor(logger) {

subscribedTopics: new Set(),
connectionState: websocket_client_1.WsConnectionState.READY_STATE_INITIAL
connectionState: websocket_client_1.WsConnectionState.READY_STATE_INITIAL,
};

@@ -60,3 +59,4 @@ return this.get(key);

const existingConnection = this.getWs(key);
return !!existingConnection && existingConnection.readyState === existingConnection.OPEN;
return (!!existingConnection &&
existingConnection.readyState === existingConnection.OPEN);
}

@@ -63,0 +63,0 @@ getConnectionState(key) {

@@ -26,3 +26,3 @@ "use strict";

livenet: 'wss://stream.bybit.com/realtime',
testnet: 'wss://stream-testnet.bybit.com/realtime'
testnet: 'wss://stream-testnet.bybit.com/realtime',
};

@@ -33,3 +33,3 @@ const linearEndpoints = {

livenet2: 'wss://stream.bytick.com/realtime_private',
testnet: 'wss://stream-testnet.bybit.com/realtime_private'
testnet: 'wss://stream-testnet.bybit.com/realtime_private',
},

@@ -39,4 +39,4 @@ public: {

livenet2: 'wss://stream.bytick.com/realtime_public',
testnet: 'wss://stream-testnet.bybit.com/realtime_public'
}
testnet: 'wss://stream-testnet.bybit.com/realtime_public',
},
};

@@ -53,3 +53,3 @@ const spotEndpoints = {

testnet2: 'wss://stream-testnet.bybit.com/spot/quote/ws/v2',
}
},
};

@@ -70,5 +70,2 @@ const loggerCategory = { category: 'bybit-ws' };

})(WsConnectionState = exports.WsConnectionState || (exports.WsConnectionState = {}));
;
;
;
exports.wsKeyInverse = 'inverse';

@@ -80,3 +77,9 @@ exports.wsKeyLinearPrivate = 'linearPrivate';

const getLinearWsKeyForTopic = (topic) => {
const privateLinearTopics = ['position', 'execution', 'order', 'stop_order', 'wallet'];
const privateLinearTopics = [
'position',
'execution',
'order',
'stop_order',
'wallet',
];
if (privateLinearTopics.includes(topic)) {

@@ -88,3 +91,11 @@ return exports.wsKeyLinearPrivate;

const getSpotWsKeyForTopic = (topic) => {
const privateLinearTopics = ['position', 'execution', 'order', 'stop_order', 'outboundAccountInfo', 'executionReport', 'ticketInfo'];
const privateLinearTopics = [
'position',
'execution',
'order',
'stop_order',
'outboundAccountInfo',
'executionReport',
'ticketInfo',
];
if (privateLinearTopics.includes(topic)) {

@@ -139,3 +150,3 @@ return exports.wsKeySpotPrivate;

const topics = Array.isArray(wsTopics) ? wsTopics : [wsTopics];
topics.forEach(topic => this.wsStore.addTopic(this.getWsKeyForTopic(topic), topic));
topics.forEach((topic) => this.wsStore.addTopic(this.getWsKeyForTopic(topic), topic));
// attempt to send subscription topic per websocket

@@ -159,3 +170,3 @@ this.wsStore.getKeys().forEach((wsKey) => {

const topics = Array.isArray(wsTopics) ? wsTopics : [wsTopics];
topics.forEach(topic => this.wsStore.deleteTopic(this.getWsKeyForTopic(topic), topic));
topics.forEach((topic) => this.wsStore.deleteTopic(this.getWsKeyForTopic(topic), topic));
this.wsStore.getKeys().forEach((wsKey) => {

@@ -183,3 +194,6 @@ // unsubscribe request only necessary if active connection exists

if (this.isLinear()) {
return [this.connect(exports.wsKeyLinearPublic), this.connect(exports.wsKeyLinearPrivate)];
return [
this.connect(exports.wsKeyLinearPublic),
this.connect(exports.wsKeyLinearPrivate),
];
}

@@ -258,8 +272,11 @@ if (this.isSpot()) {

const { key, secret } = this.options;
if (key && secret && wsKey !== exports.wsKeyLinearPublic && wsKey !== exports.wsKeySpotPublic) {
this.logger.debug('Getting auth\'d request params', Object.assign(Object.assign({}, loggerCategory), { wsKey }));
const timeOffset = yield this.restClient.getTimeOffset();
if (key &&
secret &&
wsKey !== exports.wsKeyLinearPublic &&
wsKey !== exports.wsKeySpotPublic) {
this.logger.debug("Getting auth'd request params", Object.assign(Object.assign({}, loggerCategory), { wsKey }));
const timeOffset = yield this.restClient.fetchTimeOffset();
const params = {
api_key: this.options.key,
expires: (Date.now() + timeOffset + 5000)
expires: Date.now() + timeOffset + 5000,
};

@@ -327,3 +344,3 @@ params.signature = yield node_support_1.signMessage('GET/realtime' + params.expires, secret);

op: 'subscribe',
args: topics
args: topics,
});

@@ -341,3 +358,3 @@ this.tryWsSend(wsKey, wsMessage);

op: 'unsubscribe',
args: topics
args: topics,
});

@@ -348,3 +365,4 @@ this.tryWsSend(wsKey, wsMessage);

try {
this.logger.silly(`Sending upstream ws message: `, Object.assign(Object.assign({}, loggerCategory), { wsMessage, wsKey }));
this.logger.silly(`Sending upstream ws message: `, Object.assign(Object.assign({}, loggerCategory), { wsMessage,
wsKey }));
if (!wsKey) {

@@ -360,3 +378,4 @@ throw new Error('Cannot send message due to no known websocket for this wsKey');

catch (e) {
this.logger.error(`Failed to send WS message`, Object.assign(Object.assign({}, loggerCategory), { wsMessage, wsKey, exception: e }));
this.logger.error(`Failed to send WS message`, Object.assign(Object.assign({}, loggerCategory), { wsMessage,
wsKey, exception: e }));
}

@@ -369,6 +388,6 @@ }

const ws = new isomorphic_ws_1.default(url, undefined, agent ? { agent } : undefined);
ws.onopen = event => this.onWsOpen(event, wsKey);
ws.onmessage = event => this.onWsMessage(event, wsKey);
ws.onerror = event => this.onWsError(event, wsKey);
ws.onclose = event => this.onWsClose(event, wsKey);
ws.onopen = (event) => this.onWsOpen(event, wsKey);
ws.onmessage = (event) => this.onWsMessage(event, wsKey);
ws.onerror = (event) => this.onWsError(event, wsKey);
ws.onclose = (event) => this.onWsClose(event, wsKey);
return ws;

@@ -396,3 +415,3 @@ }

this.clearPongTimer(wsKey);
const msg = JSON.parse(event && event.data || event);
const msg = JSON.parse((event && event.data) || event);
if ('success' in msg || (msg === null || msg === void 0 ? void 0 : msg.pong)) {

@@ -405,7 +424,9 @@ this.onWsMessageResponse(msg, wsKey);

else {
this.logger.warning('Got unhandled ws message', Object.assign(Object.assign({}, loggerCategory), { message: msg, event, wsKey }));
this.logger.warning('Got unhandled ws message', Object.assign(Object.assign({}, loggerCategory), { message: msg, event,
wsKey }));
}
}
catch (e) {
this.logger.error('Failed to parse ws event message', Object.assign(Object.assign({}, loggerCategory), { error: e, event, wsKey }));
this.logger.error('Failed to parse ws event message', Object.assign(Object.assign({}, loggerCategory), { error: e, event,
wsKey }));
}

@@ -499,3 +520,3 @@ }

binary: !!binary,
}
},
}));

@@ -538,8 +559,6 @@ }

switch (depth) {
case 'full':
{
topic = 'depth';
break;
}
;
case 'full': {
topic = 'depth';
break;
}
case 'merge': {

@@ -572,3 +591,2 @@ topic = 'mergedDepth';

exports.WebsocketClient = WebsocketClient;
;
//# sourceMappingURL=websocket-client.js.map
{
"name": "bybit-api",
"version": "2.1.10",
"version": "2.2.0-beta.1",
"description": "Node.js connector for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc