删除中控下单区
This commit is contained in:
+11
-108
@@ -1,6 +1,6 @@
|
||||
"""
|
||||
多账户交易中控:监控区 / 下单区 / 系统设置。
|
||||
转发至各 crypto_monitor_* 的 /api/hub/* 与子代理 /status。
|
||||
多账户交易中控:监控区 / 系统设置。
|
||||
聚合各实例监控数据与子代理 /status;下单请在各实例网页操作。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -9,7 +9,7 @@ import os
|
||||
from pathlib import Path
|
||||
|
||||
import httpx
|
||||
from fastapi import Body, FastAPI, HTTPException, Query, Request
|
||||
from fastapi import Body, FastAPI, HTTPException, Request
|
||||
from fastapi.responses import FileResponse, JSONResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from pydantic import BaseModel, Field
|
||||
@@ -114,12 +114,18 @@ def root_redirect():
|
||||
|
||||
|
||||
@app.get("/monitor")
|
||||
@app.get("/trade")
|
||||
@app.get("/settings")
|
||||
def shell_pages():
|
||||
return _shell_page()
|
||||
|
||||
|
||||
@app.get("/trade")
|
||||
def trade_removed_redirect():
|
||||
from fastapi.responses import RedirectResponse
|
||||
|
||||
return RedirectResponse("/monitor", status_code=302)
|
||||
|
||||
|
||||
@app.get("/api/settings")
|
||||
def api_get_settings():
|
||||
return load_settings()
|
||||
@@ -142,7 +148,7 @@ def api_settings_meta():
|
||||
return {
|
||||
"env_disabled_ids": sorted(env_force_disabled_ids()),
|
||||
"hub_bridge_token_set": bool(HUB_BRIDGE_TOKEN),
|
||||
"capability_options": ["order", "key", "trend"],
|
||||
"capability_options": ["key", "trend"],
|
||||
"public_origin": f"{po[0]}://{po[1]}" if po else None,
|
||||
"public_origin_hint": (
|
||||
"未设置 HUB_PUBLIC_ORIGIN 时,复盘链接若为 127.0.0.1,仅服务器本机浏览器可打开"
|
||||
@@ -182,25 +188,6 @@ async def _fetch_agent_status(client: httpx.AsyncClient, ex: dict) -> dict:
|
||||
}
|
||||
|
||||
|
||||
def _exchange_brief(ex: dict | None) -> dict | None:
|
||||
if not ex:
|
||||
return None
|
||||
return {
|
||||
"id": ex.get("id"),
|
||||
"key": ex.get("key"),
|
||||
"name": ex.get("name"),
|
||||
}
|
||||
|
||||
|
||||
def _form_plain_dict(form) -> dict[str, str]:
|
||||
out: dict[str, str] = {}
|
||||
for k, v in form.multi_items() if hasattr(form, "multi_items") else form.items():
|
||||
if hasattr(v, "read"):
|
||||
continue
|
||||
out[str(k)] = "" if v is None else str(v)
|
||||
return out
|
||||
|
||||
|
||||
def _parse_http_json_body(r: httpx.Response) -> dict:
|
||||
text = (r.text or "").strip()
|
||||
if not text:
|
||||
@@ -336,90 +323,6 @@ async def api_close_all(body: CloseAllBody | None = Body(default=None)):
|
||||
return {"results": list(results)}
|
||||
|
||||
|
||||
@app.get("/api/trade/meta/{exchange_id}")
|
||||
async def api_trade_meta(exchange_id: str):
|
||||
ex = _find_exchange(exchange_id)
|
||||
if not ex or not ex.get("enabled"):
|
||||
raise HTTPException(status_code=404, detail="账户未启用")
|
||||
async with httpx.AsyncClient() as client:
|
||||
meta = await _fetch_flask_json(client, ex, "/api/hub/meta")
|
||||
return {"exchange": ex, "meta": meta}
|
||||
|
||||
|
||||
@app.post("/api/trade/order/{exchange_id}")
|
||||
async def api_trade_order(exchange_id: str, request: Request):
|
||||
ex = _find_exchange(exchange_id)
|
||||
if not ex or not ex.get("enabled"):
|
||||
raise HTTPException(status_code=404, detail="账户未启用")
|
||||
try:
|
||||
form = _form_plain_dict(await request.form())
|
||||
async with httpx.AsyncClient() as client:
|
||||
result = await _fetch_flask_json(client, ex, "/api/hub/add_order", "POST", form)
|
||||
return {"exchange": _exchange_brief(ex), "result": result}
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
return JSONResponse(
|
||||
{"exchange": _exchange_brief(ex), "result": {"ok": False, "messages": [str(e)]}},
|
||||
status_code=200,
|
||||
)
|
||||
|
||||
|
||||
@app.post("/api/trade/key/{exchange_id}")
|
||||
async def api_trade_key(exchange_id: str, request: Request):
|
||||
ex = _find_exchange(exchange_id)
|
||||
if not ex or not ex.get("enabled"):
|
||||
raise HTTPException(status_code=404, detail="账户未启用")
|
||||
if "key" not in (ex.get("capabilities") or []):
|
||||
raise HTTPException(status_code=400, detail="该账户不支持关键位")
|
||||
try:
|
||||
form = _form_plain_dict(await request.form())
|
||||
async with httpx.AsyncClient() as client:
|
||||
result = await _fetch_flask_json(client, ex, "/api/hub/add_key", "POST", form)
|
||||
return {"exchange": _exchange_brief(ex), "result": result}
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
return JSONResponse(
|
||||
{"exchange": _exchange_brief(ex), "result": {"ok": False, "messages": [str(e)]}},
|
||||
status_code=200,
|
||||
)
|
||||
|
||||
|
||||
@app.post("/api/trade/trend/preview/{exchange_id}")
|
||||
async def api_trade_trend_preview(exchange_id: str, request: Request):
|
||||
ex = _find_exchange(exchange_id)
|
||||
if not ex or not ex.get("enabled"):
|
||||
raise HTTPException(status_code=404, detail="账户未启用")
|
||||
if "trend" not in (ex.get("capabilities") or []):
|
||||
raise HTTPException(status_code=400, detail="该账户不支持趋势回调")
|
||||
form = await request.form()
|
||||
async with httpx.AsyncClient() as client:
|
||||
result = await _fetch_flask_json(client, ex, "/api/hub/trend/preview", "POST", dict(form))
|
||||
return {"exchange": ex, "result": result}
|
||||
|
||||
|
||||
@app.post("/api/trade/trend/execute/{exchange_id}")
|
||||
async def api_trade_trend_execute(exchange_id: str, request: Request):
|
||||
ex = _find_exchange(exchange_id)
|
||||
if not ex or not ex.get("enabled"):
|
||||
raise HTTPException(status_code=404, detail="账户未启用")
|
||||
form = await request.form()
|
||||
async with httpx.AsyncClient() as client:
|
||||
result = await _fetch_flask_json(client, ex, "/api/hub/trend/execute", "POST", dict(form))
|
||||
return {"exchange": ex, "result": result}
|
||||
|
||||
|
||||
@app.get("/api/trade/trend/preview/{exchange_id}/{preview_id}")
|
||||
async def api_trade_trend_preview_get(exchange_id: str, preview_id: str):
|
||||
ex = _find_exchange(exchange_id)
|
||||
if not ex or not ex.get("enabled"):
|
||||
raise HTTPException(status_code=404, detail="账户未启用")
|
||||
async with httpx.AsyncClient() as client:
|
||||
result = await _fetch_flask_json(client, ex, f"/api/hub/trend/preview/{preview_id}")
|
||||
return {"exchange": ex, "result": result}
|
||||
|
||||
|
||||
def main():
|
||||
import uvicorn
|
||||
|
||||
|
||||
Reference in New Issue
Block a user