tardis-dev
Version:
Convenient access to tick-level historical and real-time cryptocurrency market data via Node.js
50 lines • 1.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CryptoComRealTimeFeed = void 0;
const realtimefeed_1 = require("./realtimefeed");
class CryptoComRealTimeFeed extends realtimefeed_1.RealTimeFeedBase {
constructor() {
super(...arguments);
this.wssURL = 'wss://stream.crypto.com/exchange/v1/market';
}
mapToSubscribeMessages(filters) {
const channels = filters
.map((filter) => {
if (!filter.symbols || filter.symbols.length === 0) {
throw new Error('CryptoComRealTimeFeed requires explicitly specified symbols when subscribing to live feed');
}
return filter.symbols.map((symbol) => {
const suffix = filter.channel === 'book' ? '.50' : '';
return `${filter.channel}.${symbol}${suffix}`;
});
})
.flatMap((s) => s);
return [
{
id: 1,
method: 'subscribe',
nonce: new Date().valueOf(),
params: {
channels: channels,
book_subscription_type: 'SNAPSHOT_AND_UPDATE'
}
}
];
}
messageIsError(message) {
return message.code !== undefined && message.code !== 0 && message.code !== 40003;
}
onMessage(msg) {
if (msg.method === 'public/heartbeat') {
this.send({
id: msg.id,
method: 'public/respond-heartbeat'
});
}
}
messageIsHeartbeat(msg) {
return msg.method === 'public/heartbeat';
}
}
exports.CryptoComRealTimeFeed = CryptoComRealTimeFeed;
//# sourceMappingURL=cryptocom.js.map