-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (46 loc) · 1.67 KB
/
Copy pathmain.py
File metadata and controls
59 lines (46 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""Cloud Run / local entrypoint for QMT platform dry-run cycles."""
from __future__ import annotations
import os
import traceback
from flask import Flask, jsonify
from application.dry_run_service import run_dry_run_cycle
from application.qmt_client import QmtBrokerClient
from runtime_config_support import load_platform_runtime_settings
from strategy_registry import get_platform_profile_status_matrix
app = Flask(__name__)
@app.get("/probe")
def probe():
settings = load_platform_runtime_settings()
return jsonify(
{
"status": "ok",
"platform_id": "qmt",
"strategy_profile": settings.strategy_profile,
"dry_run_only": settings.dry_run_only,
}
)
@app.get("/profiles")
def profiles():
return jsonify({"profiles": get_platform_profile_status_matrix()})
@app.route("/dry-run", methods=["GET", "POST"])
def dry_run():
settings = load_platform_runtime_settings()
effective_settings = settings
if not settings.dry_run_only:
effective_settings = settings.__class__(
**{
**settings.__dict__,
"dry_run_only": True,
}
)
try:
client = QmtBrokerClient(
market_history_path=effective_settings.market_history_path
or os.getenv("QMT_MARKET_HISTORY_PATH"),
)
report = run_dry_run_cycle(runtime_settings=effective_settings, client=client)
return jsonify(report)
except Exception as exc:
return jsonify({"status": "error", "error": str(exc), "traceback": traceback.format_exc()}), 500
if __name__ == "__main__":
app.run(host="0.0.0.0", port=int(os.getenv("PORT", "8080")))