feat(ui): strategy config form and backend endpoint

This commit is contained in:
2026-02-07 08:06:27 +08:00
parent f30bcdc680
commit 06081aa939
3 changed files with 102 additions and 15 deletions

28
app.py
View File

@@ -5,7 +5,7 @@ Provides mock metrics for PnL, drawdown, and win rate.
"""
from flask import Flask, render_template, jsonify, request
import random
import os
from datetime import datetime, timedelta
from data.connectors import create_moomoo_client, Interval
@@ -14,6 +14,8 @@ app = Flask(__name__)
# Initialize MoomooClient in mock mode (using our LLM scenario generator)
client = create_moomoo_client(mock_mode=True)
STRATEGY_CONFIG_PATH = os.path.join(os.path.dirname(__file__), 'data', 'strategy_configs.json')
@app.route('/')
def dashboard():
"""Serve the dashboard HTML page."""
@@ -91,6 +93,30 @@ def market_data(symbol):
except Exception as e:
return jsonify({'error': str(e)}), 500
@app.route('/api/strategy-config', methods=['POST'])
def save_strategy_config():
"""Save strategy configuration to a JSON file (simple local persistence)."""
try:
data = request.get_json(force=True) or {}
os.makedirs(os.path.join(os.path.dirname(__file__), 'data'), exist_ok=True)
configs = []
if os.path.exists(STRATEGY_CONFIG_PATH):
import json as _json
with open(STRATEGY_CONFIG_PATH, 'r') as f:
try:
configs = _json.load(f)
except Exception:
configs = []
# Append with timestamp
data['savedAt'] = datetime.now().isoformat()
configs.append(data)
import json
with open(STRATEGY_CONFIG_PATH, 'w') as f:
json.dump(configs, f, indent=2)
return jsonify({'status': 'ok', 'count': len(configs)})
except Exception as e:
return jsonify({'status': 'error', 'error': str(e)}), 500
@app.route('/health')
def health():
"""Health check endpoint."""