Step 1.
npm install tardis-dev
Step 2.
Try it live on RunKit or run snippet below locally
const { streamNormalized, normalizeLiquidations, combine } = require('tardis-dev') | |
// let's monitor BTC perpetuals swaps only | |
const monitoredExchanges = [ | |
{ id: 'ftx', symbols: ['BTC-PERP'] }, | |
{ id: 'bitmex', symbols: ['XBTUSD'] }, | |
{ id: 'deribit', symbols: ['BTC-PERPETUAL'] }, | |
{ id: 'binance-futures', symbols: ['BTCUSDT'] }, | |
{ id: 'binance-delivery', symbols: ['BTCUSD_PERP'] }, | |
{ id: 'bitfinex-derivatives', symbols: ['BTCF0:USTF0'] }, | |
{ id: 'cryptofacilities', symbols: ['PI_XBTUSD'] }, | |
{ id: 'huobi-dm-swap', symbols: ['BTC-USD'] } | |
] | |
async function monitorLiquidations() { | |
const monitoredExchangesLiquidationsStreams = monitoredExchanges.map((exchange) => { | |
return streamNormalized( | |
{ | |
exchange: exchange.id, | |
symbols: exchange.symbols, | |
timeoutIntervalMS: 30 * 60 * 1000 | |
}, | |
normalizeLiquidations | |
) | |
}) | |
const combinedLiquidationStream = combine(...monitoredExchangesLiquidationsStreams) | |
console.log('Liquidations monitor started...') | |
for await (const liquidation of combinedLiquidationStream) { | |
formatLiquidation(liquidation) | |
} | |
} | |
const meta = { | |
ftx: { | |
name: 'FTX', | |
contractMultiplier: 1, | |
inverse: false | |
}, | |
bitmex: { | |
name: 'BitMEX', | |
contractMultiplier: 1, | |
inverse: true | |
}, | |
deribit: { | |
name: 'Deribit', | |
contractMultiplier: 1, | |
inverse: true | |
}, | |
'binance-futures': { | |
name: 'Binance USDT Futures', | |
contractMultiplier: 1, | |
inverse: false | |
}, | |
'binance-delivery': { | |
name: 'Binance COIN Futures', | |
contractMultiplier: 1, | |
inverse: true | |
}, | |
'bitfinex-derivatives': { | |
name: 'Bitfinex Derivatives', | |
contractMultiplier: 1, | |
inverse: false | |
}, | |
cryptofacilities: { | |
name: 'Kraken Futures', | |
contractMultiplier: 1, | |
inverse: true | |
}, | |
'huobi-dm-swap': { | |
name: 'Huobi Swap', | |
contractMultiplier: 100, | |
inverse: true | |
} | |
} | |
const usdCurrencyFormatter = new Intl.NumberFormat('en-US', { | |
style: 'currency', | |
currency: 'USD' | |
}) | |
function formatLiquidation(liquidation) { | |
const { name, contractMultiplier, inverse } = meta[liquidation.exchange] | |
const position = liquidation.side === 'sell' ? 'long' : 'short' | |
const price = usdCurrencyFormatter.format(liquidation.price) | |
let normalizedAmount = liquidation.amount * contractMultiplier | |
if (inverse === false) { | |
normalizedAmount = normalizedAmount * liquidation.price | |
} | |
const minSize = 10000 | |
if (normalizedAmount < minSize) { | |
return; | |
} | |
const liquidatedAmunt = usdCurrencyFormatter.format(normalizedAmount) | |
const timestamp = liquidation.timestamp.toISOString() | |
const direction = liquidation.side === 'sell' ? '📉' : '📈' | |
console.log( | |
`${direction} ${name} liquidated ${position} ${liquidation.symbol} position` + | |
` at ${price}: ${liquidation.side} ${liquidatedAmunt}, timestmap: ${timestamp}` | |
) | |
} | |
monitorLiquidations() |
Step 3.
Enjoy watching the blood!
If you'd prefer standalone CLI version of that or trying to use it but from different language, please reach out in comments! Thanks.
Resources:
1) tardis-dev lib https://github.com/tardis-dev/tardis-node
2) not sure what the liquidation is? See https://blog.bybit.com/academy/what-is-liquidation/
or https://academy.binance.com/en/glossary/forced-liquidation
Top comments (1)
Super cool, well done!