This commit is contained in:
薇薇安 2026-01-14 11:40:50 +08:00
parent 4140370c2d
commit 1bfa7c18ef
5 changed files with 24 additions and 4 deletions

View File

@ -93,7 +93,8 @@ logger.info(f"日志级别: {os.getenv('LOG_LEVEL', 'INFO')}")
app = FastAPI(
title="Auto Trade System API",
version="1.0.0",
description="币安自动交易系统API"
description="币安自动交易系统API",
redirect_slashes=False # 禁用自动重定向避免307重定向问题
)
# CORS配置允许React前端访问

View File

@ -16,6 +16,7 @@ from database.models import TradingConfig
router = APIRouter()
@router.get("")
@router.get("/")
async def get_all_configs():
"""获取所有配置"""

View File

@ -6,5 +6,6 @@ from api.routes.stats import get_dashboard_data
router = APIRouter()
# 使用stats模块的dashboard函数
# 使用stats模块的dashboard函数同时支持有斜杠和无斜杠
router.add_api_route("", get_dashboard_data, methods=["GET"])
router.add_api_route("/", get_dashboard_data, methods=["GET"])

View File

@ -43,6 +43,7 @@ def get_date_range(period: Optional[str] = None):
return start_date.strftime('%Y-%m-%d 00:00:00'), end_date.strftime('%Y-%m-%d %H:%M:%S')
@router.get("")
@router.get("/")
async def get_trades(
start_date: Optional[str] = Query(None, description="开始日期 (YYYY-MM-DD 或 YYYY-MM-DD HH:MM:SS)"),

View File

@ -11,12 +11,20 @@ const buildUrl = (path) => {
export const api = {
// 配置管理
getConfigs: async () => {
const response = await fetch(buildUrl('/api/config/'));
const response = await fetch(buildUrl('/api/config'));
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: '获取配置失败' }));
throw new Error(error.detail || '获取配置失败');
}
return response.json();
},
getConfig: async (key) => {
const response = await fetch(buildUrl(`/api/config/${key}`));
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: '获取配置失败' }));
throw new Error(error.detail || '获取配置失败');
}
return response.json();
},
@ -82,11 +90,19 @@ export const api = {
// 统计
getPerformance: async (days = 7) => {
const response = await fetch(buildUrl(`/api/stats/performance?days=${days}`));
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: '获取性能统计失败' }));
throw new Error(error.detail || '获取性能统计失败');
}
return response.json();
},
getDashboard: async () => {
const response = await fetch(buildUrl('/api/dashboard/'));
const response = await fetch(buildUrl('/api/dashboard'));
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: '获取仪表板数据失败' }));
throw new Error(error.detail || '获取仪表板数据失败');
}
return response.json();
},
};