117 lines
3.9 KiB
Python
117 lines
3.9 KiB
Python
from fastapi import APIRouter, Cookie, HTTPException
|
|
|
|
from app.db.paper_trading import (
|
|
delete_paper_order,
|
|
delete_paper_trade,
|
|
get_paper_trading_performance,
|
|
get_paper_trading_summary,
|
|
list_paper_orders,
|
|
list_paper_trade_events,
|
|
list_paper_trades,
|
|
reset_paper_trading_data,
|
|
send_paper_trading_report,
|
|
)
|
|
from app.db.intraday_frequency import get_intraday_frequency_health
|
|
from app.db.strategy_insights import get_strategy_evaluation
|
|
from app.web.shared import require_admin
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/api/paper-trading/summary")
|
|
async def api_paper_trading_summary(days: int = 30, altcoin_session: str = Cookie(default="")):
|
|
require_admin(altcoin_session)
|
|
return get_paper_trading_summary(days=days)
|
|
|
|
|
|
@router.get("/api/paper-trading/frequency-health")
|
|
async def api_paper_trading_frequency_health(days: int = 7, altcoin_session: str = Cookie(default="")):
|
|
require_admin(altcoin_session)
|
|
return get_intraday_frequency_health(days=days)
|
|
|
|
|
|
@router.get("/api/paper-trading/performance")
|
|
async def api_paper_trading_performance(days: int = 30, altcoin_session: str = Cookie(default="")):
|
|
require_admin(altcoin_session)
|
|
return get_paper_trading_performance(days=days)
|
|
|
|
|
|
@router.get("/api/paper-trading/strategies")
|
|
async def api_paper_trading_strategies(days: int = 30, altcoin_session: str = Cookie(default="")):
|
|
require_admin(altcoin_session)
|
|
return get_strategy_evaluation(days=days)
|
|
|
|
|
|
@router.get("/api/paper-trading/trades")
|
|
async def api_paper_trading_trades(
|
|
limit: int = 50,
|
|
offset: int = 0,
|
|
status: str = "",
|
|
strategy_code: str = "",
|
|
side: str = "",
|
|
altcoin_session: str = Cookie(default=""),
|
|
):
|
|
require_admin(altcoin_session)
|
|
return list_paper_trades(limit=limit, offset=offset, status=status, strategy_code=strategy_code, side=side)
|
|
|
|
|
|
@router.get("/api/paper-trading/orders")
|
|
async def api_paper_trading_orders(
|
|
limit: int = 50,
|
|
offset: int = 0,
|
|
status: str = "",
|
|
strategy_code: str = "",
|
|
side: str = "",
|
|
altcoin_session: str = Cookie(default=""),
|
|
):
|
|
require_admin(altcoin_session)
|
|
return list_paper_orders(limit=limit, offset=offset, status=status, strategy_code=strategy_code, side=side)
|
|
|
|
|
|
@router.get("/api/paper-trading/events")
|
|
async def api_paper_trading_events(
|
|
limit: int = 80,
|
|
offset: int = 0,
|
|
symbol: str = "",
|
|
event_type: str = "",
|
|
strategy_code: str = "",
|
|
side: str = "",
|
|
altcoin_session: str = Cookie(default=""),
|
|
):
|
|
require_admin(altcoin_session)
|
|
return list_paper_trade_events(limit=limit, offset=offset, symbol=symbol, event_type=event_type, strategy_code=strategy_code, side=side)
|
|
|
|
|
|
@router.post("/api/paper-trading/report")
|
|
async def api_paper_trading_report(days: int = 30, altcoin_session: str = Cookie(default="")):
|
|
require_admin(altcoin_session)
|
|
return send_paper_trading_report(days=days)
|
|
|
|
|
|
@router.delete("/api/paper-trading/trades/{trade_id}")
|
|
async def api_delete_paper_trade(trade_id: int, altcoin_session: str = Cookie(default="")):
|
|
require_admin(altcoin_session)
|
|
result = delete_paper_trade(trade_id)
|
|
if not result.get("deleted"):
|
|
raise HTTPException(status_code=404 if result.get("reason") == "not_found" else 400, detail=result)
|
|
return result
|
|
|
|
|
|
@router.delete("/api/paper-trading/orders/{order_id}")
|
|
async def api_delete_paper_order(order_id: int, altcoin_session: str = Cookie(default="")):
|
|
require_admin(altcoin_session)
|
|
result = delete_paper_order(order_id)
|
|
if not result.get("deleted"):
|
|
raise HTTPException(status_code=404 if result.get("reason") == "not_found" else 400, detail=result)
|
|
return result
|
|
|
|
|
|
@router.post("/api/paper-trading/reset")
|
|
async def api_reset_paper_trading(scope: str = "all", altcoin_session: str = Cookie(default="")):
|
|
require_admin(altcoin_session)
|
|
result = reset_paper_trading_data(scope=scope)
|
|
if not result.get("reset"):
|
|
raise HTTPException(status_code=400, detail=result)
|
|
return result
|