stock-bot/libs/questdb-client
2025-06-08 12:31:29 -04:00
..
src removed deprecated createLogger and replaced with getLogger 2025-06-08 12:31:29 -04:00
test added questdb-client integration tests 2025-06-04 14:15:36 -04:00
bunfig.toml removed jest 2025-06-04 12:48:09 -04:00
package.json moved to zod, packages messed up still 2025-06-07 14:24:28 -04:00
README.md added initial integration tests with bun 2025-06-04 12:26:55 -04:00
tsconfig.json updated tsconfigs 2025-06-07 14:51:48 -04:00

QuestDB Client Library

A comprehensive QuestDB client library for the Stock Bot trading platform, optimized for time-series data, market analytics, and high-performance queries.

Features

  • Time-Series Optimized: Built specifically for time-series data patterns
  • Dual Protocol Support: HTTP REST API and PostgreSQL wire protocol
  • InfluxDB Line Protocol: High-performance data ingestion
  • SQL Analytics: Full SQL support for complex analytics
  • Schema Management: Automatic table creation and partitioning
  • Performance Monitoring: Query performance tracking and optimization
  • Health Monitoring: Connection health monitoring and metrics

Usage

import { QuestDBClient } from '@stock-bot/questdb-client';

// Initialize client
const questClient = new QuestDBClient();
await questClient.connect();

// Insert market data using InfluxDB Line Protocol
await questClient.insert('ohlcv', {
  symbol: 'AAPL',
  open: 150.00,
  high: 152.00,
  low: 149.50,
  close: 151.50,
  volume: 1000000,
  timestamp: new Date()
});

// Query with SQL
const prices = await questClient.query(`
  SELECT symbol, close, timestamp 
  FROM ohlcv 
  WHERE symbol = 'AAPL' 
  AND timestamp > dateadd('d', -1, now())
  ORDER BY timestamp DESC
`);

// Time-series aggregations
const dailyStats = await questClient.aggregate('ohlcv')
  .select(['symbol', 'avg(close) as avg_price'])
  .where('symbol = ?', ['AAPL'])
  .groupBy('symbol')
  .sampleBy('1d', 'timestamp')
  .execute();

Data Types

The client provides typed access to the following time-series data:

  • ohlcv: OHLCV candlestick data
  • trades: Individual trade executions
  • quotes: Bid/ask quote data
  • indicators: Technical indicator values
  • performance: Portfolio performance metrics
  • risk_metrics: Risk calculation results

Configuration

Configure using environment variables:

QUESTDB_HOST=localhost
QUESTDB_HTTP_PORT=9000
QUESTDB_PG_PORT=8812
QUESTDB_INFLUX_PORT=9009

Time-Series Features

QuestDB excels at:

  • High-frequency data: Millions of data points per second
  • Time-based partitioning: Automatic partitioning by time
  • ASOF JOINs: Time-series specific joins
  • SAMPLE BY: Time-based aggregations
  • LATEST BY: Get latest values by key

Performance

The client includes performance optimizations:

  • Connection pooling for HTTP and PostgreSQL protocols
  • Batch insertions for high throughput
  • Compressed data transfer
  • Query result caching
  • Automatic schema optimization

Health Monitoring

Built-in health monitoring:

const health = await questClient.getHealth();
console.log(health.status); // 'healthy' | 'degraded' | 'unhealthy'