tardis-dev real-time spread for multiple exchanges

node v12.22.12
version: 1.0.0
endpointsharetweet
const { streamNormalized, normalizeBookChanges, combine, compute, computeBookSnapshots } = require('tardis-dev') const exchangesToStream = [ { exchange: 'bitmex', symbols: ['XBTUSD'] }, { exchange: 'deribit', symbols: ['BTC-PERPETUAL'] }, { exchange: 'cryptofacilities', symbols: ['PI_XBTUSD'] } ] const realTimeStreams = exchangesToStream.map(e => { return streamNormalized(e, normalizeBookChanges) }) const messages = combine(...realTimeStreams) const realTimeQuoteComputable = computeBookSnapshots({ depth: 1, interval: 0, name: 'realtime_quote' }) const messagesWithQuotes = compute(messages, realTimeQuoteComputable) const spreads = {} // print spreads info every 100ms setInterval(() => { console.clear() console.log(spreads) }, 100) async function run() { // update spread info real-time for await (const message of messagesWithQuotes) { if (message.type === 'book_snapshot') { spreads[message.exchange] = { spread: message.asks[0].price - message.bids[0].price, bestBid: message.bids[0], bestAsk: message.asks[0] } } } } run()
Loading…

no comments

    sign in to comment