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 normalize deribit liquidations data

node v12.22.12
version: 1.0.0
endpointsharetweet
const { replayNormalized } = require('tardis-dev') const deribitLiquidationsMapper = { canHandle(message) { const channel = message.params !== undefined ? message.params.channel : undefined if (channel === undefined) { return false } return channel.startsWith('trades') && message.params.data.some(trade => trade.liquidation !== undefined) }, getFilters(symbols) { return [ { channel: 'trades', symbols } ] }, *map(message, localTimestamp) { for (const deribitLiquidationTrade of message.params.data) { if (deribitLiquidationTrade.liquidation === undefined) { continue } yield { type: 'liquidation', symbol: deribitLiquidationTrade.instrument_name, exchange: 'deribit', price: deribitLiquidationTrade.price, amount: deribitLiquidationTrade.amount, side: deribitLiquidationTrade.direction, timestamp: new Date(deribitLiquidationTrade.timestamp), localTimestamp: localTimestamp } } } } const normalizeLiquidations = exchange => { if (exchange === 'deribit') { return deribitLiquidationsMapper } throw new Error(`normalizeLiquidations: ${exchange} not supported`) } async function run() { const messages = replayNormalized( { exchange: 'deribit', symbols: ['BTC-PERPETUAL'], from: '2019-07-01', to: '2019-07-02' }, normalizeLiquidations ) for await (const message of messages) { console.log(message) } } run()
Loading…

no comments

    sign in to comment