Merge pull request #129 from tiagosiebler/types

reduce ping timeouts for ws, improve request types, improve response types
This commit is contained in:
Tiago
2021-12-31 00:46:57 +00:00
committed by GitHub
11 changed files with 179 additions and 212 deletions

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "2.0.7", "version": "2.1.6",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "2.1.6", "version": "2.1.7",
"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",

View File

@@ -4,3 +4,5 @@ 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/spot';

View File

@@ -2,6 +2,7 @@ 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 { SymbolFromLimitParam, SymbolIntervalFromLimitParam, SymbolParam } from './types/shared';
export class InverseClient extends SharedEndpoints { export class InverseClient extends SharedEndpoints {
protected requestWrapper: RequestWrapper; protected requestWrapper: RequestWrapper;
@@ -40,67 +41,37 @@ export class InverseClient extends SharedEndpoints {
* *
*/ */
getKline(params: { getKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/kline/list', params); return this.requestWrapper.get('v2/public/kline/list', params);
} }
/** /**
* @deprecated use getTickers() instead * @deprecated use getTickers() instead
*/ */
getLatestInformation(params?: { getLatestInformation(params?: Partial<SymbolParam>): GenericAPIResponse {
symbol?: string;
}): GenericAPIResponse {
return this.getTickers(params); return this.getTickers(params);
} }
/** /**
* @deprecated use getTrades() instead * @deprecated use getTrades() instead
*/ */
getPublicTradingRecords(params: { getPublicTradingRecords(params: SymbolFromLimitParam): GenericAPIResponse {
symbol: string;
from?: number;
limit?: number;
}): GenericAPIResponse {
return this.getTrades(params); return this.getTrades(params);
} }
getTrades(params: { getTrades(params: SymbolFromLimitParam): GenericAPIResponse {
symbol: string;
from?: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/trading-records', params); return this.requestWrapper.get('v2/public/trading-records', params);
} }
getMarkPriceKline(params: { getMarkPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/mark-price-kline', params); return this.requestWrapper.get('v2/public/mark-price-kline', params);
} }
getIndexPriceKline(params: { getIndexPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/index-price-kline', params); return this.requestWrapper.get('v2/public/index-price-kline', params);
} }
getPremiumIndexKline(params: { getPremiumIndexKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/premium-index-kline', params); return this.requestWrapper.get('v2/public/premium-index-kline', params);
} }
@@ -150,9 +121,7 @@ export class InverseClient extends SharedEndpoints {
return this.requestWrapper.post('v2/private/order/cancel', params); return this.requestWrapper.post('v2/private/order/cancel', params);
} }
cancelAllActiveOrders(params: { cancelAllActiveOrders(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.post('v2/private/order/cancelAll', params); return this.requestWrapper.post('v2/private/order/cancelAll', params);
} }
@@ -212,9 +181,7 @@ export class InverseClient extends SharedEndpoints {
return this.requestWrapper.post('v2/private/stop-order/cancel', params); return this.requestWrapper.post('v2/private/stop-order/cancel', params);
} }
cancelAllConditionalOrders(params: { cancelAllConditionalOrders(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.post('v2/private/stop-order/cancelAll', params); return this.requestWrapper.post('v2/private/stop-order/cancelAll', params);
} }
@@ -248,9 +215,7 @@ export class InverseClient extends SharedEndpoints {
return this.requestWrapper.get('user/leverage'); return this.requestWrapper.get('user/leverage');
} }
getPosition(params?: { getPosition(params?: Partial<SymbolParam>): GenericAPIResponse {
symbol?: string;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/private/position/list', params); return this.requestWrapper.get('v2/private/position/list', params);
} }
@@ -359,21 +324,15 @@ export class InverseClient extends SharedEndpoints {
* Funding * Funding
*/ */
getLastFundingRate(params: { getLastFundingRate(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/funding/prev-funding-rate', params); return this.requestWrapper.get('v2/public/funding/prev-funding-rate', params);
} }
getMyLastFundingFee(params: { getMyLastFundingFee(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/private/funding/prev-funding', params); return this.requestWrapper.get('v2/private/funding/prev-funding', params);
} }
getPredictedFunding(params: { getPredictedFunding(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/private/funding/predicted-funding', params); return this.requestWrapper.get('v2/private/funding/predicted-funding', params);
} }
@@ -381,12 +340,10 @@ export class InverseClient extends SharedEndpoints {
* LCP Info * LCP Info
*/ */
getLcpInfo(params: { getLcpInfo(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/private/account/lcp', params); return this.requestWrapper.get('v2/private/account/lcp', params);
} }
//API Key Info //API Key Info
getAPIKeyInfo(): GenericAPIResponse { getAPIKeyInfo(): GenericAPIResponse {
return this.requestWrapper.get('v2/private/account/api-key'); return this.requestWrapper.get('v2/private/account/api-key');

View File

@@ -2,6 +2,7 @@ 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 { SymbolFromLimitParam, SymbolIntervalFromLimitParam, SymbolParam } from './types/shared';
export class InverseFuturesClient extends SharedEndpoints { export class InverseFuturesClient extends SharedEndpoints {
protected requestWrapper: RequestWrapper; protected requestWrapper: RequestWrapper;
@@ -40,50 +41,26 @@ export class InverseFuturesClient extends SharedEndpoints {
* Note: These are currently the same as the inverse client * Note: These are currently the same as the inverse client
*/ */
getKline(params: { getKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/kline/list', params); return this.requestWrapper.get('v2/public/kline/list', params);
} }
/** /**
* Public trading records * Public trading records
*/ */
getTrades(params: { getTrades(params: SymbolFromLimitParam): GenericAPIResponse {
symbol: string;
from?: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/trading-records', params); return this.requestWrapper.get('v2/public/trading-records', params);
} }
getMarkPriceKline(params: { getMarkPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/mark-price-kline', params); return this.requestWrapper.get('v2/public/mark-price-kline', params);
} }
getIndexPriceKline(params: { getIndexPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/index-price-kline', params); return this.requestWrapper.get('v2/public/index-price-kline', params);
} }
getPremiumIndexKline(params: { getPremiumIndexKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/premium-index-kline', params); return this.requestWrapper.get('v2/public/premium-index-kline', params);
} }
@@ -131,9 +108,7 @@ export class InverseFuturesClient extends SharedEndpoints {
return this.requestWrapper.post('futures/private/order/cancel', params); return this.requestWrapper.post('futures/private/order/cancel', params);
} }
cancelAllActiveOrders(params: { cancelAllActiveOrders(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.post('futures/private/order/cancelAll', params); return this.requestWrapper.post('futures/private/order/cancelAll', params);
} }
@@ -193,9 +168,7 @@ export class InverseFuturesClient extends SharedEndpoints {
return this.requestWrapper.post('futures/private/stop-order/cancel', params); return this.requestWrapper.post('futures/private/stop-order/cancel', params);
} }
cancelAllConditionalOrders(params: { cancelAllConditionalOrders(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.post('futures/private/stop-order/cancelAll', params); return this.requestWrapper.post('futures/private/stop-order/cancelAll', params);
} }
@@ -226,9 +199,7 @@ export class InverseFuturesClient extends SharedEndpoints {
/** /**
* Get position list * Get position list
*/ */
getPosition(params?: { getPosition(params?: Partial<SymbolParam>): GenericAPIResponse {
symbol?: string;
}): GenericAPIResponse {
return this.requestWrapper.get('futures/private/position/list', params); return this.requestWrapper.get('futures/private/position/list', params);
} }
@@ -325,21 +296,15 @@ export class InverseFuturesClient extends SharedEndpoints {
* Funding * Funding
*/ */
getLastFundingRate(params: { getLastFundingRate(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/funding/prev-funding-rate', params); return this.requestWrapper.get('v2/public/funding/prev-funding-rate', params);
} }
getMyLastFundingFee(params: { getMyLastFundingFee(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/private/funding/prev-funding', params); return this.requestWrapper.get('v2/private/funding/prev-funding', params);
} }
getPredictedFunding(params: { getPredictedFunding(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/private/funding/predicted-funding', params); return this.requestWrapper.get('v2/private/funding/predicted-funding', params);
} }
@@ -347,9 +312,7 @@ export class InverseFuturesClient extends SharedEndpoints {
* LCP Info * LCP Info
*/ */
getLcpInfo(params: { getLcpInfo(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/private/account/lcp', params); return this.requestWrapper.get('v2/private/account/lcp', params);
} }
}; };

View File

@@ -2,6 +2,7 @@ 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 '.';
export class LinearClient extends SharedEndpoints { export class LinearClient extends SharedEndpoints {
protected requestWrapper: RequestWrapper; protected requestWrapper: RequestWrapper;
@@ -40,52 +41,27 @@ export class LinearClient extends SharedEndpoints {
* *
*/ */
getKline(params: { getKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('public/linear/kline', params); return this.requestWrapper.get('public/linear/kline', params);
} }
getTrades(params: { getTrades(params: SymbolLimitParam): GenericAPIResponse {
symbol: string;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('public/linear/recent-trading-records', params); return this.requestWrapper.get('public/linear/recent-trading-records', params);
} }
getLastFundingRate(params: { getLastFundingRate(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): 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: { getMarkPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('public/linear/mark-price-kline', params); return this.requestWrapper.get('public/linear/mark-price-kline', params);
} }
getIndexPriceKline(params: { getIndexPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('public/linear/index-price-kline', params); return this.requestWrapper.get('public/linear/index-price-kline', params);
} }
getPremiumIndexKline(params: { getPremiumIndexKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('public/linear/premium-index-kline', params); return this.requestWrapper.get('public/linear/premium-index-kline', params);
} }
@@ -133,9 +109,7 @@ export class LinearClient extends SharedEndpoints {
return this.requestWrapper.post('private/linear/order/cancel', params); return this.requestWrapper.post('private/linear/order/cancel', params);
} }
cancelAllActiveOrders(params: { cancelAllActiveOrders(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.post('private/linear/order/cancel-all', params); return this.requestWrapper.post('private/linear/order/cancel-all', params);
} }
@@ -206,9 +180,7 @@ export class LinearClient extends SharedEndpoints {
return this.requestWrapper.post('private/linear/stop-order/cancel', params); return this.requestWrapper.post('private/linear/stop-order/cancel', params);
} }
cancelAllConditionalOrders(params: { cancelAllConditionalOrders(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.post('private/linear/stop-order/cancel-all', params); return this.requestWrapper.post('private/linear/stop-order/cancel-all', params);
} }
@@ -239,9 +211,7 @@ export class LinearClient extends SharedEndpoints {
* Position * Position
*/ */
getPosition(params?: { getPosition(params?: Partial<SymbolParam>): GenericAPIResponse {
symbol?: string;
}): GenericAPIResponse {
return this.requestWrapper.get('private/linear/position/list', params); return this.requestWrapper.get('private/linear/position/list', params);
} }
@@ -325,9 +295,7 @@ export class LinearClient extends SharedEndpoints {
* Risk Limit * Risk Limit
*/ */
getRiskLimitList(params: { getRiskLimitList(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.get('public/linear/risk-limit', params); return this.requestWrapper.get('public/linear/risk-limit', params);
} }
@@ -343,15 +311,11 @@ export class LinearClient extends SharedEndpoints {
* Funding * Funding
*/ */
getPredictedFundingFee(params: { getPredictedFundingFee(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.get('private/linear/funding/predicted-funding', params); return this.requestWrapper.get('private/linear/funding/predicted-funding', params);
} }
getLastFundingFee(params: { getLastFundingFee(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.get('private/linear/funding/prev-funding', params); return this.requestWrapper.get('private/linear/funding/prev-funding', params);
} }
} }

View File

@@ -1,3 +1,14 @@
import {
APIResponse,
AssetExchangeRecordsReq,
CoinParam,
SymbolInfo,
SymbolLimitParam,
SymbolParam,
SymbolPeriodLimitParam,
WalletFundRecordsReq,
WithdrawRecordsReq,
} from './types/shared';
import { GenericAPIResponse } from './util/requestUtils'; import { GenericAPIResponse } from './util/requestUtils';
import RequestWrapper from './util/requestWrapper'; import RequestWrapper from './util/requestWrapper';
@@ -11,22 +22,18 @@ export default class SharedEndpoints {
* *
*/ */
getOrderBook(params: { getOrderBook(params: SymbolParam): GenericAPIResponse {
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/orderBook/L2', params); return this.requestWrapper.get('v2/public/orderBook/L2', params);
} }
/** /**
* Get latest information for symbol * Get latest information for symbol
*/ */
getTickers(params?: { getTickers(params?: Partial<SymbolParam>): GenericAPIResponse {
symbol?: string;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/tickers', params); return this.requestWrapper.get('v2/public/tickers', params);
} }
getSymbols(): GenericAPIResponse { getSymbols(): Promise<APIResponse<SymbolInfo[]>> {
return this.requestWrapper.get('v2/public/symbols'); return this.requestWrapper.get('v2/public/symbols');
} }
@@ -36,26 +43,15 @@ export default class SharedEndpoints {
* *
*/ */
getOpenInterest(params: { getOpenInterest(params: SymbolPeriodLimitParam): GenericAPIResponse {
symbol: string;
period: string;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/open-interest', params); return this.requestWrapper.get('v2/public/open-interest', params);
} }
getLatestBigDeal(params: { getLatestBigDeal(params: SymbolLimitParam): GenericAPIResponse {
symbol: string;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/big-deal', params); return this.requestWrapper.get('v2/public/big-deal', params);
} }
getLongShortRatio(params: { getLongShortRatio(params: SymbolPeriodLimitParam): GenericAPIResponse {
symbol: string;
period: string;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/public/account-ratio', params); return this.requestWrapper.get('v2/public/account-ratio', params);
} }
@@ -75,40 +71,19 @@ export default class SharedEndpoints {
* *
*/ */
getWalletBalance(params: { getWalletBalance(params?: Partial<CoinParam>): GenericAPIResponse {
coin?: string;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/private/wallet/balance', params) return this.requestWrapper.get('v2/private/wallet/balance', params)
} }
getWalletFundRecords(params?: { getWalletFundRecords(params?: WalletFundRecordsReq): GenericAPIResponse {
start_date?: string;
end_date?: string;
currency?: string;
coin?: string;
wallet_fund_type?: string;
page?: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/private/wallet/fund/records', params); return this.requestWrapper.get('v2/private/wallet/fund/records', params);
} }
getWithdrawRecords(params: { getWithdrawRecords(params: WithdrawRecordsReq): GenericAPIResponse {
start_date?: string;
end_date?: string;
coin?: string;
status?: string;
page?: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/private/wallet/withdraw/list', params); return this.requestWrapper.get('v2/private/wallet/withdraw/list', params);
} }
getAssetExchangeRecords(params?: { getAssetExchangeRecords(params?: AssetExchangeRecordsReq): GenericAPIResponse {
limit?: number;
from?: number;
direction?: string;
}): GenericAPIResponse {
return this.requestWrapper.get('v2/private/exchange-order/list', params); return this.requestWrapper.get('v2/private/exchange-order/list', params);
} }

View File

@@ -11,3 +11,108 @@ export type KlineInterval = '1m'
| '1d' | '1d'
| '1w' | '1w'
| '1M'; | '1M';
export type numberInString = string;
export interface APIResponse<T> {
ret_code: number;
ret_msg: "OK" | string;
ext_code: string;
ext_info: string;
result: T;
}
/**
* Request Parameter Types
*/
export interface SymbolParam {
symbol: string;
}
export interface SymbolLimitParam {
symbol: string;
limit?: number;
}
export interface SymbolPeriodLimitParam {
symbol: string;
period: string;
limit?: number;
}
export interface SymbolFromLimitParam {
symbol: string;
from?: number;
limit?: number;
}
export interface SymbolIntervalFromLimitParam {
symbol: string;
interval: string;
from: number;
limit?: number;
}
export interface CoinParam {
coin: string;
}
export interface WalletFundRecordsReq {
start_date?: string;
end_date?: string;
currency?: string;
coin?: string;
wallet_fund_type?: string;
page?: number;
limit?: number;
}
export interface WithdrawRecordsReq {
start_date?: string;
end_date?: string;
coin?: string;
status?: string;
page?: number;
limit?: number;
}
export interface AssetExchangeRecordsReq {
limit?: number;
from?: number;
direction?: string;
}
/**
* Response types
*/
export interface LeverageFilter {
min_leverage: numberInString;
max_leveage: numberInString;
leverage_step: numberInString;
}
export interface PriceFilter {
min_price: numberInString;
max_price: numberInString;
tick_size: numberInString;
}
export interface LotSizeFilter {
max_trading_qty: number;
min_trading_qty: number;
qty_step: number;
}
export interface SymbolInfo {
name: string;
alias: string;
status: 'Trading' | string;
base_currency: string;
quote_currency: string;
price_scale: number;
taker_fee: numberInString;
maker_fee: numberInString;
leverage_filter: LeverageFilter;
price_filter: PriceFilter;
lot_size_filter: LotSizeFilter;
}

View File

@@ -56,18 +56,18 @@ export default class RequestUtil {
this.secret = secret; this.secret = secret;
} }
get(endpoint: string, params?: any): GenericAPIResponse { get<T>(endpoint: string, params?: any): Promise<T> {
return this._call('GET', endpoint, params); return this._call('GET', endpoint, params);
} }
post(endpoint: string, params?: any): GenericAPIResponse { post<T>(endpoint: string, params?: any): Promise<T> {
return this._call('POST', endpoint, params); return this._call('POST', endpoint, params);
} }
/** /**
* @private Make a HTTP request to a specific endpoint. Private endpoints are automatically signed. * @private Make a HTTP request to a specific endpoint. Private endpoints are automatically signed.
*/ */
async _call(method: Method, endpoint: string, params?: any): GenericAPIResponse { async _call<T>(method: Method, endpoint: string, params?: any): Promise<T> {
if (!isPublicEndpoint(endpoint)) { if (!isPublicEndpoint(endpoint)) {
if (!this.key || !this.secret) { if (!this.key || !this.secret) {
throw new Error('Private endpoints require api and private keys set'); throw new Error('Private endpoints require api and private keys set');
@@ -183,7 +183,7 @@ export default class RequestUtil {
*/ */
async getTimeOffset(): Promise<number> { async getTimeOffset(): Promise<number> {
const start = Date.now(); const start = Date.now();
const result = await this.get('v2/public/time'); const result = await this.get<any>('v2/public/time');
const end = Date.now(); const end = Date.now();
return Math.ceil((result.time_now * 1000) - end + ((end - start) / 2)); return Math.ceil((result.time_now * 1000) - end + ((end - start) / 2));

View File

@@ -544,6 +544,9 @@ export class WebsocketClient extends EventEmitter {
private onWsMessage(event, wsKey: WsKey) { private onWsMessage(event, wsKey: WsKey) {
try { try {
// any message can clear the pong timer - wouldn't get a message if the ws dropped
this.clearPongTimer(wsKey);
const msg = JSON.parse(event && event.data || event); const msg = JSON.parse(event && event.data || event);
if ('success' in msg || msg?.pong) { if ('success' in msg || msg?.pong) {
this.onWsMessageResponse(msg, wsKey); this.onWsMessageResponse(msg, wsKey);
@@ -579,7 +582,6 @@ export class WebsocketClient extends EventEmitter {
private onWsMessageResponse(response: any, wsKey: WsKey) { private onWsMessageResponse(response: any, wsKey: WsKey) {
if (isWsPong(response)) { if (isWsPong(response)) {
this.logger.silly('Received pong', { ...loggerCategory, wsKey }); this.logger.silly('Received pong', { ...loggerCategory, wsKey });
this.clearPongTimer(wsKey);
} else { } else {
this.emit('response', response); this.emit('response', response);
} }

View File

@@ -14,7 +14,6 @@
"sourceMap": true, "sourceMap": true,
"esModuleInterop": true, "esModuleInterop": true,
"lib": ["es2017","dom"], "lib": ["es2017","dom"],
"baseUrl": ".",
"outDir": "lib" "outDir": "lib"
}, },
"include": ["src/**/*"], "include": ["src/**/*"],