tardis-dev
Version:
Convenient access to tick-level historical and real-time cryptocurrency market data via Node.js
74 lines • 2.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GateIORealTimeFeed = void 0;
const handy_1 = require("../handy");
const realtimefeed_1 = require("./realtimefeed");
class GateIORealTimeFeed extends realtimefeed_1.RealTimeFeedBase {
constructor() {
super(...arguments);
this.wssURL = 'wss://api.gateio.ws/ws/v4/';
this.httpURL = 'https://api.gateio.ws/api/v4';
}
mapToSubscribeMessages(filters) {
const payload = filters.map((filter) => {
if (!filter.symbols || filter.symbols.length === 0) {
throw new Error('GateIORealTimeFeed requires explicitly specified symbols when subscribing to live feed');
}
if (filter.channel === 'order_book_update') {
return filter.symbols.map((symbol) => {
return {
time: new Date().valueOf(),
channel: `spot.${filter.channel}`,
event: 'subscribe',
method: `${filter.channel}.subscribe`,
payload: [symbol, '100ms']
};
});
}
else {
return filter.symbols.map((symbol) => {
return {
time: new Date().valueOf(),
channel: `spot.${filter.channel}`,
event: 'subscribe',
method: `${filter.channel}.subscribe`,
payload: [symbol]
};
});
}
});
return payload.flatMap((f) => f);
}
messageIsError(message) {
if (message.error !== null && message.error !== undefined) {
return true;
}
return false;
}
async provideManualSnapshots(filters, shouldCancel) {
const orderBookFilter = filters.find((f) => f.channel === 'order_book_update');
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}/spot/order_book?currency_pair=${symbol}&limit=100&with_id=true`)
.json();
const snapshot = {
result: depthSnapshotResponse,
event: 'snapshot',
channel: `spot.order_book_update`,
symbol,
generated: true
};
this.manualSnapshotsBuffer.push(snapshot);
}
this.debug('requested manual snapshots successfully for: %s ', orderBookFilter.symbols);
}
}
exports.GateIORealTimeFeed = GateIORealTimeFeed;
//# sourceMappingURL=gateio.js.map