NetTrader is built using a Clean Architecture / Domain-Driven Design (DDD) approach, now fully evolved into a multi-tenant SaaS platform.
-
Domain Layer (
NetTrader.Domain)- Core entities:
User,TradeSession,UserApiKey. - Business logic abstractions and Enums.
- Zero external dependencies.
- Core entities:
-
Application Layer (
NetTrader.Application)- Orchestrates multi-tenant trading cycles.
GridTradingManager: Handles grid orchestration and order execution logic.IndicatorEnrichmentService: Computes MTF technical indicators.
-
Infrastructure Layer (
NetTrader.Infrastructure)- Exchanges: User-scoped
OrderExecutorFactorydecrypts keys and createsIOrderExecutorinstances for Binance/Bybit. - AI/ML:
GeminiAdvisor(LLM-based strategy) andMLSignalService(ML.NET inference). - Persistence: EF Core with PostgreSQL.
- Exchanges: User-scoped
-
Presentation/Worker Layer (
NetTrader.Api&NetTrader.Worker)- REST API: Secure endpoints for user management, settings, and trading control.
- SignalR: Real-time data streaming to frontend.
- Background Workers:
TradingBotWorker(Main loop) andTelegramListenerWorker.
graph TD
A[REST API / SignalR] --> B[Application Layer]
B --> C[TradingBotWorker]
C --> D{Cycle Type}
D -->|Fast 10s| E[ROI Monitor & Trailing Stop]
D -->|ML 60s| F[ML.NET Sniper Signals]
D -->|AI 30m| G[Gemini 1.5 Pro Advisory]
E & F & G --> H[OrderExecutorFactory]
H --> I[AES-256 Key Decrypt]
I --> J[Binance / Bybit API]
B --> K[(PostgreSQL)]
The TradingBotWorker executes a sequential loop over all active, subscribed users to ensure isolation and prevent API rate limiting.
graph TD
A[Start Cycle] --> B{Manual Trigger?}
B -- Yes --> C[Targeted User Cycle]
B -- No --> D{Global Interval?}
D -- Yes --> E[Fetch Market Data & ML Signals]
E --> F[Foreach Active User]
F --> G[Create Scoped OrderExecutor]
G --> H[Fetch Balance & Active Sessions]
H --> I[AI Advisory & ML Confluence]
I --> J[Update Grids & Place Orders]
J --> K[Wait 3-5s for Rate Limiting]
K --> L{More Users?}
L -- Yes --> F
L -- No --> M[End Cycle]
D -- No --> N[Fast Monitoring Loop]
UserExchangeExecutorFactory: The security gateway. It fetches encrypted API keys from the DB, decrypts them using a system-levelENCRYPTION_KEY, and provides a transientIOrderExecutorfor the current user's operation.GridMathCalculator: Implements Nash Equilibrium position sizing. It analyzes the Volume Profile to place orders at High Volume Nodes (HVNs), ensuring trades are executed near peak liquidity.MLSignalService: Uses aPredictionEnginePoolto run ML.NET models. It applies Bayesian inference to adjust confidence thresholds based on current market volatility and ADX trend strength.
- Sequential Execution: Users are processed one-by-one with an explicit delay to prevent Gemini API 429 errors and exchange rate-limit penalties.
- Memory Management: Use of
StringBuilderwith capacity andAsNoTracking()in EF Core for high-frequency loops. - Fail-Fast DI: The system refuses to start if critical security configurations (like
Encryption__Key) are missing.