tardis-dev
Version:
Convenient access to tick-level historical and real-time cryptocurrency market data via Node.js
65 lines • 2.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WooxRealTimeFeed = void 0;
const handy_1 = require("../handy");
const realtimefeed_1 = require("./realtimefeed");
class WooxRealTimeFeed extends realtimefeed_1.RealTimeFeedBase {
constructor() {
super(...arguments);
this.wssURL = 'wss://wss.woo.org/ws/stream/OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY';
}
mapToSubscribeMessages(filters) {
return filters
.filter((filter) => filter.channel !== 'orderbook')
.map((filter) => {
if (!filter.symbols || filter.symbols.length === 0) {
throw new Error('WooxRealTimeFeed requires explicitly specified symbols when subscribing to live feed');
}
return filter.symbols.map((symbol) => {
return {
id: `${symbol}@${filter.channel}`,
topic: `${symbol}@${filter.channel}`,
event: 'subscribe'
};
});
})
.flatMap((f) => f);
}
async provideManualSnapshots(filters, shouldCancel) {
const orderbookFilter = filters.find((f) => f.channel === 'orderbook');
if (!orderbookFilter) {
return;
}
await (0, handy_1.wait)(200);
for (let symbol of orderbookFilter.symbols) {
if (shouldCancel()) {
return;
}
this.send({
id: `${symbol}@orderbook`,
event: 'request',
params: {
type: 'orderbook',
symbol
}
});
await (0, handy_1.wait)(1);
}
this.debug('sent orderbook requests for: %s', orderbookFilter.symbols);
}
messageIsError(message) {
return message.success === false || message.errorMsg !== undefined;
}
messageIsHeartbeat(message) {
return message.event === 'ping';
}
onMessage(msg) {
if (msg.event === 'ping') {
this.send({
event: 'ping'
});
}
}
}
exports.WooxRealTimeFeed = WooxRealTimeFeed;
//# sourceMappingURL=woox.js.map