nt-core
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
tokiofor high-performance concurrent operations - Thread-Safe - Concurrent data structures with
dashmapandparking_lot - Validation - Input validation with
validatorderive macros - Configuration - TOML-based configuration management
- Error Handling - Comprehensive error types with
thiserrorandanyhow
Quick Start
Add nt-core to your Cargo.toml:
[]
= "0.1"
Basic Usage
use ;
use Decimal;
use Utc;
async
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:
Run with property-based testing:
Run benchmarks:
Contributing
Contributions are welcome! Please ensure:
- All tests pass:
cargo test -p nt-core - Code is formatted:
cargo fmt -p nt-core - No clippy warnings:
cargo clippy -p nt-core -- -D warnings - Documentation builds:
cargo doc -p nt-core --no-deps
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.