tardis-dev
Version:
Convenient access to tick-level historical and real-time cryptocurrency market data via Node.js
66 lines • 2.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AscendexRealTimeFeed = void 0;
const handy_1 = require("../handy");
const realtimefeed_1 = require("./realtimefeed");
class AscendexRealTimeFeed extends realtimefeed_1.RealTimeFeedBase {
constructor() {
super(...arguments);
this.wssURL = 'wss://ascendex.com/api/pro/v2/stream';
this.sendCustomPing = () => {
this.send({ op: 'ping' });
};
}
mapToSubscribeMessages(filters) {
const subs = filters
.filter((f) => f.channel !== 'depth-snapshot-realtime')
.map((filter) => {
if (filter.channel === 'futures-pricing-data') {
return [
{
op: 'sub',
ch: 'futures-pricing-data'
}
];
}
if (!filter.symbols || filter.symbols.length === 0) {
throw new Error('AscendexRealTimeFeed requires explicitly specified symbols when subscribing to live feed');
}
return filter.symbols.map((symbol) => {
return {
op: 'sub',
ch: `${filter.channel}:${symbol}`
};
});
})
.flatMap((f) => f);
return subs;
}
messageIsError(message) {
return message.m === 'error';
}
messageIsHeartbeat(msg) {
return msg.m === 'pong';
}
async provideManualSnapshots(filters, shouldCancel) {
const depthSnapshotChannel = filters.find((f) => f.channel === 'depth-snapshot-realtime');
if (!depthSnapshotChannel) {
return;
}
await (0, handy_1.wait)(100);
for (let symbol of depthSnapshotChannel.symbols) {
if (shouldCancel()) {
return;
}
this.send({
op: 'req',
action: 'depth-snapshot-realtime',
args: { symbol }
});
await (0, handy_1.wait)(10);
}
this.debug('sent depth-snapshot-realtime "req" for: %s', depthSnapshotChannel.symbols);
}
}
exports.AscendexRealTimeFeed = AscendexRealTimeFeed;
//# sourceMappingURL=ascendex.js.map