- 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 |
||
|---|---|---|
| .. | ||
| src | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
PostgreSQL Client Library
A comprehensive PostgreSQL client library for the Stock Bot trading platform, designed for operational data, transactions, and relational queries.
Features
- Connection Pooling: Robust connection pool management
- Type Safety: Full TypeScript support with typed queries
- Transaction Support: Multi-statement transactions with rollback
- Schema Management: Database schema validation and migrations
- Query Builder: Fluent query building interface
- Health Monitoring: Connection health monitoring and metrics
- Performance Tracking: Query performance monitoring and optimization
Usage
import { PostgreSQLClient } from '@stock-bot/postgres';
// Initialize client
const pgClient = new PostgreSQLClient();
await pgClient.connect();
// Execute a query
const users = await pgClient.query('SELECT * FROM users WHERE active = $1', [true]);
// Use query builder
const trades = await pgClient
.select('*')
.from('trades')
.where('symbol', '=', 'AAPL')
.orderBy('created_at', 'DESC')
.limit(10)
.execute();
// Execute in transaction
await pgClient.transaction(async (tx) => {
await tx.query('INSERT INTO trades (...) VALUES (...)', []);
await tx.query('UPDATE portfolio SET balance = balance - $1', [amount]);
});
Database Schemas
The client provides typed access to the following schemas:
- trading: Core trading operations (trades, orders, positions)
- strategy: Strategy definitions and performance
- risk: Risk management and compliance
- audit: Audit trails and logging
Configuration
Configure using environment variables:
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DATABASE=stockbot
POSTGRES_USERNAME=stockbot
POSTGRES_PASSWORD=your_password
Query Builder
The fluent query builder supports:
- SELECT, INSERT, UPDATE, DELETE operations
- Complex WHERE conditions with AND/OR logic
- JOINs (INNER, LEFT, RIGHT, FULL)
- Aggregations (COUNT, SUM, AVG, etc.)
- Subqueries and CTEs
- Window functions
Health Monitoring
The client includes built-in health monitoring:
const health = await pgClient.getHealth();
console.log(health.status); // 'healthy' | 'degraded' | 'unhealthy'