Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

tardis-dev custom binance trades normalization

node v12.22.6
version: 1.0.0
endpointsharetweet
const { streamNormalized, normalizeTrades } = require('tardis-dev') const customBinanceTradesMapper = { canHandle(message) { return message.stream.endsWith('@aggTrade') }, getFilters(symbols) { if (symbols !== undefined) { symbols = symbols.map(s => s.toLocaleLowerCase()) } // binance api expects all symbols to be lower cased return [ { channel: 'aggTrade', symbols } ] }, *map(message, localTimestamp) { const binanceAggTrade = message.data yield { type: 'trade', symbol: binanceAggTrade.s, exchange: 'binance', id: String(binanceAggTrade.a), price: Number(binanceAggTrade.p), amount: Number(binanceAggTrade.q), side: binanceAggTrade.m ? 'sell' : 'buy', timestamp: new Date(binanceAggTrade.T), localTimestamp: localTimestamp } } } const normalizeTradesWithBinancePatch = exchange => { if (exchange === 'binance') { return customBinanceTradesMapper } return normalizeTrades(exchange) } async function run() { const messages = streamNormalized( { exchange: 'binance', symbols: ['btcusdt'] }, normalizeTradesWithBinancePatch ) for await (const message of messages) { console.log(message) } } run()
Loading…

no comments

    sign in to comment