const fetch = require('node-fetch')
const split2 = require('split2')
const serialize = (options) => {
return encodeURIComponent(JSON.stringify(options))
async function getDataFeeds() {
const filters = serialize([
symbols: ['XBTUSD', 'ETHUSD']
symbols: ['XBTUSD', 'ETHUSD']
const base_url = 'https://api.tardis.dev/v1/data-feeds/bitmex'
const url = `${base_url}?from=2019-07-01&offset=3&filters=${filters}`
const response = await fetch(url)
const lines = response.body.pipe(split2())
for await (const line of lines) {
// empty lines in response are being used as markers
// for disconnect events that occurred when collecting the data
const parts = line.split(' ')
const localTimestamp = parts[0]
const message = JSON.parse(parts[1])
// localTimestamp string marks message arrival timestamp
// message is a message dict as provided by exchange real-time stream
console.log(localTimestamp, message)