Add hub strategy compare page for perp vs options vs 7:3 hedge.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-23 14:39:59 +08:00
parent b6156e0049
commit ed3033d793
9 changed files with 1094 additions and 2 deletions
+43
View File
@@ -991,6 +991,7 @@ def root_redirect():
@app.get("/monitor")
@app.get("/plan")
@app.get("/calculator")
@app.get("/compare")
@app.get("/market")
@app.get("/archive")
@app.get("/quotes")
@@ -1113,6 +1114,7 @@ class SettingsDisplayBody(BaseModel):
show_nav_quotes: bool = True
show_nav_ai: bool = True
show_nav_calculator: bool = True
show_nav_compare: bool = True
show_nav_strategy: bool = True
show_nav_amp_stats: bool = True
show_nav_help: bool = True
@@ -1212,6 +1214,27 @@ class RollCalculatorBody(BaseModel):
base: str = "ETH"
class CompareOptionLegBody(BaseModel):
opt_type: str = "C"
strike: float | None = None
ask: float | None = None
class CompareBody(BaseModel):
base: str = "ETH"
direction: str = "long"
entry: float = Field(gt=0)
sl: float = Field(gt=0)
tp: float = Field(gt=0)
risk_u: float = Field(gt=0)
tp_opt: float | None = None
tp_hedge: float | None = None
contract_size: float | None = None
ct_mult: float | None = None
option: CompareOptionLegBody | None = None
hedge: dict | None = None
@app.get("/api/calculator/exchanges")
def api_calculator_exchanges():
from lib.hub.hub_calculator_market_lib import list_calculator_exchanges
@@ -1272,6 +1295,26 @@ def api_calculator_roll(body: RollCalculatorBody):
return {"ok": True, "data": data}
@app.post("/api/compare/calc")
def api_compare_calc(body: CompareBody):
from lib.hub.hub_compare_lib import run_compare
payload = body.model_dump()
hedge = payload.get("hedge") if isinstance(payload.get("hedge"), dict) else {}
# normalize hedge legs from nested dicts
if hedge:
payload["hedge"] = {
"main": hedge.get("main") if isinstance(hedge.get("main"), dict) else {},
"side": hedge.get("side") if isinstance(hedge.get("side"), dict) else {},
}
if payload.get("option") is None:
payload["option"] = {}
data = run_compare(payload)
if not data.get("ok"):
return JSONResponse(data, status_code=400)
return data
def _find_exchange_by_key(exchange_key: str) -> dict | None:
key = (exchange_key or "").strip().lower()
if not key: