Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tardis-node

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tardis-node

tardis-node library provides fast and convenient access to tick-level real-time and historical cryptocurrency market data.

  • 2.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
38
increased by8.57%
Maintainers
1
Weekly downloads
 
Created
Source

tardis-node

Version Try on RunKit

Tardis Node library provides fast and convenient access to tick-level real-time and historical cryptocurrency market data.

Built-in support for:

  • real-time streaming market data with unified interface for connecting to public exchanges WebSocket APIs
  • historical market data replay backed by tardis.dev API
  • both exchange native and normalized* market data format
  • top cryptocurrency exchanges
  • automatic reconnection and stale connections detection logic for real-time streams
  • combining multiple exchanges feeds into single one
  • computing custom trade bins/bars and book snapshots client-side (eg: volume based bars, top 20 levels 100ms order book snapshots etc.)
  • full limit order book reconstruction, both for real-time and historical data
  • built-in TypeScript support

* normalized: consistent format for accessing market data across multiple exchanges -normalized trade, order book L2 and ticker data

Installation

Requires Node.js v12+ installed.

npm install tardis-node --save

Documentation

See the tardis-node docs.

Usage

Stream real-time market data in exchange native data format

const { Tardis } = require('tardis-node')
const tardis = new Tardis()

async function stream() {
  const messages = tardis.stream({
    exchange: 'bitmex',
    filters: [{ channel: 'trade', symbols: ['XBTUSD'] }, { channel: 'orderBookL2', symbols: ['XBTUSD'] }]
  })

  for await (const { message, localTimestamp } of messages) {
    console.log(message)
  }
}

stream()

Replay historical market data in exchange native data format

const { Tardis } = require('tardis-node')
const tardis = new Tardis()

async function replay() {
  const messages = tardis.replay({
    exchange: 'bitmex',
    filters: [{ channel: 'trade', symbols: ['XBTUSD'] }, { channel: 'orderBookL2', symbols: ['XBTUSD'] }],
    from: '2019-05-01',
    to: '2019-05-02'
  })

  for await (const { message, localTimestamp } of messages) {
    console.log(message)
  }
}

replay()

Stream real-time market data in normalized data format

const { Tardis } = require('tardis-node')
const tardis = new Tardis()

async function streamNormalized() {
  const messages = tardis.streamNormalized({
    exchange: 'bitmex',
    dataTypes: ['trade', 'book_change'],
    symbols: ['XBTUSD']
  })

  for await (const message of messages) {
    console.log(message)
  }
}

streamNormalized()

Replay historical market data in normalized data format

const { Tardis } = require('tardis-node')
const tardis = new Tardis()

async function replayNormalized() {
  const messages = tardis.replayNormalized({
    exchange: 'bitmex',
    dataTypes: ['trade', 'book_change'],
    symbols: ['XBTUSD'],
    from: '2019-05-01',
    to: '2019-05-02'
  })

  for await (const message of messages) {
    console.log(message)
  }
}

replayNormalized()

Combine two historical exchange market data feeds

Returns single messages 'stream' that is ordered by localTimestamp. It works the same way for real-time market data as well, but messages are returned in FIFO manner.

const { Tardis, combine } = require('tardis-node')
const tardis = new Tardis()

async function replayCombined() {
  const bitmexMessages = tardis.replayNormalized({
    exchange: 'bitmex',
    dataTypes: ['trade', 'book_change'],
    symbols: ['XBTUSD'],
    from: '2019-05-01',
    to: '2019-05-02'
  })

  const deribitMessages = tardis.replayNormalized({
    exchange: 'deribit',
    dataTypes: ['trade', 'book_change'],
    symbols: ['BTC-PERPETUAL'],
    from: '2019-05-01',
    to: '2019-05-02'
  })

  const combinedStream = combine(bitmexMessages, deribitMessages)

  for await (const message of combinedStream) {
    console.log(message)
  }
}

replayCombined()

Compute 10 seconds trade bins and top 5 levels book snapshots every 2 seconds for real-time market data stream

const { Tardis, compute } = require('tardis-node')
const tardis = new Tardis()

async function streamComputed() {
  const bitmexMessages = tardis.streamNormalized({
    exchange: 'bitmex',
    dataTypes: ['trade', 'book_change'],
    symbols: ['XBTUSD']
  })

  const messagesWithComputedTypes = compute(
    bitmexMessages,
    { type: 'trade_bin', binBy: 'time', binSize: 10 * 1000 },
    { type: 'book_snapshot', depth: 5, interval: 2 * 1000 }
  )

  for await (const message of messagesWithComputedTypes) {
    if (message.type === 'book_snapshot' || message.type === 'trade_bin') {
      console.log(message)
    }
  }
}

streamComputed()

Reconstruct historical limit order book at any point in time

It works in the same way for real-time market data.

const { Tardis, OrderBook } = require('tardis-node')
const tardis = new Tardis()

async function reconstructLOB() {
  const bitmexXBTMessages = tardis.replayNormalized({
    exchange: 'bitmex',
    dataTypes: ['trade', 'book_change'],
    symbols: ['XBTUSD'],
    from: '2019-05-01',
    to: '2019-05-02'
  })
  const orderBook = new OrderBook()

  for await (const message of bitmexXBTMessages) {
    if (message.type === 'book_change') {
      orderBook.update(message)
    }
    console.log(message.localTimestamp.toISOString(), orderBook.bestAsk(), orderBook.bestBid())
    // or orderBook.bids(), orderBook.asks() to get all levels at any given point in time
  }
}

reconstructLOB()

Keywords

FAQs

Package last updated on 15 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc