Files
foxhunt/database
jgrusewski 1ece987396 chore(clippy): add deny(unwrap_used) to 4 low-violation crates and fix 13 violations
Add #![deny(clippy::unwrap_used, clippy::expect_used)] to database, ml-data,
trading-data, and broker_gateway_service crates, fixing all violations:

- database/src/transaction.rs: replace 7x .expect("Transaction already consumed")
  with .ok_or_else(|| DatabaseError::Transaction) and 2x .unwrap() on take()
  in commit/rollback with safe .ok_or_else() variants
- ml-data/src/performance.rs: replace .last().unwrap() and .first().unwrap()
  with if-let destructuring pattern
- trading-data/src/positions.rs: replace 3x write!().unwrap() with let _ = write!()
  and Decimal::from_str_exact("0.02").unwrap() with Decimal::new(2, 2)
- trading-data/src/executions.rs: replace 3x write!().unwrap() with let _ = write!(),
  and 3x .expect() on and_hms_opt(0,0,0) with .unwrap_or_default()
- broker_gateway_service/src/main.rs: replace encode().unwrap() with if-let,
  and from_utf8().unwrap() with .unwrap_or_else()
- Add #[allow(clippy::unwrap_used)] to test modules in all affected crates

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 23:59:10 +01:00
..

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

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

cargo test --package database

Documentation

Detailed API documentation is available at docs.rs/database.