← Back to Learn
III AdvancedWeek 29 • Lesson 79Duration: 35 min

LOGS Monitoring & Logging

Observability — knowing what your system is doing at all times

Learning Objectives

  • Implement structured logging for trading systems
  • Set up monitoring dashboards and alerts
  • Know what metrics to track in production

Explain Like I'm 5

Logging = recording what happened. Monitoring = watching it in real-time. Alerting = getting notified when something goes wrong. Together, they give you OBSERVABILITY — the ability to understand your system's behavior without being physically present. Critical for a 24/7 trading system.

Think of It This Way

Monitoring is like having security cameras for your trading system. Logs are the recorded footage. Alerts are the alarm system. You can't watch 24/7, but you can set up systems that watch for you and notify you when something needs attention.

1What to Log

Trade events (HIGH priority): - Signal generated: symbol, direction, confidence, features - L2 decision: SKIP or ENTER with reason - Order placed: symbol, direction, price, SL, TP, volume - Order filled: fill price, slippage - Trade closed: exit price, PnL, duration, exit reason Risk events (HIGH priority): - DD zone change: from NORMAL to CAUTION - Risk level adjustment: 0.30% -> 0.25% - Daily limit approach: nearing 4.5R limit System events (MEDIUM priority): - Model prediction: symbol, prediction value - Feature computation: any anomalies - Connection status: connected, disconnected, reconnecting Performance metrics (MEDIUM priority): - Inference latency per model - Data fetch latency - Cycle time (total time per bar) Debug events (LOW priority): - Raw data received - Intermediate calculations - Configuration changes

2Alert Thresholds

Alerts that should wake you up: CRITICAL (immediate action): - Drawdown > 8% (CRITICAL DD zone) - 3+ consecutive errors - Connection down > 30 minutes - Model returning NaN predictions WARNING (check within hours): - Drawdown > 4% (entered CAUTION zone) - Win rate dropped below 50% (rolling 50 trades) - IC below 0.02 (signal quality degrading) - Unusual prediction distribution INFO (daily review): - Daily PnL summary - Trade count and stats - Feature distribution summary Don't over-alert. If you get 100 alerts a day, you'll ignore them all. Focus on actionable alerts that require specific responses.

Hands-On Code

Structured Trading Logger

python
import logging
import json
from datetime import datetime

class TradingLogger:
    """Structured logging for trading system."""
    
    def __init__(self, name='v7_engine'):
        self.logger = logging.getLogger(name)
        handler = logging.FileHandler(f'logs/{name}_{datetime.now():%Y%m%d}.log')
        handler.setFormatter(logging.Formatter(
            '%(asctime)s | %(levelname)s | %(message)s'
        ))
        self.logger.addHandler(handler)
        self.logger.setLevel(logging.INFO)
    
    def log_signal(self, symbol, direction, confidence, l2_decision):
        self.logger.info(json.dumps({
            'event': 'SIGNAL',
            'symbol': symbol,
            'direction': direction,
            'confidence': confidence,
            'l2_decision': l2_decision,
        }))
    
    def log_trade(self, symbol, direction, price, sl, tp, volume, pnl_r=None):
        self.logger.info(json.dumps({
            'event': 'TRADE',
            'symbol': symbol,
            'direction': direction,
            'price': price,
            'sl': sl,
            'tp': tp,
            'volume': volume,
            'pnl_r': pnl_r,
        }))
    
    def log_risk(self, dd_pct, dd_zone, risk_level, daily_r_used):
        level = logging.WARNING if dd_zone != 'NORMAL' else logging.INFO
        self.logger.log(level, json.dumps({
            'event': 'RISK_STATE',
            'drawdown_pct': dd_pct,
            'dd_zone': dd_zone,
            'risk_level': risk_level,
            'daily_r_used': daily_r_used,
        }))
    
    def log_alert(self, severity, message, details=None):
        level = logging.CRITICAL if severity == 'CRITICAL' else logging.WARNING
        self.logger.log(level, json.dumps({
            'event': 'ALERT',
            'severity': severity,
            'message': message,
            'details': details,
        }))

Structured logging (JSON format) makes it easy to parse, search, and analyze logs. Every trade decision should be logged with enough context to reconstruct the reasoning.

Knowledge Check

Q1.Your monitoring shows IC dropped from 0.07 to 0.01 over 2 weeks. What should happen?

Assignment

Implement structured logging for your trading system. Log at least: signals, trades, risk state changes, and errors. Set up 3 alert thresholds (critical, warning, info) and test them.