@deeptick/client
v0.1.2
Published
DeepTick TypeScript SDK — high-frequency crypto market data
Maintainers
Readme
DeepTick TypeScript SDK
npm install @deeptick/client
The TypeScript SDK provides three layers of access to DeepTick market data:
- CachedClient — Download daily Parquet/CSV archives with local disk caching
- DeepTickStream — Real-time WebSocket streaming with typed callbacks
- DeepTickFeed — Unified live/replay feed (backtest code = production code)
- Types & Derive — Full type definitions and client-side derived computations
Quick Start
import { CachedClient } from '@deeptick/client/cache';
const client = new CachedClient("https://api.deeptick.com");
// Load BTC trades for a date range (cached after first download)
const batches = await client.loadTrades(
"binance_futures",
"BTCUSDT",
"2026-05-01",
"2026-05-02"
);
console.log(`Loaded ${batches.length} daily files.`);
console.log(client.getStats());Streaming (Real-Time)
import { DeepTickStream } from '@deeptick/client/streaming';
const stream = new DeepTickStream({
url: "wss://api.deeptick.com/v1/stream?api_key=dtk_your_key"
});
// Typed callbacks for each data type
stream.onTrade((exchange, symbol, trade) => {
console.log(`[${exchange}] ${symbol}: ${trade.price} x ${trade.amount}`);
});
stream.onBookTicker((exchange, symbol, ticker) => {
console.log(`[${exchange}] ${symbol}: ${ticker.bid_price}/${ticker.ask_price}`);
});
stream.onDerivativeTicker((exchange, symbol, data) => {
console.log(`[${exchange}] ${symbol} funding: ${data.funding_rate}`);
});
// Connect and subscribe
await stream.connect();
await stream.subscribe([
"binance_futures.trades.BTCUSDT",
"*.book_ticker.*",
"*.derivative_ticker.*",
]);
// Measure latency
const latency = await stream.ping();
console.log(`Round-trip: ${latency}ms`);Global Callback
stream.onData((exchange, symbol, data) => {
// Receives ALL data types
console.log(exchange, symbol, data);
});Replay (Historical Tick-by-Tick)
import { DeepTickFeed } from '@deeptick/client/feed';
const feed = DeepTickFeed.replay(
"wss://api.deeptick.com/v1/replay/ws",
{
apiKey: "dtk_your_key",
sources: [
"binance_futures:trades:BTCUSDT",
"binance_futures:book_l2_delta:BTCUSDT",
],
from: "2026-05-01",
to: "2026-05-02",
speed: 0, // max speed
}
);
feed.onData((topic, data) => console.log(topic, data));
feed.onReplayEnd((stats) => {
console.log(`Replay complete: ${stats.totalEvents} events in ${stats.durationS}s`);
});
await feed.connect();Auto Mode (Replay → Live)
const feed = DeepTickFeed.auto(
"wss://api.deeptick.com",
{
apiKey: "dtk_your_key",
sources: ["hyperliquid:trades:BTC"],
from: "2026-05-01", // replay from here, then switch to live
}
);
feed.onData((topic, data) => process(data)); // same handler!
feed.onModeChange((from, to) => {
console.log(`Switched from ${from} to ${to}`);
});
await feed.connect();Derived Data (Computed On-the-Fly)
import { CachedClient } from '@deeptick/client/cache';
import { derive, unpackLevels } from '@deeptick/client/types';
import type {
TradeRecord,
BookDeltaRecord,
BBORecord,
CandleRecord,
BookSnapshot,
ImbalanceRecord,
VolumeProfileBucket,
} from '@deeptick/client/types';
const client = new CachedClient("https://api.deeptick.com");
// ── BBO from L2 deltas ──────────────────────────────────────────────
const deltas = await client.loadBookDeltas("binance_futures", "BTCUSDT", "2026-05-01");
const bbo: BBORecord[] = derive.bbo(deltas);
console.log(`BBO rows: ${bbo.length}`);
// ── Candles at any interval ─────────────────────────────────────────
const trades = await client.loadTrades("binance_futures", "BTCUSDT", "2026-05-01");
const candles1m: CandleRecord[] = derive.candles(trades, { intervalMs: 60_000 });
const candles5m: CandleRecord[] = derive.candles(trades, { intervalMs: 300_000 });
// ── Book snapshots (20 levels every 1 min) ──────────────────────────
const snapshots: BookSnapshot[] = derive.bookSnapshots(deltas, {
depth: 20,
intervalMs: 60_000,
});
// ── Volume profile ──────────────────────────────────────────────────
const profile: VolumeProfileBucket[] = derive.volumeProfile(trades, {
numBuckets: 100,
});
// ── Order book imbalance ────────────────────────────────────────────
const imbalance: ImbalanceRecord[] = derive.bookImbalance(deltas, {
depth: 5,
intervalMs: 1000,
});
// ── Cross-exchange funding spread ───────────────────────────────────
const hlFunding = await client.loadFunding("hyperliquid", "BTC", "2026-05-01");
const bnFunding = await client.loadFunding("binance_futures", "BTCUSDT", "2026-05-01");
const fundingCross = derive.fundingCross(
{ hyperliquid: hlFunding, binance_futures: bnFunding },
{ intervalMs: 3_600_000 }
);
// ── Cross-exchange basis ────────────────────────────────────────────
const hlTrades = await client.loadTrades("hyperliquid", "BTC", "2026-05-01");
const bnTrades = await client.loadTrades("binance_futures", "BTCUSDT", "2026-05-01");
const basis = derive.crossExchangeBasis(
{ hyperliquid: hlTrades, binance_futures: bnTrades },
{ intervalMs: 1000 }
);
// ── Unpack binary book levels ───────────────────────────────────────
const packed = new Uint8Array(/* from parquet column */);
const levels: [number, number][] = unpackLevels(packed);
// levels = [[price1, size1], [price2, size2], ...]Type Definitions
// Wire protocol types for streaming
interface StreamTrade {
exchange: string; symbol: string;
timestamp: number; local_timestamp: number;
trade_id: string; price: number; amount: number;
side: 'buy' | 'sell';
}
interface StreamBookTicker {
exchange: string; symbol: string;
timestamp: number; local_timestamp: number;
bid_price: number; bid_amount: number;
ask_price: number; ask_amount: number;
}
interface StreamDerivativeTicker {
exchange: string; symbol: string;
timestamp: number; local_timestamp: number;
funding_rate: number | null;
predicted_funding_rate: number | null;
open_interest: number | null;
last_price: number | null;
mark_price: number | null;
index_price: number | null;
}Architecture
client-ts/src/
├── types.ts # Type definitions + derive namespace (BBO, candles, snapshots)
├── cache.ts # CachedClient — HTTP download + disk cache
├── streaming.ts # DeepTickStream — real-time WebSocket (Node + Browser)
└── feed.ts # DeepTickFeed — unified live/replay feed