a
This commit is contained in:
parent
4140370c2d
commit
1bfa7c18ef
|
|
@ -93,7 +93,8 @@ logger.info(f"日志级别: {os.getenv('LOG_LEVEL', 'INFO')}")
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
title="Auto Trade System API",
|
title="Auto Trade System API",
|
||||||
version="1.0.0",
|
version="1.0.0",
|
||||||
description="币安自动交易系统API"
|
description="币安自动交易系统API",
|
||||||
|
redirect_slashes=False # 禁用自动重定向,避免307重定向问题
|
||||||
)
|
)
|
||||||
|
|
||||||
# CORS配置(允许React前端访问)
|
# CORS配置(允许React前端访问)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ from database.models import TradingConfig
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("")
|
||||||
@router.get("/")
|
@router.get("/")
|
||||||
async def get_all_configs():
|
async def get_all_configs():
|
||||||
"""获取所有配置"""
|
"""获取所有配置"""
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,6 @@ from api.routes.stats import get_dashboard_data
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
# 使用stats模块的dashboard函数
|
# 使用stats模块的dashboard函数(同时支持有斜杠和无斜杠)
|
||||||
|
router.add_api_route("", get_dashboard_data, methods=["GET"])
|
||||||
router.add_api_route("/", get_dashboard_data, methods=["GET"])
|
router.add_api_route("/", get_dashboard_data, methods=["GET"])
|
||||||
|
|
|
||||||
|
|
@ -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')
|
return start_date.strftime('%Y-%m-%d 00:00:00'), end_date.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("")
|
||||||
@router.get("/")
|
@router.get("/")
|
||||||
async def get_trades(
|
async def get_trades(
|
||||||
start_date: Optional[str] = Query(None, description="开始日期 (YYYY-MM-DD 或 YYYY-MM-DD HH:MM:SS)"),
|
start_date: Optional[str] = Query(None, description="开始日期 (YYYY-MM-DD 或 YYYY-MM-DD HH:MM:SS)"),
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,20 @@ const buildUrl = (path) => {
|
||||||
export const api = {
|
export const api = {
|
||||||
// 配置管理
|
// 配置管理
|
||||||
getConfigs: async () => {
|
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();
|
return response.json();
|
||||||
},
|
},
|
||||||
|
|
||||||
getConfig: async (key) => {
|
getConfig: async (key) => {
|
||||||
const response = await fetch(buildUrl(`/api/config/${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();
|
return response.json();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -82,11 +90,19 @@ export const api = {
|
||||||
// 统计
|
// 统计
|
||||||
getPerformance: async (days = 7) => {
|
getPerformance: async (days = 7) => {
|
||||||
const response = await fetch(buildUrl(`/api/stats/performance?days=${days}`));
|
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();
|
return response.json();
|
||||||
},
|
},
|
||||||
|
|
||||||
getDashboard: async () => {
|
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();
|
return response.json();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user