tardis-dev
Advanced tools
Comparing version 13.2.0 to 13.4.0
@@ -15,5 +15,8 @@ import { BookChange, BookTicker, DerivativeTicker, Exchange, Liquidation, OptionSummary, Trade } from '../types'; | ||
private readonly _exchange; | ||
private readonly _usePublicBooksChannel; | ||
constructor(_exchange: Exchange, _usePublicBooksChannel: boolean); | ||
private _channelName; | ||
constructor(_exchange: Exchange, usePublicBooksChannel: boolean); | ||
canHandle(message: any): boolean; | ||
private _hasCredentials; | ||
private _hasVip5Access; | ||
private _getBooksChannelName; | ||
getFilters(symbols?: string[]): { | ||
@@ -20,0 +23,0 @@ channel: any; |
@@ -50,5 +50,7 @@ "use strict"; | ||
class OkexV5BookChangeMapper { | ||
constructor(_exchange, _usePublicBooksChannel) { | ||
constructor(_exchange, usePublicBooksChannel) { | ||
this._exchange = _exchange; | ||
this._usePublicBooksChannel = _usePublicBooksChannel; | ||
this._hasCredentials = process.env.OKX_API_KEY !== undefined; | ||
this._hasVip5Access = process.env.OKX_API_VIP_5 !== undefined; | ||
this._channelName = this._getBooksChannelName(usePublicBooksChannel); | ||
} | ||
@@ -59,20 +61,22 @@ canHandle(message) { | ||
} | ||
if (this._usePublicBooksChannel) { | ||
return message.arg.channel === 'books'; | ||
return message.arg.channel === this._channelName; | ||
} | ||
_getBooksChannelName(usePublicBooksChannel) { | ||
if (usePublicBooksChannel === false) { | ||
// historical data always uses books-l2-tbt | ||
return 'books-l2-tbt'; | ||
} | ||
return message.arg.channel === 'books-l2-tbt'; | ||
if (this._hasCredentials && this._hasVip5Access) { | ||
return 'books-l2-tbt'; | ||
} | ||
if (this._hasCredentials) { | ||
return 'books50-l2-tbt'; | ||
} | ||
return 'books'; | ||
} | ||
getFilters(symbols) { | ||
symbols = (0, handy_1.upperCaseSymbols)(symbols); | ||
if (this._usePublicBooksChannel) { | ||
return [ | ||
{ | ||
channel: `books`, | ||
symbols | ||
} | ||
]; | ||
} | ||
return [ | ||
{ | ||
channel: `books-l2-tbt`, | ||
channel: this._channelName, | ||
symbols | ||
@@ -79,0 +83,0 @@ } |
@@ -5,7 +5,7 @@ import { Filter, FilterForExchange } from '../types'; | ||
protected wssURL: string; | ||
private _hasCredentials; | ||
protected channelsWithIntervals: FilterForExchange['deribit']['channel'][]; | ||
protected mapToSubscribeMessages(filters: Filter<string>[]): any[]; | ||
protected messageIsError(message: any): boolean; | ||
private hasCredentials; | ||
protected onConnected(): void; | ||
protected onConnected(): Promise<void>; | ||
protected messageIsHeartbeat(msg: any): boolean; | ||
@@ -12,0 +12,0 @@ protected onMessage(msg: any): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DeribitRealTimeDataFeed = void 0; | ||
const handy_1 = require("../handy"); | ||
const realtimefeed_1 = require("./realtimefeed"); | ||
@@ -9,6 +10,7 @@ class DeribitRealTimeDataFeed extends realtimefeed_1.RealTimeFeedBase { | ||
this.wssURL = 'wss://www.deribit.com/ws/api/v2'; | ||
this._hasCredentials = process.env.DERIBIT_API_CLIENT_ID !== undefined && process.env.DERIBIT_API_CLIENT_SECRET !== undefined; | ||
this.channelsWithIntervals = ['book', 'perpetual', 'trades', 'ticker']; | ||
} | ||
mapToSubscribeMessages(filters) { | ||
const hasCredentials = this.hasCredentials(); | ||
const hasCredentials = this._hasCredentials; | ||
const channels = filters | ||
@@ -39,6 +41,3 @@ .map((filter) => { | ||
} | ||
hasCredentials() { | ||
return process.env.DERIBIT_API_CLIENT_ID !== undefined && process.env.DERIBIT_API_CLIENT_SECRET !== undefined; | ||
} | ||
onConnected() { | ||
async onConnected() { | ||
// set heartbeat so deribit won't close connection prematurely | ||
@@ -54,3 +53,3 @@ // https://docs.deribit.com/v2/#public-set_heartbeat | ||
}); | ||
if (this.hasCredentials()) { | ||
if (this._hasCredentials) { | ||
this.send({ | ||
@@ -66,2 +65,3 @@ jsonrpc: '2.0', | ||
}); | ||
await (0, handy_1.wait)(10); | ||
} | ||
@@ -68,0 +68,0 @@ } |
@@ -5,2 +5,5 @@ import { Filter } from '../types'; | ||
protected wssURL: string; | ||
private _hasCredentials; | ||
private secondsSinceEpoch; | ||
protected onConnected(): Promise<void>; | ||
protected mapToSubscribeMessages(filters: Filter<string>[]): any[]; | ||
@@ -7,0 +10,0 @@ protected messageIsError(message: any): boolean; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OkexOptionsRealTimeFeed = exports.OKCoinRealTimeFeed = exports.OkexRealTimeFeed = void 0; | ||
const zlib_1 = require("zlib"); | ||
const crypto_1 = __importDefault(require("crypto")); | ||
const handy_1 = require("../handy"); | ||
const realtimefeed_1 = require("./realtimefeed"); | ||
@@ -10,3 +15,25 @@ class OkexRealTimeFeed extends realtimefeed_1.RealTimeFeedBase { | ||
this.wssURL = 'wss://ws.okx.com:8443/ws/v5/public'; | ||
this._hasCredentials = process.env.OKX_API_KEY !== undefined; | ||
} | ||
secondsSinceEpoch() { | ||
return Math.floor(Date.now() / 1000); | ||
} | ||
async onConnected() { | ||
if (this._hasCredentials) { | ||
const timestamp = this.secondsSinceEpoch().toString(); | ||
const sign = crypto_1.default.createHmac('sha256', process.env.OKX_API_SECRET_KEY).update(`${timestamp}GET/users/self/verify`).digest('base64'); | ||
this.send({ | ||
op: 'login', | ||
args: [ | ||
{ | ||
apiKey: process.env.OKX_API_KEY, | ||
passphrase: process.env.OKX_API_PASSPHRASE, | ||
timestamp, | ||
sign | ||
} | ||
] | ||
}); | ||
await (0, handy_1.wait)(50); | ||
} | ||
} | ||
mapToSubscribeMessages(filters) { | ||
@@ -13,0 +40,0 @@ const args = filters |
@@ -31,3 +31,3 @@ /// <reference types="node" /> | ||
protected onMessage(_msg: any): void; | ||
protected onConnected(): void; | ||
protected onConnected(): Promise<void>; | ||
protected decompress?: (msg: any) => Buffer; | ||
@@ -34,0 +34,0 @@ private _monitorConnectionIfStale; |
@@ -33,3 +33,3 @@ "use strict"; | ||
}, new Set()).size; | ||
this.onConnected(); | ||
await this.onConnected(); | ||
for (const message of subscribeMessages) { | ||
@@ -180,3 +180,3 @@ this.send(message); | ||
onMessage(_msg) { } | ||
onConnected() { } | ||
async onConnected() { } | ||
_monitorConnectionIfStale() { | ||
@@ -183,0 +183,0 @@ if (this._timeoutIntervalMS === undefined || this._timeoutIntervalMS === 0) { |
{ | ||
"name": "tardis-dev", | ||
"version": "13.2.0", | ||
"version": "13.4.0", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=12" |
@@ -54,4 +54,8 @@ import { asNumberIfValid, upperCaseSymbols } from '../handy' | ||
export class OkexV5BookChangeMapper implements Mapper<OKEX_EXCHANGES, BookChange> { | ||
constructor(private readonly _exchange: Exchange, private readonly _usePublicBooksChannel: boolean) {} | ||
private _channelName: string | ||
constructor(private readonly _exchange: Exchange, usePublicBooksChannel: boolean) { | ||
this._channelName = this._getBooksChannelName(usePublicBooksChannel) | ||
} | ||
canHandle(message: any) { | ||
@@ -62,6 +66,23 @@ if (message.event !== undefined || message.arg === undefined) { | ||
if (this._usePublicBooksChannel) { | ||
return message.arg.channel === 'books' | ||
return message.arg.channel === this._channelName | ||
} | ||
private _hasCredentials = process.env.OKX_API_KEY !== undefined | ||
private _hasVip5Access = process.env.OKX_API_VIP_5 !== undefined | ||
private _getBooksChannelName(usePublicBooksChannel: boolean) { | ||
if (usePublicBooksChannel === false) { | ||
// historical data always uses books-l2-tbt | ||
return 'books-l2-tbt' | ||
} | ||
return message.arg.channel === 'books-l2-tbt' | ||
if (this._hasCredentials && this._hasVip5Access) { | ||
return 'books-l2-tbt' | ||
} | ||
if (this._hasCredentials) { | ||
return 'books50-l2-tbt' | ||
} | ||
return 'books' | ||
} | ||
@@ -72,14 +93,5 @@ | ||
if (this._usePublicBooksChannel) { | ||
return [ | ||
{ | ||
channel: `books` as any, | ||
symbols | ||
} | ||
] | ||
} | ||
return [ | ||
{ | ||
channel: `books-l2-tbt` as const, | ||
channel: this._channelName as any, | ||
symbols | ||
@@ -86,0 +98,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import { wait } from '../handy' | ||
import { Filter, FilterForExchange } from '../types' | ||
@@ -6,2 +7,3 @@ import { RealTimeFeedBase } from './realtimefeed' | ||
protected wssURL = 'wss://www.deribit.com/ws/api/v2' | ||
private _hasCredentials = process.env.DERIBIT_API_CLIENT_ID !== undefined && process.env.DERIBIT_API_CLIENT_SECRET !== undefined | ||
@@ -11,3 +13,4 @@ protected channelsWithIntervals: FilterForExchange['deribit']['channel'][] = ['book', 'perpetual', 'trades', 'ticker'] | ||
protected mapToSubscribeMessages(filters: Filter<string>[]): any[] { | ||
const hasCredentials = this.hasCredentials() | ||
const hasCredentials = this._hasCredentials | ||
const channels = filters | ||
@@ -43,7 +46,3 @@ .map((filter) => { | ||
private hasCredentials() { | ||
return process.env.DERIBIT_API_CLIENT_ID !== undefined && process.env.DERIBIT_API_CLIENT_SECRET !== undefined | ||
} | ||
protected onConnected() { | ||
protected async onConnected() { | ||
// set heartbeat so deribit won't close connection prematurely | ||
@@ -61,3 +60,3 @@ // https://docs.deribit.com/v2/#public-set_heartbeat | ||
if (this.hasCredentials()) { | ||
if (this._hasCredentials) { | ||
this.send({ | ||
@@ -73,2 +72,4 @@ jsonrpc: '2.0', | ||
}) | ||
await wait(10) | ||
} | ||
@@ -75,0 +76,0 @@ } |
import { inflateRawSync } from 'zlib' | ||
import crypto from 'crypto' | ||
import { wait } from '../handy' | ||
import { Filter } from '../types' | ||
@@ -8,2 +10,29 @@ import { RealTimeFeedBase } from './realtimefeed' | ||
private _hasCredentials = process.env.OKX_API_KEY !== undefined | ||
private secondsSinceEpoch() { | ||
return Math.floor(Date.now() / 1000) | ||
} | ||
protected async onConnected() { | ||
if (this._hasCredentials) { | ||
const timestamp = this.secondsSinceEpoch().toString() | ||
const sign = crypto.createHmac('sha256', process.env.OKX_API_SECRET_KEY!).update(`${timestamp}GET/users/self/verify`).digest('base64') | ||
this.send({ | ||
op: 'login', | ||
args: [ | ||
{ | ||
apiKey: process.env.OKX_API_KEY, | ||
passphrase: process.env.OKX_API_PASSPHRASE, | ||
timestamp, | ||
sign | ||
} | ||
] | ||
}) | ||
await wait(50) | ||
} | ||
} | ||
protected mapToSubscribeMessages(filters: Filter<string>[]): any[] { | ||
@@ -10,0 +39,0 @@ const args = filters |
@@ -207,3 +207,3 @@ import dbg from 'debug' | ||
protected onConnected() {} | ||
protected async onConnected() {} | ||
@@ -258,3 +258,3 @@ protected decompress?: (msg: any) => Buffer | ||
this.onConnected() | ||
await this.onConnected() | ||
@@ -261,0 +261,0 @@ for (const message of subscribeMessages) { |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1404619
25743
20