tardis-dev

Node.js tardis-dev library provides convenient access to tick-level real-time and historical cryptocurrency market data both in exchange native and normalized formats. Instead of callbacks it relies on async iteration (for await …of) enabling composability features like seamless switching between real-time data streaming and historical data replay or computing derived data locally.
import { replayNormalized, normalizeTrades, normalizeBookChanges } from 'tardis-dev'
const messages = replayNormalized(
{
exchange: 'binance',
symbols: ['btcusdt'],
from: '2024-03-01',
to: '2024-03-02'
},
normalizeTrades,
normalizeBookChanges
)
for await (const message of messages) {
console.log(message)
}
Features
-
historical tick-level market data replay backed by tardis.dev HTTP API — includes full order book depth snapshots plus incremental updates, tick-by-tick trades, historical open interest, funding, index, mark prices, liquidations and more
-
consolidated real-time data streaming API connecting directly to exchanges’ public WebSocket APIs
- transparent historical local data caching (cached data is stored on disk per slice in compressed format and decompressed on demand when reading the data)
- support for many cryptocurrency exchanges — see docs.tardis.dev for the full list
- automatic closed connections and stale connections reconnection logic for real-time streams
- computing derived data locally like order book imbalance, custom trade bars, book snapshots and more via
compute helper function and computables, e.g., volume based bars, top 20 levels order book snapshots taken every 10 ms etc.
- fast and lightweight architecture — low memory footprint and no heavy in-memory buffering
Installation
Requires Node.js v24.22.1+ (24.x) or v26.12.1+ installed.
npm install tardis-dev --save
tardis-dev is ESM-only. Examples in this README use ES modules and top-level await. Save snippets as .mjs or set "type": "module" in your package.json.
Documentation
Examples
Run the bundled example script
The repository includes example.js for quick manual checks against streaming, replay, native, and normalized data.
node example.js stream <exchange> <symbol> <channel>
node example.js replay <exchange> <symbol> <channel> <from> <to>
Optional flags can be mixed:
--normalized uses normalized <data-type> instead of native <channel>
--endpoint <url> overrides the API endpoint, default: https://api.tardis.dev/v1
--api-key <key> overrides the API key, default: TARDIS_DEV_API_KEY env var
--limit <n> stops after n messages
Real-time spread across multiple exchanges
Example showing how to quickly display real-time spread and best bid/ask info across multiple exchanges at once. It can be easily adapted to do the same for historical data (replayNormalized instead of streamNormalized).
import { streamNormalized, normalizeBookChanges, combine, compute, computeBookSnapshots } from 'tardis-dev'
const exchangesToStream = [
{ exchange: 'binance-futures', symbols: ['btcusdt'] },
{ exchange: 'deribit', symbols: ['BTC-PERPETUAL'] },
{ exchange: 'cryptofacilities', symbols: ['PI_XBTUSD'] }
]
const realTimeStreams = exchangesToStream.map((e) => {
return streamNormalized(e, normalizeBookChanges)
})
const messages = combine(...realTimeStreams)
const realTimeQuoteComputable = computeBookSnapshots({
depth: 1,
interval: 0,
name: 'realtime_quote'
})
const messagesWithQuotes = compute(messages, realTimeQuoteComputable)
const spreads = {}
setInterval(() => {
console.clear()
console.log(spreads)
}, 100)
for await (const message of messagesWithQuotes) {
if (message.type === 'book_snapshot') {
spreads[message.exchange] = {
spread: message.asks[0].price - message.bids[0].price,
bestBid: message.bids[0],
bestAsk: message.asks[0]
}
}
}
Seamless switching between real-time streaming and historical market data replay
Example showing a simple pattern of providing an async iterable of market data messages to a function that can process real-time or historical market data. That enables the same data pipeline for backtesting and live trading.
import { replayNormalized, streamNormalized, normalizeTrades, compute, computeTradeBars } from 'tardis-dev'
const historicalMessages = replayNormalized(
{
exchange: 'binance',
symbols: ['btcusdt'],
from: '2024-03-01',
to: '2024-03-02'
},
normalizeTrades
)
const realTimeMessages = streamNormalized(
{
exchange: 'binance',
symbols: ['btcusdt']
},
normalizeTrades
)
async function produceVolumeBasedTradeBars(messages) {
const withVolumeTradeBars = compute(
messages,
computeTradeBars({
kind: 'volume',
interval: 1
})
)
for await (const message of withVolumeTradeBars) {
if (message.type === 'trade_bar') {
console.log(message.name, message)
}
}
}
await produceVolumeBasedTradeBars(historicalMessages)
import { stream } from 'tardis-dev'
const messages = stream({
exchange: 'binance',
filters: [
{ channel: 'trade', symbols: ['btcusdt'] },
{ channel: 'depth', symbols: ['btcusdt'] }
]
})
for await (const { localTimestamp, message } of messages) {
console.log(localTimestamp, message)
}
Bitvavo real-time streaming uses Market Data Pro and requires BITVAVO_API_KEY and BITVAVO_API_SECRET environment variables.
stream() and streamNormalized() validate exchange sequence numbers by default. On a gap the message is dropped, onError receives a SequenceGapError, and the connection reconnects with fresh subscriptions and order book snapshots. Pass validateSequence: false to disable the check.
import { replay } from 'tardis-dev'
const messages = replay({
exchange: 'binance',
filters: [
{ channel: 'trade', symbols: ['btcusdt'] },
{ channel: 'depth', symbols: ['btcusdt'] }
],
from: '2024-03-01',
to: '2024-03-02'
})
for await (const { localTimestamp, message } of messages) {
console.log(localTimestamp, message)
}
评论