tardis-dev normalize deribit liquidations data
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()
no comments