from __future__ import annotations from aureon_baton_link import link_system as _baton_link; _baton_link(__name__) from flask import Flask, jsonify, redirect, render_template_string, request, url_for from .trading_runtime import TradingService HTML_TEMPLATE = """ Aureon Dashboard

Aureon Local Dashboard

Connection Status: {{ 'Running' if running else 'Stopped' }}

Controls

{% if running %} {% else %} {% endif %}

Session

Exchange: {{ config.exchange }}

Pair: {{ config.base_asset }}/{{ config.quote_asset }}

Mode: {{ config.mode }} | Trade size: {{ config.trade_size }}

P&L

{{ pnl }}

Positions

{% if positions %} {% else %}

No open positions.

{% endif %}

Logs

{{ logs }}
""" def create_app(service: TradingService) -> Flask: app = Flask(__name__) @app.route("/") def index(): state = service.state return render_template_string( HTML_TEMPLATE, running=state.running, pnl=round(state.pnl, 2), positions=state.positions, logs="\n".join(state.logs[-20:]), config=service.config, ) @app.route("/toggle", methods=["POST"]) def toggle(): action = request.form.get("action", "") if action == "start": service.start() elif action == "stop": service.stop() return redirect(url_for("index")) @app.route("/api/status") def api_status(): state = service.state return jsonify( { "running": state.running, "pnl": round(state.pnl, 2), "positions": [pos.__dict__ for pos in state.positions], "logs": state.logs[-50:], "config": { "exchange": service.config.exchange, "pair": f"{service.config.base_asset}/{service.config.quote_asset}", "mode": service.config.mode, "trade_size": service.config.trade_size, }, } ) return app __all__ = ["create_app"]