mirror of
https://github.com/chrisnov-it/quantumbotx.git
synced 2026-07-28 03:07:53 +00:00
a7b99ec1cf
🔧 Core System Improvements: - Enhanced backtesting engine with realistic spread modeling and ATR-based risk management - Improved bot controller with better error handling and status tracking - Optimized MT5 integration with symbol verification and market watch integration - Strengthened database queries with better performance and reliability 🎯 New Strategy Features: - Added index strategies (Index Momentum, Index Breakout Pro) for stock market trading - Implemented market condition detector for dynamic strategy adaptation - Created performance scorer for strategy evaluation and ranking - Added strategy switcher system for automatic strategy optimization 📚 Educational Framework: - New beginner guide documentation for newcomer onboarding - Enhanced FAQ section with common trading questions - Quick start guide for rapid setup and deployment - Improved AI mentor integration with personalized guidance 🌍 Multi-Asset Expansion: - Extended data collection for 20+ trading instruments (Forex, Crypto, Indices) - Enhanced broker compatibility with FBS and other platforms - Improved symbol migration system for seamless broker switching - Added holiday integration for culturally-aware trading automation 🧪 Testing & Validation: - Added comprehensive index strategy testing suite - Enhanced holiday integration validation - Dynamic strategy signal testing for improved reliability - EURUSD optimization testing with London session focus ⚡ Performance & UI: - Frontend JavaScript optimizations for better trading bot management - Enhanced templates with improved user experience - Database migration system for smooth version upgrades - Optimized data download scripts for better efficiency 📊 Analytics & Monitoring: - Strengthened Flask application architecture with better routing - Improved logging system for production deployment - Enhanced error handling across all components - Better API response handling and status reporting
75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
# run.py
|
|
|
|
import os
|
|
import sys
|
|
import atexit
|
|
import logging
|
|
import MetaTrader5 as mt5
|
|
from flask import jsonify
|
|
from core import create_app
|
|
from core.utils.mt5 import initialize_mt5
|
|
from core.bots.controller import shutdown_all_bots, ambil_semua_bot
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
# Konfigurasi logging bersih dari awal
|
|
logging.getLogger('werkzeug').setLevel(logging.WARNING)
|
|
|
|
def shutdown_app():
|
|
"""Fungsi shutdown terpusat."""
|
|
logging.info("Memulai proses shutdown aplikasi...")
|
|
shutdown_all_bots()
|
|
mt5.shutdown() # pyright: ignore[reportAttributeAccessIssue]
|
|
logging.info("Koneksi MetaTrader 5 ditutup. Aplikasi berhenti.")
|
|
|
|
# Panggil pabrik untuk membuat aplikasi kita
|
|
app = create_app()
|
|
|
|
@app.route('/api/health')
|
|
def health_check():
|
|
"""Endpoint untuk memastikan server berjalan."""
|
|
return jsonify({"status": "ok", "message": "Server is running"})
|
|
|
|
if __name__ == '__main__':
|
|
# --- Inisialisasi MT5 Terpusat ---
|
|
# Dilakukan di sini untuk memastikan hanya berjalan sekali.
|
|
try:
|
|
# Ambil kredensial MT5 dari environment variables dengan validasi
|
|
account_str = os.getenv('MT5_LOGIN')
|
|
password = os.getenv('MT5_PASSWORD')
|
|
server = os.getenv('MT5_SERVER', 'MetaQuotes-Demo')
|
|
|
|
# Validasi kredensial tidak kosong
|
|
if not account_str or not password:
|
|
logging.error("Error: MT5_LOGIN dan MT5_PASSWORD harus diisi di file .env")
|
|
sys.exit(1)
|
|
|
|
# Convert account to integer dengan error handling
|
|
try:
|
|
account = int(account_str)
|
|
except ValueError:
|
|
logging.error(f"Error: MT5_LOGIN harus berupa angka, ditemukan: {account_str}")
|
|
sys.exit(1)
|
|
|
|
if initialize_mt5(account, password, server):
|
|
logging.info("Koneksi MT5 berhasil diinisialisasi dari run.py.")
|
|
|
|
# Load bots - automatic broker migration happens here
|
|
ambil_semua_bot()
|
|
atexit.register(shutdown_app) # Daftarkan shutdown HANYA jika koneksi berhasil
|
|
else:
|
|
logging.error("Error: Gagal terhubung ke MT5. Pastikan MT5 terminal berjalan dan kredensial benar.")
|
|
sys.exit(1)
|
|
except Exception as e:
|
|
logging.critical(
|
|
f"GAGAL total saat inisialisasi MT5 di run.py: {e}",
|
|
exc_info=True
|
|
)
|
|
|
|
app.run(
|
|
debug=os.getenv('FLASK_DEBUG', 'False').lower() == 'true',
|
|
host=os.getenv('FLASK_HOST', '127.0.0.1'),
|
|
port=int(os.getenv('FLASK_PORT', 5000)),
|
|
use_reloader=False
|
|
) |