This system is built as a polyglot architecture leveraging NautilusTrader's dual Rust/Python APIs:
┌─────────────────────────────────────────────────────────────────┐
│ NautilusTrader Core │
│ ┌─────────────┐ ┌──────────────┐ ┌─────────────────┐ │
│ │ Rust Core │◄──►│ PyO3 Bridge │◄──►│ Python Runtime │ │
│ │ (Native) │ │ (Zero-Copy) │ │ (Strategy) │ │
│ └─────────────┘ └──────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
▲ ▲ ▲
│ │ │
┌────────┴────────┐ ┌───────┴────────┐ ┌────────┴────────┐
│ Signal Engine │ │ Type Mapping │ │ Strategy Logic │
│ - BBW Z-Score │ │ - Bar → Bar │ │ - Order Mgmt │
│ - ADX/CHOP │ │ - Price/Qty │ │ - Risk Mgmt │
│ - Correlation │ │ - UnixNanos │ │ - Lifecycle │
│ - ML Inference │ │ │ │ │
└─────────────────┘ └────────────────┘ └─────────────────┘
Native Rust library using NautilusTrader's Rust crates:
nautilus-core- Core time/types utilitiesnautilus-models- Bar, Instrument, Price, Quantity typesnautilus-indicators- Technical indicators (future integration)
Modules:
bbw_zscore.rs- Multi-timeframe Bollinger Band Width Z-scoresregime_filter.rs- ADX/Choppiness regime classificationcorr_detector.rs- BTC/ETH correlation for baseline routingml_inference.rs- ONNX runtime with Bayesian shrinkageposition_sizing.rs- Kelly-ATR-Liquidity modelsignal_router.rs- Confluence-based signal generationcircuit_breakers.rs- Safety mechanismspython.rs- PyO3 bindings module
NautilusTrader strategy that directly imports and uses the Rust engine:
from mft_engine import SignalRouter, CircuitBreakerManager
class MftSwingScalpStrategy(Strategy):
def on_bar(self, bar: Bar):
# Pass Nautilus Bar directly to Rust
self.router.update(bar, "5m")
# Generate signal using Rust engine
signal = self.router.generate_signal(...)
# Execute using Nautilus order factory
order = self.order_factory.market(...)
self.submit_order(order)- Rust 1.75+
- Python 3.8+
- NautilusTrader installed
cd engine
# Development build
cargo build --release
# Build Python extension
pip install maturin
maturin develop --releasepip install nautilus-trader numpy pandasfrom nautilus_trader.model.data import BarType
from nautilus_trader.model.identifiers import InstrumentId
from execution.nautilus_strategy import MftSwingScalpStrategy
instrument_id = InstrumentId.from_str("BTC-PERP.HYPERLIQUID")
btc_bar_type = BarType.from_str("BTC/USDT.HYPERLIQUID-1H-LAST-EXTERNAL")
eth_bar_type = BarType.from_str("ETH/USDT.HYPERLIQUID-1H-LAST-EXTERNAL")
strategy = MftSwingScalpStrategy(
instrument_ids=[instrument_id],
btc_bar_type=btc_bar_type,
eth_bar_type=eth_bar_type,
bar_types_5m=[BarType.from_str("BTC-PERP.HYPERLIQUID-5M-LAST-EXTERNAL")],
bar_types_15m=[BarType.from_str("BTC-PERP.HYPERLIQUID-15M-LAST-EXTERNAL")],
bar_types_1h=[BarType.from_str("BTC-PERP.HYPERLIQUID-1H-LAST-EXTERNAL")],
account_balance=100_000.0,
ml_model_path="models/ml_model.onnx",
min_confluence=0.65,
)from nautilus_trader.live.node import TradingNode
from nautilus_trader.adapters.hyperliquid.config import HyperLiquidDataClientConfig
config = TradingNodeConfig(
trader_id="TRADER-001",
data_clients=[HyperLiquidDataClientConfig(...)],
exec_clients=[],
strategies=[strategy],
)
node = TradingNode(config=config)
await node.run_async()- Ingestion: NautilusTrader fetches bars from exchange (HyperLiquid, Binance, etc.)
- Processing: Bars passed to Rust engine via PyO3 (zero-copy)
- Signal Generation: Rust computes indicators, ML inference, confluence
- Execution: Signal returned to Python, orders submitted via Nautilus
- Monitoring: PnL tracked, circuit breakers updated in real-time
| Operation | Latency | Notes |
|---|---|---|
| Bar update (Rust) | <1μs | Native processing |
| PyO3 call overhead | ~100ns | Zero-copy for primitives |
| ML inference | 50-500μs | Depends on model size |
| Signal generation | <1ms | Full pipeline |
| Order submission | 1-5ms | Network dependent |
# Rust tests
cd engine && cargo test
# Python tests
pytest tests/cd engine && cargo doc --open| Parameter | Default | Description |
|---|---|---|
min_confluence |
0.65 | Minimum score to generate signal |
max_daily_drawdown |
0.05 | Daily loss limit (5%) |
max_loss_streak |
5 | Consecutive losses before halt |
kelly_fraction |
0.25 | Quarter-Kelly sizing |
confidence_shrinkage |
0.15 | Bayesian ML confidence adjustment |
- 5m: Scalp signals, BBW updates
- 15m: Intermediate trend confirmation
- 1H: Regime filter, correlation, swing signals
The system integrates with NautilusTrader's monitoring:
- Metrics: Prometheus endpoints for latency, signal counts
- Logs: Structured logging via Nautilus infrastructure
- Alerts: Circuit breaker triggers logged and emitted
- API Keys: Managed by NautilusTrader, never in Rust code
- Position Limits: Enforced at strategy and exchange level
- Circuit Breakers: Automatic halt on adverse conditions
- Audit Trail: All signals and orders logged with timestamps
# Check if PyO3 module loads
try:
from mft_engine import SignalRouter
print("✅ Rust engine available")
except ImportError as e:
print(f"❌ Import failed: {e}")
# Rebuild: cd engine && maturin develop --releaseCheck confluence score threshold:
print(f"Current confluence: {signal.confluence_score}")
print(f"Minimum required: {router.min_confluence}")MIT License - See LICENSE file for details.
- Fork repository
- Create feature branch
- Add tests for new functionality
- Ensure all existing tests pass
- Submit pull request