drl-trading-bot-dev2 / docs /trading_system_architecture.drawio
DRL Trading Bot
Feature: HTF Agent integration β€” live trading, API endpoints, UI tab
fc115d5
Raw
History Blame Contribute Delete
17.1 kB
<mxfile host="app.diagrams.net" modified="2026-02-06T12:30:00.000Z" agent="draw.io" version="21.0.0" type="device">
<diagram name="DRL Trading System Architecture" id="trading-system">
<mxGraphModel dx="1200" dy="800" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1600" pageHeight="1200" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<!-- Title -->
<mxCell id="title" value="πŸ€– DRL Trading System - Complete Architecture" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=24;fontStyle=1;fontColor=#1a1a1a;" vertex="1" parent="1">
<mxGeometry x="400" y="20" width="600" height="40" as="geometry" />
</mxCell>
<!-- ========== DATA SOURCES (Left Side) ========== -->
<mxCell id="data-sources-group" value="πŸ“‘ Data Sources" style="swimlane;startSize=30;fillColor=#dae8fc;strokeColor=#6c8ebf;fontStyle=1;fontSize=14;" vertex="1" parent="1">
<mxGeometry x="40" y="80" width="200" height="400" as="geometry" />
</mxCell>
<mxCell id="binance-api" value="Binance API&#xa;(OHLCV + Futures)" style="rounded=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="data-sources-group">
<mxGeometry x="20" y="50" width="160" height="50" as="geometry" />
</mxCell>
<mxCell id="binance-ls" value="Binance L/S Ratio&#xa;(Crowding Signal)" style="rounded=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="data-sources-group">
<mxGeometry x="20" y="110" width="160" height="50" as="geometry" />
</mxCell>
<mxCell id="binance-oi" value="Binance OI&#xa;(Open Interest)" style="rounded=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="data-sources-group">
<mxGeometry x="20" y="170" width="160" height="50" as="geometry" />
</mxCell>
<mxCell id="top-traders" value="Top Traders&#xa;(Smart Money)" style="rounded=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="data-sources-group">
<mxGeometry x="20" y="230" width="160" height="50" as="geometry" />
</mxCell>
<mxCell id="fear-greed" value="Fear &amp; Greed Index&#xa;(Sentiment)" style="rounded=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="data-sources-group">
<mxGeometry x="20" y="290" width="160" height="50" as="geometry" />
</mxCell>
<!-- ========== FEATURE ENGINEERING (Center-Left) ========== -->
<mxCell id="features-group" value="πŸ”§ Feature Engineering" style="swimlane;startSize=30;fillColor=#d5e8d4;strokeColor=#82b366;fontStyle=1;fontSize=14;" vertex="1" parent="1">
<mxGeometry x="280" y="80" width="220" height="400" as="geometry" />
</mxCell>
<mxCell id="ultimate-features" value="Ultimate Feature Engine&#xa;(125+ Features)" style="rounded=1;whiteSpace=wrap;fillColor=#e1d5e7;strokeColor=#9673a6;fontStyle=1;" vertex="1" parent="features-group">
<mxGeometry x="20" y="50" width="180" height="60" as="geometry" />
</mxCell>
<mxCell id="technical" value="Technical Indicators&#xa;RSI, MACD, BB, ATR..." style="rounded=1;whiteSpace=wrap;fillColor=#f5f5f5;strokeColor=#666666;" vertex="1" parent="features-group">
<mxGeometry x="20" y="120" width="180" height="45" as="geometry" />
</mxCell>
<mxCell id="volatility" value="Volatility Analysis&#xa;ATR, HV, IV Proxy" style="rounded=1;whiteSpace=wrap;fillColor=#f5f5f5;strokeColor=#666666;" vertex="1" parent="features-group">
<mxGeometry x="20" y="170" width="180" height="45" as="geometry" />
</mxCell>
<mxCell id="whale-tracker" value="πŸ‹ Whale Tracker&#xa;(4 FREE Sources)" style="rounded=1;whiteSpace=wrap;fillColor=#ffe6cc;strokeColor=#d79b00;fontStyle=1;" vertex="1" parent="features-group">
<mxGeometry x="20" y="225" width="180" height="55" as="geometry" />
</mxCell>
<mxCell id="correlation" value="Correlation Engine&#xa;Multi-Asset Signals" style="rounded=1;whiteSpace=wrap;fillColor=#f5f5f5;strokeColor=#666666;" vertex="1" parent="features-group">
<mxGeometry x="20" y="290" width="180" height="45" as="geometry" />
</mxCell>
<mxCell id="observation" value="Normalized Observation&#xa;(125 dims β†’ Model)" style="rounded=1;whiteSpace=wrap;fillColor=#d5e8d4;strokeColor=#82b366;fontStyle=1;" vertex="1" parent="features-group">
<mxGeometry x="20" y="345" width="180" height="45" as="geometry" />
</mxCell>
<!-- ========== DRL BRAIN (Center) ========== -->
<mxCell id="brain-group" value="🧠 DRL Brain" style="swimlane;startSize=30;fillColor=#f8cecc;strokeColor=#b85450;fontStyle=1;fontSize=14;" vertex="1" parent="1">
<mxGeometry x="540" y="80" width="220" height="400" as="geometry" />
</mxCell>
<mxCell id="ppo-agent" value="PPO Agent&#xa;(Stable Baselines3)" style="rounded=1;whiteSpace=wrap;fillColor=#f8cecc;strokeColor=#b85450;fontStyle=1;" vertex="1" parent="brain-group">
<mxGeometry x="20" y="50" width="180" height="60" as="geometry" />
</mxCell>
<mxCell id="policy-net" value="Policy Network&#xa;Ο€(a|s) β†’ Action Probs" style="rounded=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="brain-group">
<mxGeometry x="20" y="120" width="180" height="50" as="geometry" />
</mxCell>
<mxCell id="value-net" value="Value Network&#xa;V(s) β†’ State Value" style="rounded=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="brain-group">
<mxGeometry x="20" y="180" width="180" height="50" as="geometry" />
</mxCell>
<mxCell id="action-output" value="Action Output&#xa;0=HOLD, 1=BUY, 2=SELL" style="rounded=1;whiteSpace=wrap;fillColor=#e1d5e7;strokeColor=#9673a6;fontStyle=1;" vertex="1" parent="brain-group">
<mxGeometry x="20" y="250" width="180" height="50" as="geometry" />
</mxCell>
<mxCell id="vec-normalize" value="VecNormalize&#xa;Observation Scaling" style="rounded=1;whiteSpace=wrap;fillColor=#f5f5f5;strokeColor=#666666;" vertex="1" parent="brain-group">
<mxGeometry x="20" y="310" width="180" height="45" as="geometry" />
</mxCell>
<!-- ========== RISK MANAGEMENT (Center-Right) ========== -->
<mxCell id="risk-group" value="⚠️ Risk Management" style="swimlane;startSize=30;fillColor=#ffe6cc;strokeColor=#d79b00;fontStyle=1;fontSize=14;" vertex="1" parent="1">
<mxGeometry x="800" y="80" width="220" height="400" as="geometry" />
</mxCell>
<mxCell id="whale-filter" value="πŸ‹ Whale Filter&#xa;Block Bad Trades" style="rounded=1;whiteSpace=wrap;fillColor=#ffe6cc;strokeColor=#d79b00;fontStyle=1;" vertex="1" parent="risk-group">
<mxGeometry x="20" y="50" width="180" height="55" as="geometry" />
</mxCell>
<mxCell id="stop-loss" value="Stop Loss&#xa;1.5% Max Loss" style="rounded=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="risk-group">
<mxGeometry x="20" y="115" width="180" height="45" as="geometry" />
</mxCell>
<mxCell id="take-profit" value="Take Profit&#xa;2.5% Target" style="rounded=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="risk-group">
<mxGeometry x="20" y="170" width="180" height="45" as="geometry" />
</mxCell>
<mxCell id="circuit-breaker" value="Circuit Breaker&#xa;5% Daily Loss Limit" style="rounded=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="risk-group">
<mxGeometry x="20" y="225" width="180" height="45" as="geometry" />
</mxCell>
<mxCell id="cooldown" value="Trade Cooldown&#xa;30min Min Hold" style="rounded=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="risk-group">
<mxGeometry x="20" y="280" width="180" height="45" as="geometry" />
</mxCell>
<mxCell id="position-size" value="Position Sizing&#xa;50% of Balance" style="rounded=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="risk-group">
<mxGeometry x="20" y="335" width="180" height="45" as="geometry" />
</mxCell>
<!-- ========== EXECUTION (Right Side) ========== -->
<mxCell id="execution-group" value="πŸ’° Trade Execution" style="swimlane;startSize=30;fillColor=#d5e8d4;strokeColor=#82b366;fontStyle=1;fontSize=14;" vertex="1" parent="1">
<mxGeometry x="1060" y="80" width="200" height="400" as="geometry" />
</mxCell>
<mxCell id="live-trading" value="Live Trading Agent&#xa;(live_trading.py)" style="rounded=1;whiteSpace=wrap;fillColor=#d5e8d4;strokeColor=#82b366;fontStyle=1;" vertex="1" parent="execution-group">
<mxGeometry x="15" y="50" width="170" height="55" as="geometry" />
</mxCell>
<mxCell id="dry-run" value="πŸ§ͺ Dry Run Mode&#xa;Simulated Trades" style="rounded=1;whiteSpace=wrap;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="execution-group">
<mxGeometry x="15" y="115" width="170" height="45" as="geometry" />
</mxCell>
<mxCell id="open-position" value="Open Position&#xa;LONG / SHORT" style="rounded=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="execution-group">
<mxGeometry x="15" y="170" width="170" height="45" as="geometry" />
</mxCell>
<mxCell id="close-position" value="Close Position&#xa;+ P&amp;L Calculation" style="rounded=1;whiteSpace=wrap;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="execution-group">
<mxGeometry x="15" y="225" width="170" height="45" as="geometry" />
</mxCell>
<mxCell id="state-persist" value="State Persistence&#xa;trading_state.json" style="rounded=1;whiteSpace=wrap;fillColor=#f5f5f5;strokeColor=#666666;" vertex="1" parent="execution-group">
<mxGeometry x="15" y="280" width="170" height="45" as="geometry" />
</mxCell>
<mxCell id="trade-log" value="Trade Log&#xa;trades.csv" style="rounded=1;whiteSpace=wrap;fillColor=#f5f5f5;strokeColor=#666666;" vertex="1" parent="execution-group">
<mxGeometry x="15" y="335" width="170" height="45" as="geometry" />
</mxCell>
<!-- ========== FLOW ARROWS ========== -->
<!-- Data Sources β†’ Features -->
<mxCell id="arrow1" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;curved=1;strokeWidth=2;strokeColor=#6c8ebf;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="240" y="200" as="sourcePoint" />
<mxPoint x="280" y="200" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="arrow1-label" value="Market Data" style="text;html=1;align=center;verticalAlign=middle;fontSize=10;fontColor=#6c8ebf;" vertex="1" parent="1">
<mxGeometry x="240" y="175" width="60" height="20" as="geometry" />
</mxCell>
<!-- Features β†’ Brain -->
<mxCell id="arrow2" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;curved=1;strokeWidth=2;strokeColor=#82b366;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="500" y="280" as="sourcePoint" />
<mxPoint x="540" y="280" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="arrow2-label" value="125 Features" style="text;html=1;align=center;verticalAlign=middle;fontSize=10;fontColor=#82b366;" vertex="1" parent="1">
<mxGeometry x="500" y="255" width="60" height="20" as="geometry" />
</mxCell>
<!-- Brain β†’ Risk -->
<mxCell id="arrow3" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;curved=1;strokeWidth=2;strokeColor=#b85450;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="760" y="280" as="sourcePoint" />
<mxPoint x="800" y="280" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="arrow3-label" value="Action" style="text;html=1;align=center;verticalAlign=middle;fontSize=10;fontColor=#b85450;" vertex="1" parent="1">
<mxGeometry x="760" y="255" width="50" height="20" as="geometry" />
</mxCell>
<!-- Risk β†’ Execution -->
<mxCell id="arrow4" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;curved=1;strokeWidth=2;strokeColor=#d79b00;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="1020" y="280" as="sourcePoint" />
<mxPoint x="1060" y="280" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="arrow4-label" value="Filtered" style="text;html=1;align=center;verticalAlign=middle;fontSize=10;fontColor=#d79b00;" vertex="1" parent="1">
<mxGeometry x="1020" y="255" width="50" height="20" as="geometry" />
</mxCell>
<!-- ========== WHALE TRACKER DETAIL BOX ========== -->
<mxCell id="whale-detail" value="πŸ‹ Whale Tracker (4 Sources)&#xa;─────────────────────&#xa;1. Binance L/S (25%) - Crowding&#xa;2. OI Trend (25%) - Smart Money&#xa;3. Top Traders (25%) - Positioning&#xa;4. Fear/Greed (25%) - Sentiment&#xa;─────────────────────&#xa;Confidence β‰₯50% β†’ HIGH&#xa;2+ Signals Agree β†’ Block Trades" style="shape=note;whiteSpace=wrap;strokeColor=#d79b00;fillColor=#fff2cc;align=left;verticalAlign=top;spacingLeft=10;fontSize=11;" vertex="1" parent="1">
<mxGeometry x="40" y="510" width="240" height="160" as="geometry" />
</mxCell>
<!-- ========== TRADING LOOP BOX ========== -->
<mxCell id="loop-detail" value="πŸ”„ Trading Loop (Every 30 min)&#xa;─────────────────────&#xa;1. Fetch latest 720 candles&#xa;2. Compute 125 features&#xa;3. Get whale signals (4 sources)&#xa;4. Model predicts action&#xa;5. Whale filter checks confidence&#xa;6. Risk checks (SL/TP/Circuit)&#xa;7. Execute or block trade&#xa;8. Log and persist state" style="shape=note;whiteSpace=wrap;strokeColor=#82b366;fillColor=#d5e8d4;align=left;verticalAlign=top;spacingLeft=10;fontSize=11;" vertex="1" parent="1">
<mxGeometry x="300" y="510" width="240" height="160" as="geometry" />
</mxCell>
<!-- ========== SIGNAL INTERPRETATION ========== -->
<mxCell id="signal-legend" value="πŸ“Š Signal Interpretation&#xa;─────────────────────&#xa;Score &gt; +0.15 β†’ BULLISH&#xa;Score &lt; -0.15 β†’ BEARISH&#xa;Otherwise β†’ NEUTRAL&#xa;─────────────────────&#xa;HIGH CONF + Bearish β†’ Block LONG&#xa;HIGH CONF + Bullish β†’ Block SHORT&#xa;LOW CONF β†’ Allow all trades" style="shape=note;whiteSpace=wrap;strokeColor=#9673a6;fillColor=#e1d5e7;align=left;verticalAlign=top;spacingLeft=10;fontSize=11;" vertex="1" parent="1">
<mxGeometry x="560" y="510" width="240" height="160" as="geometry" />
</mxCell>
<!-- ========== CURRENT STATUS ========== -->
<mxCell id="status-box" value="βœ… Current Status&#xa;─────────────────────&#xa;Mode: DRY-RUN&#xa;Position: LONG&#xa;Return: +1.0%&#xa;Confidence: 50% (HIGH)&#xa;─────────────────────&#xa;Whale Filter: ACTIVE" style="shape=note;whiteSpace=wrap;strokeColor=#82b366;fillColor=#d5e8d4;align=left;verticalAlign=top;spacingLeft=10;fontSize=11;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="820" y="510" width="200" height="160" as="geometry" />
</mxCell>
<!-- ========== FILES REFERENCE ========== -->
<mxCell id="files-box" value="πŸ“ Key Files&#xa;─────────────────────&#xa;live_trading.py - Main loop&#xa;src/brain/agent.py - PPO agent&#xa;src/features/ultimate_features.py&#xa;src/features/whale_tracker.py&#xa;src/backtest/data_loader.py&#xa;config/config.yaml" style="shape=note;whiteSpace=wrap;strokeColor=#6c8ebf;fillColor=#dae8fc;align=left;verticalAlign=top;spacingLeft=10;fontSize=11;" vertex="1" parent="1">
<mxGeometry x="1040" y="510" width="220" height="160" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>