This commit is contained in:
薇薇安 2026-02-03 11:45:20 +08:00
parent 0962df4112
commit d0688c57b7

View File

@ -90,8 +90,12 @@ async def create_account(
@router.get("/{account_id}")
async def get_account_detail(account_id: int, user: Dict[str, Any] = Depends(require_account_access)):
async def get_account_detail(
account_id: int,
user: Dict[str, Any] = Depends(get_current_user)
):
"""获取账号详情"""
require_account_access(account_id, user)
try:
acc = Account.get_by_id(account_id)
if not acc:
@ -131,9 +135,10 @@ async def update_account(
async def update_credentials(
account_id: int,
data: AccountCredentialsUpdate,
user: Dict[str, Any] = Depends(require_account_owner)
user: Dict[str, Any] = Depends(get_current_user)
):
"""更新API密钥"""
require_account_owner(account_id, user)
try:
updates = {}
if data.api_key is not None:
@ -155,8 +160,14 @@ async def update_credentials(
@router.get("/{account_id}/trading/status")
@router.get("/{account_id}/service/status", include_in_schema=False) # 兼容旧路由
async def get_service_status(account_id: int, user: Dict[str, Any] = Depends(require_account_access)):
async def get_service_status(
account_id: int,
user: Dict[str, Any] = Depends(get_current_user)
):
"""获取该账号关联的交易服务状态"""
# 手动调用权限检查,因为 Depends(require_account_access) 无法直接获取路径参数 account_id
require_account_access(account_id, user)
try:
program = program_name_for_account(account_id)
# status <program>
@ -185,8 +196,12 @@ async def get_service_status(account_id: int, user: Dict[str, Any] = Depends(req
@router.post("/{account_id}/service/start")
async def start_service(account_id: int, user: Dict[str, Any] = Depends(require_account_owner)):
async def start_service(
account_id: int,
user: Dict[str, Any] = Depends(get_current_user)
):
"""启动交易服务"""
require_account_owner(account_id, user)
try:
program = program_name_for_account(account_id)
out = run_supervisorctl(["start", program])
@ -207,8 +222,12 @@ async def start_service(account_id: int, user: Dict[str, Any] = Depends(require_
@router.post("/{account_id}/service/stop")
async def stop_service(account_id: int, user: Dict[str, Any] = Depends(require_account_owner)):
async def stop_service(
account_id: int,
user: Dict[str, Any] = Depends(get_current_user)
):
"""停止交易服务"""
require_account_owner(account_id, user)
try:
program = program_name_for_account(account_id)
out = run_supervisorctl(["stop", program])
@ -229,8 +248,12 @@ async def stop_service(account_id: int, user: Dict[str, Any] = Depends(require_a
@router.post("/{account_id}/service/restart")
async def restart_service(account_id: int, user: Dict[str, Any] = Depends(require_account_owner)):
async def restart_service(
account_id: int,
user: Dict[str, Any] = Depends(get_current_user)
):
"""重启交易服务"""
require_account_owner(account_id, user)
try:
program = program_name_for_account(account_id)
out = run_supervisorctl(["restart", program])