feat(v0.1.0): project foundation with logging and config
This commit is contained in:
101
config/alerts.yaml
Normal file
101
config/alerts.yaml
Normal file
@@ -0,0 +1,101 @@
|
||||
# Alert System Configuration
|
||||
|
||||
enabled: true
|
||||
default_channel: "telegram" # telegram, slack, email, all
|
||||
|
||||
telegram:
|
||||
enabled: true
|
||||
bot_token: "${TELEGRAM_BOT_TOKEN}"
|
||||
chat_id: "${TELEGRAM_CHAT_ID}"
|
||||
|
||||
alerts:
|
||||
pattern_detected: true
|
||||
high_grade_pattern: true # Grade 4-5 patterns only
|
||||
setup_complete: true
|
||||
trade_executed: true
|
||||
trade_closed: true
|
||||
daily_summary: true
|
||||
|
||||
rate_limit:
|
||||
max_alerts_per_minute: 10
|
||||
max_alerts_per_hour: 50
|
||||
|
||||
slack:
|
||||
enabled: false
|
||||
webhook_url: "${SLACK_WEBHOOK_URL}"
|
||||
|
||||
alerts:
|
||||
pattern_detected: false
|
||||
high_grade_pattern: true
|
||||
setup_complete: true
|
||||
trade_executed: true
|
||||
trade_closed: true
|
||||
daily_summary: true
|
||||
|
||||
rate_limit:
|
||||
max_alerts_per_minute: 5
|
||||
max_alerts_per_hour: 30
|
||||
|
||||
email:
|
||||
enabled: false
|
||||
smtp_host: "${SMTP_HOST}"
|
||||
smtp_port: "${SMTP_PORT}"
|
||||
smtp_user: "${SMTP_USER}"
|
||||
smtp_password: "${SMTP_PASSWORD}"
|
||||
from_address: "${EMAIL_FROM}"
|
||||
to_addresses:
|
||||
- "${EMAIL_TO}"
|
||||
|
||||
alerts:
|
||||
pattern_detected: false
|
||||
high_grade_pattern: false
|
||||
setup_complete: true
|
||||
trade_executed: true
|
||||
trade_closed: true
|
||||
daily_summary: true
|
||||
|
||||
rate_limit:
|
||||
max_emails_per_hour: 5
|
||||
|
||||
# Alert message templates
|
||||
templates:
|
||||
pattern_detected: |
|
||||
🎯 Pattern Detected: {pattern_type}
|
||||
Grade: {grade}/5
|
||||
Symbol: {symbol}
|
||||
Time: {timestamp}
|
||||
Price: {price}
|
||||
|
||||
high_grade_pattern: |
|
||||
⭐ High Grade Pattern: {pattern_type}
|
||||
Grade: {grade}/5
|
||||
Confidence: {confidence}%
|
||||
Symbol: {symbol}
|
||||
Time: {timestamp}
|
||||
|
||||
setup_complete: |
|
||||
✅ Setup Complete: {setup_type}
|
||||
Patterns: {patterns}
|
||||
Confidence: {confidence}%
|
||||
Entry Signal: {signal}
|
||||
|
||||
trade_executed: |
|
||||
📈 Trade Executed
|
||||
Type: {trade_type}
|
||||
Entry: {entry_price}
|
||||
Stop Loss: {stop_loss}
|
||||
Take Profit: {take_profit}
|
||||
Size: {size} contracts
|
||||
|
||||
trade_closed: |
|
||||
📊 Trade Closed
|
||||
P&L: {pnl} EUR
|
||||
Return: {return_pct}%
|
||||
Duration: {duration}
|
||||
|
||||
# Alert filtering
|
||||
filters:
|
||||
min_pattern_grade: 3 # Only alert on grade 3+ patterns
|
||||
min_setup_confidence: 0.70
|
||||
only_live_trading: false # If true, only alert during live trading hours
|
||||
|
||||
53
config/config.yaml
Normal file
53
config/config.yaml
Normal file
@@ -0,0 +1,53 @@
|
||||
# Main Application Configuration
|
||||
|
||||
app:
|
||||
name: "ICT ML Trading System"
|
||||
version: "0.1.0"
|
||||
environment: "${ENVIRONMENT:-development}"
|
||||
debug: "${DEBUG:-false}"
|
||||
|
||||
# Trading Session Configuration
|
||||
trading:
|
||||
session:
|
||||
start_time: "03:00" # EST
|
||||
end_time: "04:00" # EST
|
||||
timezone: "America/New_York"
|
||||
|
||||
instrument:
|
||||
symbol: "DEUIDXEUR"
|
||||
exchange: "EUREX"
|
||||
contract_size: 25 # EUR per point
|
||||
|
||||
# Data Configuration
|
||||
data:
|
||||
raw_data_path: "data/raw"
|
||||
processed_data_path: "data/processed"
|
||||
labels_path: "data/labels"
|
||||
screenshots_path: "data/screenshots"
|
||||
|
||||
timeframes:
|
||||
- "1min"
|
||||
- "5min"
|
||||
- "15min"
|
||||
|
||||
retention:
|
||||
raw_data_days: 730 # 24 months
|
||||
processed_data_days: 365 # 12 months
|
||||
screenshots_days: 180 # 6 months
|
||||
|
||||
# Model Configuration
|
||||
models:
|
||||
base_path: "models"
|
||||
pattern_graders_path: "models/pattern_graders"
|
||||
strategy_models_path: "models/strategy_models"
|
||||
|
||||
min_labels_per_pattern: 200
|
||||
train_test_split: 0.8
|
||||
validation_split: 0.1
|
||||
|
||||
# Logging Configuration (see config/logging.yaml for detailed settings)
|
||||
logging:
|
||||
level: "${LOG_LEVEL:-INFO}"
|
||||
format: "${LOG_FORMAT:-json}"
|
||||
log_dir: "logs"
|
||||
|
||||
40
config/database.yaml
Normal file
40
config/database.yaml
Normal file
@@ -0,0 +1,40 @@
|
||||
# Database Configuration
|
||||
|
||||
# Database URL (can be overridden by DATABASE_URL environment variable)
|
||||
database_url: "${DATABASE_URL:-sqlite:///data/ict_trading.db}"
|
||||
|
||||
# Connection pool settings
|
||||
pool_size: 10
|
||||
max_overflow: 20
|
||||
pool_timeout: 30
|
||||
pool_recycle: 3600 # Recycle connections after 1 hour
|
||||
|
||||
# SQLAlchemy settings
|
||||
echo: false # Set to true for SQL query logging
|
||||
echo_pool: false
|
||||
|
||||
# Database-specific settings
|
||||
sqlite:
|
||||
# SQLite-specific settings
|
||||
check_same_thread: false
|
||||
timeout: 20
|
||||
|
||||
postgresql:
|
||||
# PostgreSQL-specific settings
|
||||
connect_args:
|
||||
connect_timeout: 10
|
||||
application_name: "ict_ml_trading"
|
||||
|
||||
# Migration settings
|
||||
alembic:
|
||||
script_location: "alembic"
|
||||
version_path_separator: "os"
|
||||
sqlalchemy.url: "${DATABASE_URL:-sqlite:///data/ict_trading.db}"
|
||||
|
||||
# Backup settings
|
||||
backup:
|
||||
enabled: true
|
||||
frequency: "daily" # daily, weekly
|
||||
retention_days: 30
|
||||
backup_path: "backups/database"
|
||||
|
||||
74
config/detectors.yaml
Normal file
74
config/detectors.yaml
Normal file
@@ -0,0 +1,74 @@
|
||||
# Pattern Detector Configuration
|
||||
|
||||
fvg_detector:
|
||||
enabled: true
|
||||
min_gap_size_pips: 5 # Minimum gap size in pips
|
||||
max_gap_age_bars: 50 # Maximum bars before gap is considered invalid
|
||||
require_confirmation: true # Require price to touch gap zone
|
||||
|
||||
bullish:
|
||||
min_body_size_ratio: 0.6 # Minimum body size relative to candle
|
||||
min_gap_size_ratio: 0.3 # Minimum gap relative to ATR
|
||||
|
||||
bearish:
|
||||
min_body_size_ratio: 0.6
|
||||
min_gap_size_ratio: 0.3
|
||||
|
||||
order_block_detector:
|
||||
enabled: true
|
||||
lookback_bars: 20 # Bars to look back for BOS
|
||||
min_candle_size_ratio: 0.5 # Minimum candle size relative to ATR
|
||||
require_structure_break: true # Require BOS before OB
|
||||
|
||||
bullish:
|
||||
min_body_size_ratio: 0.7
|
||||
max_wick_ratio: 0.3 # Maximum wick size relative to body
|
||||
|
||||
bearish:
|
||||
min_body_size_ratio: 0.7
|
||||
max_wick_ratio: 0.3
|
||||
|
||||
liquidity_detector:
|
||||
enabled: true
|
||||
swing_lookback: 10 # Bars to look back for swing points
|
||||
min_swing_size_pips: 10
|
||||
sweep_tolerance_pips: 2 # Tolerance for sweep detection
|
||||
|
||||
bullish_sweep:
|
||||
require_reversal: true
|
||||
min_reversal_size_ratio: 0.5
|
||||
|
||||
bearish_sweep:
|
||||
require_reversal: true
|
||||
min_reversal_size_ratio: 0.5
|
||||
|
||||
premium_discount:
|
||||
enabled: true
|
||||
calculation_method: "session_range" # session_range or daily_range
|
||||
session_start_time: "03:00"
|
||||
session_end_time: "04:00"
|
||||
|
||||
levels:
|
||||
premium_threshold: 0.618 # Fibonacci level
|
||||
discount_threshold: 0.382
|
||||
equilibrium_level: 0.500
|
||||
|
||||
structure_detector:
|
||||
enabled: true
|
||||
swing_period: 10 # Period for swing detection
|
||||
min_structure_size_pips: 15
|
||||
|
||||
bos:
|
||||
require_confirmation: true
|
||||
confirmation_bars: 2
|
||||
|
||||
choch:
|
||||
require_confirmation: true
|
||||
confirmation_bars: 2
|
||||
|
||||
scanner:
|
||||
run_parallel: false # Run detectors in parallel (experimental)
|
||||
save_detections: true
|
||||
generate_screenshots: false # Set to true for labeling workflow
|
||||
screenshot_path: "data/screenshots/patterns"
|
||||
|
||||
98
config/logging.yaml
Normal file
98
config/logging.yaml
Normal file
@@ -0,0 +1,98 @@
|
||||
version: 1
|
||||
disable_existing_loggers: false
|
||||
|
||||
formatters:
|
||||
json:
|
||||
class: pythonjsonlogger.jsonlogger.JsonFormatter
|
||||
format: '%(asctime)s %(name)s %(levelname)s %(message)s %(pathname)s %(lineno)d'
|
||||
datefmt: '%Y-%m-%d %H:%M:%S'
|
||||
|
||||
detailed:
|
||||
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s - [%(pathname)s:%(lineno)d]'
|
||||
datefmt: '%Y-%m-%d %H:%M:%S'
|
||||
|
||||
colored:
|
||||
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||
datefmt: '%Y-%m-%d %H:%M:%S'
|
||||
# Note: ColoredFormatter requires colorlog package
|
||||
# Falls back to standard formatter if colorlog not available
|
||||
|
||||
handlers:
|
||||
console:
|
||||
class: logging.StreamHandler
|
||||
level: INFO
|
||||
formatter: colored
|
||||
stream: ext://sys.stdout
|
||||
filters:
|
||||
- sensitive_data_filter
|
||||
|
||||
application_file:
|
||||
class: logging.handlers.RotatingFileHandler
|
||||
level: DEBUG
|
||||
formatter: json
|
||||
filename: logs/application/app.log
|
||||
maxBytes: 10485760 # 10MB
|
||||
backupCount: 5
|
||||
encoding: utf-8
|
||||
filters:
|
||||
- sensitive_data_filter
|
||||
|
||||
error_file:
|
||||
class: logging.handlers.RotatingFileHandler
|
||||
level: ERROR
|
||||
formatter: json
|
||||
filename: logs/errors/exceptions.log
|
||||
maxBytes: 10485760 # 10MB
|
||||
backupCount: 5
|
||||
encoding: utf-8
|
||||
filters:
|
||||
- sensitive_data_filter
|
||||
|
||||
critical_file:
|
||||
class: logging.handlers.RotatingFileHandler
|
||||
level: CRITICAL
|
||||
formatter: json
|
||||
filename: logs/errors/critical.log
|
||||
maxBytes: 10485760 # 10MB
|
||||
backupCount: 10
|
||||
encoding: utf-8
|
||||
filters:
|
||||
- sensitive_data_filter
|
||||
|
||||
loggers:
|
||||
src:
|
||||
level: DEBUG
|
||||
handlers:
|
||||
- console
|
||||
- application_file
|
||||
- error_file
|
||||
- critical_file
|
||||
propagate: false
|
||||
|
||||
src.detectors:
|
||||
level: DEBUG
|
||||
handlers:
|
||||
- console
|
||||
- application_file
|
||||
propagate: false
|
||||
|
||||
src.models:
|
||||
level: DEBUG
|
||||
handlers:
|
||||
- console
|
||||
- application_file
|
||||
propagate: false
|
||||
|
||||
src.trading:
|
||||
level: INFO
|
||||
handlers:
|
||||
- console
|
||||
- application_file
|
||||
propagate: false
|
||||
|
||||
root:
|
||||
level: INFO
|
||||
handlers:
|
||||
- console
|
||||
- application_file
|
||||
|
||||
87
config/models.yaml
Normal file
87
config/models.yaml
Normal file
@@ -0,0 +1,87 @@
|
||||
# Machine Learning Model Configuration
|
||||
|
||||
pattern_graders:
|
||||
# Individual pattern grading models
|
||||
base_model_type: "RandomForestClassifier" # RandomForestClassifier, XGBoostClassifier
|
||||
|
||||
random_forest:
|
||||
n_estimators: 100
|
||||
max_depth: 10
|
||||
min_samples_split: 5
|
||||
min_samples_leaf: 2
|
||||
max_features: "sqrt"
|
||||
random_state: 42
|
||||
n_jobs: -1
|
||||
|
||||
xgboost:
|
||||
n_estimators: 100
|
||||
max_depth: 6
|
||||
learning_rate: 0.1
|
||||
subsample: 0.8
|
||||
colsample_bytree: 0.8
|
||||
random_state: 42
|
||||
|
||||
# Feature selection
|
||||
feature_selection:
|
||||
enabled: true
|
||||
method: "mutual_info" # mutual_info, f_test, chi2
|
||||
top_k_features: 50
|
||||
|
||||
# Training configuration
|
||||
training:
|
||||
cv_folds: 5
|
||||
scoring_metric: "f1_weighted"
|
||||
early_stopping: true
|
||||
patience: 10
|
||||
|
||||
setup_classifier:
|
||||
# Meta-model for complete setup classification
|
||||
model_type: "RandomForestClassifier"
|
||||
|
||||
# Strategy types
|
||||
strategies:
|
||||
continuation:
|
||||
time_window_start: "03:00"
|
||||
time_window_end: "03:15"
|
||||
min_pattern_count: 2
|
||||
required_patterns: ["fvg", "order_block"]
|
||||
|
||||
reversal:
|
||||
time_window_start: "03:30"
|
||||
time_window_end: "03:50"
|
||||
min_pattern_count: 2
|
||||
required_patterns: ["fvg", "liquidity"]
|
||||
|
||||
# Model evaluation
|
||||
evaluation:
|
||||
metrics:
|
||||
- "accuracy"
|
||||
- "precision"
|
||||
- "recall"
|
||||
- "f1_score"
|
||||
- "roc_auc"
|
||||
|
||||
min_accuracy_threshold: 0.75
|
||||
min_precision_threshold: 0.70
|
||||
min_recall_threshold: 0.65
|
||||
|
||||
# Hyperparameter tuning
|
||||
tuning:
|
||||
enabled: false
|
||||
method: "grid_search" # grid_search, random_search, optuna
|
||||
n_iter: 50
|
||||
cv_folds: 5
|
||||
|
||||
grid_search:
|
||||
param_grids:
|
||||
random_forest:
|
||||
n_estimators: [50, 100, 200]
|
||||
max_depth: [5, 10, 15]
|
||||
min_samples_split: [2, 5, 10]
|
||||
|
||||
# Model registry
|
||||
registry:
|
||||
track_versions: true
|
||||
auto_promote: false # Auto-promote best model to "latest"
|
||||
min_improvement: 0.02 # Minimum improvement to promote (2%)
|
||||
|
||||
86
config/trading.yaml
Normal file
86
config/trading.yaml
Normal file
@@ -0,0 +1,86 @@
|
||||
# Trading Strategy Configuration
|
||||
|
||||
risk_management:
|
||||
max_position_size: 1 # Maximum number of contracts
|
||||
max_daily_loss: 500 # Maximum daily loss in EUR
|
||||
max_drawdown: 0.10 # Maximum drawdown (10%)
|
||||
|
||||
position_sizing:
|
||||
method: "fixed" # fixed, kelly, risk_percentage
|
||||
fixed_size: 1
|
||||
risk_percentage: 0.02 # 2% of account per trade
|
||||
kelly_fraction: 0.25 # Fraction of Kelly criterion
|
||||
|
||||
stop_loss:
|
||||
method: "atr_multiple" # atr_multiple, fixed_pips, pattern_based
|
||||
atr_multiple: 2.0
|
||||
fixed_pips: 20
|
||||
min_stop_pips: 10
|
||||
max_stop_pips: 50
|
||||
|
||||
take_profit:
|
||||
method: "risk_reward" # risk_reward, fixed_pips, pattern_based
|
||||
risk_reward_ratio: 2.0
|
||||
fixed_pips: 40
|
||||
min_tp_pips: 20
|
||||
|
||||
entry_rules:
|
||||
# Minimum model confidence for entry
|
||||
min_pattern_grade: 4 # Grade 4 or 5 required
|
||||
min_setup_confidence: 0.75
|
||||
|
||||
# Pattern requirements
|
||||
required_patterns:
|
||||
continuation: ["fvg", "order_block"]
|
||||
reversal: ["fvg", "liquidity"]
|
||||
|
||||
# Market structure requirements
|
||||
require_bos: true
|
||||
require_htf_alignment: false # Higher timeframe alignment
|
||||
|
||||
# Premium/Discount filter
|
||||
premium_discount_filter: true
|
||||
only_trade_premium_discount: false # If true, only trade in premium/discount zones
|
||||
|
||||
exit_rules:
|
||||
# Exit on pattern invalidation
|
||||
exit_on_fvg_fill: true
|
||||
exit_on_ob_break: true
|
||||
|
||||
# Time-based exit
|
||||
max_hold_time_minutes: 60
|
||||
exit_at_session_end: true
|
||||
|
||||
# Trailing stop
|
||||
trailing_stop_enabled: false
|
||||
trailing_stop_atr_multiple: 1.5
|
||||
|
||||
execution:
|
||||
# Order types
|
||||
entry_order_type: "market" # market, limit
|
||||
limit_order_offset_pips: 2
|
||||
|
||||
# Slippage and fees
|
||||
assumed_slippage_pips: 1
|
||||
commission_per_contract: 2.5 # EUR per contract
|
||||
|
||||
# Execution delays (for backtesting)
|
||||
execution_delay_seconds: 1
|
||||
|
||||
session:
|
||||
# Trading session times (EST)
|
||||
start_time: "03:00"
|
||||
end_time: "04:00"
|
||||
timezone: "America/New_York"
|
||||
|
||||
# Day of week filters
|
||||
trade_monday: true
|
||||
trade_tuesday: true
|
||||
trade_wednesday: true
|
||||
trade_thursday: true
|
||||
trade_friday: true
|
||||
|
||||
# Economic calendar filters (optional)
|
||||
avoid_high_impact_news: false
|
||||
news_buffer_minutes: 15
|
||||
|
||||
Reference in New Issue
Block a user