stock-bot/libs/data/questdb
Boki 4cd6038063 refactor: pre-M0 cleanup, core library hardening, and isolated dev/QA Docker stack
- Remove ~44k LOC of dead code, legacy v1 TS simulator/strategy stack, event-bus, analytics FastAPI prototype, legacy calculation archives, and unused deps (data-ingestion provider API handlers untouched)
- Extract @stock-bot/di/http-security and isolate @stock-bot/browser to data-ingestion via ServiceContainerBuilder.withRegistrations()
- Harden @stock-bot/mongodb read-only proxies, flatten @stock-bot/postgres with unified master+research migrations, and fix @stock-bot/config EnvLoader, ServiceApplication worker lifecycle, NamespacedCache.clear(), and BatchProcessor error propagation
- Flatten workspace root (remove apps/stock/package.json) and collapse orchestrator re-export shims
- Pin all Docker image versions, add shm_size/nofile/RAM caps and docker-compose.quant.yml, fix 05-add-visible-column.sql view recreation, and decouple dev/QA Compose project names for side-by-side execution
- Update PLATFORM-PLAN, DATA-CONTRACTS (bars_1m PARTITION BY MONTH, Rust bulk ETL, DuckDB limits), MILESTONES, and servers docs
2026-11-27 00:11:50 -05:00
..
src fix(questdb): preserve credentials and correct startup table SQL 2026-10-25 11:31:33 -04:00
test tests 2025-06-25 11:38:23 -04:00
bunfig.toml moved folders around 2025-06-21 18:27:00 -04:00
package.json refactor: pre-M0 cleanup, core library hardening, and isolated dev/QA Docker stack 2026-11-27 00:11:50 -05:00
README.md moved folders around 2025-06-21 18:27:00 -04:00
tsconfig.json commit 2 refactor 2026-10-20 14:35:45 -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';

// 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'