Files
foxhunt/database/README.md
jgrusewski 6093eac7bf 🔧 Tonic 0.14 Upgrade: Auto-generated and build system changes
Wave 64-65 cleanup: Proto regeneration and build system updates from Tonic 0.12→0.14 upgrade

Files updated:
- Cargo.lock: Dependency resolution for Tonic 0.14.2
- All build.rs: Updated for tonic-prost-build
- Proto files: Regenerated with tonic-prost 0.14
- Examples/tests: Updated for new gRPC API

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 07:34:26 +02:00

51 lines
2.1 KiB
Markdown

# Database Crate
## Overview
The `database` crate manages the persistent storage layer for the Foxhunt HFT system, primarily utilizing PostgreSQL. It handles schema definitions, migrations, and provides utilities for storing and querying critical trading data, including time-series market data and audit logs.
## Features
* **PostgreSQL Schema & Migrations:** Defines database schemas for trading events, market data, and user configurations, managed via an integrated migration system.
* **Event Streaming & Audit Log:** Provides interfaces for recording and querying all significant system events, ensuring a comprehensive audit trail for compliance and post-trade analysis.
* **Optimized Time-Series Storage:** Implements efficient storage and indexing strategies for high-volume, time-series market data.
* **Query Utilities:** Offers a set of helper functions and ORM-like abstractions for common data retrieval and manipulation tasks.
* **Connection Pooling:** Manages database connections efficiently using a connection pool to minimize overhead and improve throughput.
* **Data Archiving & Retention:** Includes mechanisms for managing data lifecycle, such as archiving old data or implementing retention policies.
## Usage
```rust
use database::models::{TradeEvent, NewTradeEvent};
use database::connection::establish_connection;
use common::types::{InstrumentId, Price, Quantity};
use chrono::Utc;
// This would typically come from a connection pool
let mut conn = establish_connection().expect("Failed to connect to database");
let new_trade = NewTradeEvent {
timestamp: Utc::now(),
instrument_id: InstrumentId::new("ETHUSD".to_string()),
price: Price::new(3000.50),
quantity: Quantity::new(1.2),
side: "BUY".to_string(),
// ... other fields
};
// Example: Insert a new trade event
// let inserted_trade = database::crud::create_trade_event(&mut conn, new_trade)
// .expect("Failed to insert trade event");
// println!("Inserted trade: {:?}", inserted_trade);
```
## Testing
```bash
cargo test --package database
```
## Documentation
Detailed API documentation is available at [docs.rs/database](https://docs.rs/database).