nt-core

Crates.iont-core
lib.rsnt-core
version1.0.0
created_at2025-11-13 16:11:49.707923+00
updated_at2025-11-13 16:11:49.707923+00
descriptionCore types, traits, and utilities for Neural Trader - A high-performance algorithmic trading platform
homepage
repositoryhttps://github.com/ruvnet/neural-trader
max_upload_size
id1931447
size135,952
rUv (ruvnet)

documentation

https://docs.rs/nt-core

README

nt-core

Crates.io Documentation License: MIT OR Apache-2.0 Rust Build Status

Core types, traits, and abstractions for the NeuralTrader algorithmic trading system.

The nt-core crate provides the foundational building blocks used across all NeuralTrader components, including order types, position management, market data structures, account abstractions, and essential trading primitives.

Features

  • Zero-Copy Serialization - Efficient binary serialization with serde
  • Decimal Precision - Financial-grade calculations with rust_decimal
  • Type Safety - Strong typing for orders, positions, and market data
  • Async-First - Built on tokio for high-performance concurrent operations
  • Thread-Safe - Concurrent data structures with dashmap and parking_lot
  • Validation - Input validation with validator derive macros
  • Configuration - TOML-based configuration management
  • Error Handling - Comprehensive error types with thiserror and anyhow

Quick Start

Add nt-core to your Cargo.toml:

[dependencies]
nt-core = "0.1"

Basic Usage

use nt_core::{
    types::{Order, OrderType, Side, Position, MarketData, Account},
    traits::{OrderManager, PositionManager},
    config::TradingConfig,
};
use rust_decimal::Decimal;
use chrono::Utc;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Create a market order
    let order = Order {
        id: uuid::Uuid::new_v4(),
        symbol: "AAPL".to_string(),
        side: Side::Buy,
        order_type: OrderType::Market,
        quantity: Decimal::from(100),
        price: None,
        status: OrderStatus::Pending,
        created_at: Utc::now(),
        updated_at: Utc::now(),
    };

    // Create a position
    let position = Position {
        symbol: "AAPL".to_string(),
        quantity: Decimal::from(100),
        entry_price: Decimal::new(15000, 2), // $150.00
        current_price: Decimal::new(15200, 2), // $152.00
        unrealized_pnl: Decimal::from(200),
        realized_pnl: Decimal::ZERO,
        opened_at: Utc::now(),
    };

    // Load configuration
    let config = TradingConfig::from_file("config.toml")?;

    println!("Position P&L: ${}", position.unrealized_pnl);

    Ok(())
}

Architecture

The crate is organized into several key modules:

nt-core/
├── types.rs          # Core data types (Order, Position, MarketData, Account)
├── traits.rs         # Trait definitions (OrderManager, PositionManager, DataProvider)
├── config.rs         # Configuration management
├── error.rs          # Error types and conversions
└── lib.rs            # Module exports and prelude

Core Types

  • Order - Order representation with type, side, quantity, price
  • Position - Open position with P&L tracking
  • MarketData - OHLCV bars, ticks, quotes, order books
  • Account - Account balance, margin, buying power
  • Trade - Executed trade with fees and timestamps

Core Traits

  • OrderManager - Order placement, cancellation, modification
  • PositionManager - Position tracking and management
  • DataProvider - Market data subscription and retrieval
  • RiskManager - Risk checks and limit enforcement

Dependencies

Crate Purpose
tokio Async runtime
serde Serialization/deserialization
rust_decimal Decimal arithmetic for financial calculations
chrono Date and time handling
uuid Unique identifiers
thiserror Error type derivation
validator Input validation
dashmap Concurrent hash map
parking_lot Efficient synchronization primitives

Testing

Run the test suite:

cargo test -p nt-core

Run with property-based testing:

cargo test -p nt-core --features proptest

Run benchmarks:

cargo bench -p nt-core

Contributing

Contributions are welcome! Please ensure:

  1. All tests pass: cargo test -p nt-core
  2. Code is formatted: cargo fmt -p nt-core
  3. No clippy warnings: cargo clippy -p nt-core -- -D warnings
  4. Documentation builds: cargo doc -p nt-core --no-deps

License

Licensed under either of:

at your option.

Commit count: 0

cargo fmt