tardis-dev computing order book imbalance ratio for BitMEX XBTUSD

node v12.22.12
version: 1.0.0
endpointsharetweet
const { streamNormalized, normalizeBookChanges, compute, computeBookSnapshots } = require('tardis-dev') class OrderBookImbalanceRatioComputable { constructor() { this.sourceDataTypes = ['book_snapshot'] } *compute(bookSnapshot) { let bidsAmount = 0 let asksAmount = 0 for (let i = 0; i < bookSnapshot.depth; i++) { bidsAmount += bookSnapshot.bids[i].amount asksAmount += bookSnapshot.asks[i].amount } const asksToBidsRatio = asksAmount / bidsAmount yield { type: 'book_imbalance', symbol: bookSnapshot.symbol, exchange: bookSnapshot.exchange, asksToBidsRatio, timestamp: bookSnapshot.timestamp, localTimestamp: bookSnapshot.localTimestamp } } } const computeOrderBookImbalanceRatio = () => new OrderBookImbalanceRatioComputable() const bitmexMessages = streamNormalized( { exchange: 'bitmex', symbols: ['XBTUSD'] }, normalizeBookChanges ) const messagesWithComputedData = compute( bitmexMessages, computeBookSnapshots({ depth: 5, interval: 2 * 1000 }), computeOrderBookImbalanceRatio ) async function run() { for await (const message of messagesWithComputedData) { if (message.type === 'book_imbalance') { console.log(message) } } } run()
Loading…

no comments

    sign in to comment