UNPKG

tardis-dev

Version:

Convenient access to tick-level historical and real-time cryptocurrency market data via Node.js

61 lines 1.98 kB
import { batchObjects } from "../handy.js"; import { RealTimeFeedBase } from "./realtimefeed.js"; class BitgetRealTimeFeedBase extends RealTimeFeedBase { throttleSubscribeMS = 100; wssURL = 'wss://ws.bitget.com/v3/ws/public'; mapToSubscribeMessages(filters) { const argsInputs = filters.flatMap((filter) => { if (filter.channel === 'liquidation') { return this.getLiquidationInstTypes().map((instType) => { return { instType, topic: filter.channel }; }); } if (!filter.symbols || filter.symbols.length === 0) { throw new Error('BitgetRealTimeFeed requires explicitly specified symbols when subscribing to live feed'); } return filter.symbols.map((symbol) => { return { instType: this.getInstType(symbol), topic: filter.channel, symbol }; }); }); const payload = [...batchObjects(argsInputs, 5)].map((args) => { return { op: 'subscribe', args }; }); return payload; } messageIsError(message) { return message.event === 'error'; } getLiquidationInstTypes() { return []; } } export class BitgetRealTimeFeed extends BitgetRealTimeFeedBase { getInstType(_) { return 'spot'; } } export class BitgetFuturesRealTimeFeed extends BitgetRealTimeFeedBase { getInstType(symbol) { if (symbol.endsWith('USDT')) { return 'usdt-futures'; } if (symbol.endsWith('PERP')) { return 'usdc-futures'; } return 'coin-futures'; } getLiquidationInstTypes() { return ['usdt-futures', 'usdc-futures', 'coin-futures']; } } //# sourceMappingURL=bitget.js.map