Last active
May 11, 2023 20:23
-
-
Save thaaddeus/39211703e378a1f16d65ad05c049939f to your computer and use it in GitHub Desktop.
liquidations_monitor.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Hi, I've updated the script to include minSize so liquidations is printed only if larger than minSize
thanks! how could i write to get all symbols for any given exchange? i was looking at tardis documentation but cant figure it out
sorry if its a silly question,,, i guess i could first get from exchanges endpoint?
yes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi! thanks so much for sharing, how could i filter for size? sorry for dumb question im really a noob with java specifically and overall coding :(