tardis-dev
Version:
Convenient access to tick-level historical and real-time cryptocurrency market data via Node.js
37 lines • 1.23 kB
JavaScript
import { wait } from "../handy.js";
import { RealTimeFeedBase } from "./realtimefeed.js";
export class BlockchainComRealTimeFeed extends RealTimeFeedBase {
wssURL = 'wss://ws.blockchain.info/mercury-gateway/v1/ws';
originHeader = 'https://exchange.blockchain.com';
mapToSubscribeMessages(filters) {
const subs = filters
.map((filter) => {
if (!filter.symbols || filter.symbols.length === 0) {
throw new Error('BlockchainComRealTimeFeed requires explicitly specified symbols when subscribing to live feed');
}
return filter.symbols.map((symbol) => {
return {
action: 'subscribe',
channel: filter.channel,
symbol
};
});
})
.flatMap((f) => f);
return subs;
}
messageIsError(message) {
return message.event === 'rejected';
}
messageIsHeartbeat(msg) {
return msg.channel === 'heartbeat';
}
async onConnected() {
this.send({
action: 'subscribe',
channel: 'heartbeat'
});
await wait(0);
}
}
//# sourceMappingURL=blockchaincom.js.map