UNPKG

tardis-dev

Version:

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

58 lines 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BitstampRealTimeFeed = void 0; const handy_1 = require("../handy"); const realtimefeed_1 = require("./realtimefeed"); class BitstampRealTimeFeed extends realtimefeed_1.RealTimeFeedBase { wssURL = 'wss://ws.bitstamp.net'; httpURL = 'https://www.bitstamp.net/api/v2'; mapToSubscribeMessages(filters) { return filters .map((filter) => { if (!filter.symbols || filter.symbols.length === 0) { throw new Error('BitstampRealTimeFeed requires explicitly specified symbols when subscribing to live feed'); } return filter.symbols.map((symbol) => { return { event: 'bts:subscribe', data: { channel: `${filter.channel}_${symbol}` } }; }); }) .flatMap((c) => c); } messageIsError(message) { if (message.channel === undefined) { return true; } if (message.event === 'bts:request_reconnect') { return true; } return false; } async provideManualSnapshots(filters, shouldCancel) { const orderBookFilter = filters.find((f) => f.channel === 'diff_order_book'); if (!orderBookFilter) { return; } this.debug('requesting manual snapshots for: %s', orderBookFilter.symbols); for (let symbol of orderBookFilter.symbols) { if (shouldCancel()) { return; } const depthSnapshotResponse = await handy_1.httpClient.get(`${this.httpURL}/order_book/${symbol}?group=1`).json(); const snapshot = { data: depthSnapshotResponse, event: 'snapshot', channel: `diff_order_book_${symbol}`, generated: true }; this.manualSnapshotsBuffer.push(snapshot); } this.debug('requested manual snapshots successfully for: %s ', orderBookFilter.symbols); } } exports.BitstampRealTimeFeed = BitstampRealTimeFeed; //# sourceMappingURL=bitstamp.js.map