Skip to main content
The Polaris TypeScript SDK is available on npm as polaris-data.

Install

Or install with yarn:
The SDK ships as a dual ESM/CJS build. It requires Node.js 18 or later.

Quickstart

Use replay(...) when you want to stream historical rows in a script or backfill job. You can run this without an API key set.

Create a client

If you omit apiKey, the client reads POLARIS_API_KEY from the environment.
The main constructor is:

Core methods

Use PolarisClient for discovery, historical replay, and direct query workflows. from and to accept ISO 8601 strings, Date objects, or Unix epoch milliseconds (number). stream, replay, events, and l2Snapshots reconstruct standardized orderbooks by default. Snapshots replace the complete state, deltas update listed prices, and zero quantity deletes a price. Books clear across gaps and reconnects, with deltas skipped until a new snapshot. Use l2Updates(...) for raw snapshots and deltas, then feed selected updates into the exported OrderbookBuilder for application-managed books.

Match event schema versions

StandardEvent is the structural LegacyStandardEvent | StandardEventV2 union. Check for collector_timestamp before reading version-specific fields:
SDK filters and derivations use collector time for v2. Exchange time is nullable venue provenance and may regress. See Event envelope.

Discover a market before you query it

Use catalog(...) to find the exact Polaris market ID for a venue.
If you want a high-level view of supported venues and example market IDs before you query the exact pair, start with Market Coverage.

Query events

Use events(...) when you want standardized historical event rows beyond trades alone.

Query trades

trades(...) returns a list of normalized trade events. The SDK handles pagination and snapshot-backed historical reads for you.

Query intents and RFQs

intents(...) returns typed RFQ, quote, executable-intent, and settlement observations in stored order. Use market: "intents" and correlate rows by their captured rfq_id or intent_id.
See the Intents and RFQs guide for lifecycle reconstruction and the schema reference for fields.

Query option tickers

Use optionTickers(...) with an underlying market such as BTC. Omit instrument for the whole option chain, or provide one exact venue-native contract.
Every option ticker event keeps source, the normalized underlying market, and the non-empty exact instrument separate. See Option tickers for the payload fields and realtime filtering behavior.

Query OHLCV bars

Use ohlcv(...) when you want interval bars instead of individual trades.
If you pass format: "tradingview", ohlcv(...) returns TradingView-style candle and volume arrays. The OHLCV aggregation engine preserves precision by scaling volume by 1e12 during accumulation to avoid floating-point drift.

Query order book snapshots

Use l2Snapshots(...) when you need order book depth data for microstructure analysis.
Use l2Updates(...) when you want to manage reconstruction in your application:
update() changes state without constructing a complete object. snapshot() creates sorted levels only when requested. Use apply() when you need the previous update-and-materialize behavior.

Query funding rates

Use fundingRates(...) to analyze perpetual funding rates and carry modeling.

Query mark prices

Use markPrices(...) for basis analysis, mark tracking, and liquidation-related research.

Query volume profiles

Use volume(...) for volume profiling and participation analysis.

Query VWAP series

Use vwap(...) for execution benchmarking and price smoothing.

Query volatility series

Use volatility(...) for risk modeling and intraperiod volatility analysis.

Query best bid/offer

Use bbo(...) for spread tracking, quote analytics, and top-of-book monitoring.

Query depth metrics

Use depthMetrics(...) for liquidity analysis and market impact estimation.

Local dataset storage

The SDK stores standardized snapshots and local day files under a shared Polaris app-data root so the TypeScript SDK and other Polaris tools can reuse the same files. Default roots:
  • macOS: ~/Library/Application Support/polaris
  • Linux: $XDG_DATA_HOME/polaris or ~/.local/share/polaris
  • Windows: %APPDATA%\polaris
Within that root, the SDK uses this layout:
Pass datasetRoot to the constructor to override the root explicitly.

Snapshot-first replay

For standardized historical data, replay(...), events(...), trades(...), and default or TradingView ohlcv(...) prefer /snapshots and /download, then read local day files when they already exist. See Snapshots for the full flow.

Authentication

Public sources (e.g. Hyperliquid BTC) work without an API key. For premium sources, raw snapshots, or extended history, set your key via the POLARIS_API_KEY environment variable or pass it directly:
See Quickstart for the full auth model.

Error handling

The SDK uses a custom error class hierarchy rooted at PolarisError.

Next steps

  • Read Catalog before you hardcode source and market IDs.
  • Read Quickstart if you want the shared auth model behind the SDK.
  • Read Snapshots if your TypeScript workflow starts from historical files.
  • Read Trades, Events, or OHLCV for detailed method documentation.