# Finlytic Trades Service Finlytic Trades is a C# microservice managing the full lifecycle of automated trade signals and positions. It handles proposed trade validation, position tracking, TTL expiration, hourly performance updates, and trade closure. --- ## Core Modules & Architecture 1. **Trade Lifecycle Engine (`ITradeLifecycleService`)**: - Ingests trade proposals (`TradeProposalDto`), validates parameters (Entry, Stop Loss, Take Profit, Win Rate, Risk Tolerance), and tracks positions through `Active`, `Closed`, `Expired`, or `Cancelled` states. 2. **TTL Worker Service (`TtlWorkerService`)**: - Periodically checks active trades against Time-To-Live (`TtlMinutes`) constraints and automatically expires stale trades. 3. **Feedback Exporter Engine (`FeedbackExporterEngine`)**: - Exports trade outcome data (`TradeFeedbackRecord`) for AI model retraining and win-rate calibration. 4. **MQTT RPC & Event Communication**: - Subscribes to `finlytic/trades/proposed/#` and `finlytic/trades/updates/#`. - Handles RPC requests on `finlytic/trades/get_active/request` and `finlytic/trades/close/request/#`. - Publishes position updates to `finlytic/trades/update` and `finlytic/trades/get_active/response`. --- ## Feature Status ### Implemented Features - [x] Full Trade Lifecycle Management (`TradesDbContext` with PostgreSQL indexes). - [x] Automated TTL Expiration Worker (`TtlWorkerService`). - [x] AI Feedback Record Exporter (`FeedbackExporterEngine`). - [x] Pure Worker Service Architecture (`Host.CreateApplicationBuilder`, Kestrel HTTP server removed). - [x] Zero-Allocation MQTT RPC handlers for active trades & trade closure. ### Planned Features - [ ] Automated Trailing Stop Loss adjustment engine based on ATR (Average True Range). - [ ] Direct Broker API Execution integration (Trade Republic / Interactive Brokers automated order placement).