653472def3
对齐 VeighNa 4.4 原生 Qt UI,新增成交监控、资金监控、网关管理、全局配置等页面与 API,功能对等性 98.5%。 - 新增 API: /api/v1/trades, /api/v1/accounts, /api/v1/settings, 网关扩展 - 新增前端页面: 成交、资金、合约、网关、全局配置、微信通知 - 扩展导航菜单与实时数据推送 - 补充需求分析与实现计划文档
98 lines
2.5 KiB
Python
98 lines
2.5 KiB
Python
"""
|
|
资金监控路由
|
|
处理账户资金查询
|
|
"""
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from typing import List
|
|
import logging
|
|
|
|
from ..deps import get_current_user, get_vn_service
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/", response_model=List[dict])
|
|
async def get_all_accounts(
|
|
current_user: dict = Depends(get_current_user),
|
|
vn_service=Depends(get_vn_service)
|
|
):
|
|
"""
|
|
获取所有账户资金
|
|
|
|
返回所有账户的资金信息,包括账号、余额、冻结、可用资金等
|
|
"""
|
|
accounts = await vn_service.get_accounts()
|
|
|
|
return [
|
|
{
|
|
"accountid": acc.get("account_id", ""),
|
|
"balance": acc.get("balance", 0.0),
|
|
"frozen": acc.get("frozen", 0.0),
|
|
"available": acc.get("available", 0.0),
|
|
"gateway_name": acc.get("gateway_name", ""),
|
|
}
|
|
for acc in accounts
|
|
]
|
|
|
|
|
|
@router.get("/{accountid}", response_model=dict)
|
|
async def get_account(
|
|
accountid: str,
|
|
current_user: dict = Depends(get_current_user),
|
|
vn_service=Depends(get_vn_service)
|
|
):
|
|
"""
|
|
获取指定账户的资金信息
|
|
|
|
- **accountid**: 账号
|
|
"""
|
|
accounts = await vn_service.get_accounts()
|
|
|
|
account = next(
|
|
(acc for acc in accounts if acc.get("account_id", "") == accountid),
|
|
None
|
|
)
|
|
|
|
if not account:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail=f"Account {accountid} not found"
|
|
)
|
|
|
|
return {
|
|
"accountid": account.get("account_id", ""),
|
|
"balance": account.get("balance", 0.0),
|
|
"frozen": account.get("frozen", 0.0),
|
|
"available": account.get("available", 0.0),
|
|
"gateway_name": account.get("gateway_name", ""),
|
|
}
|
|
|
|
|
|
@router.get("/summary/total", response_model=dict)
|
|
async def get_account_summary(
|
|
current_user: dict = Depends(get_current_user),
|
|
vn_service=Depends(get_vn_service)
|
|
):
|
|
"""
|
|
获取所有账户的资金汇总
|
|
|
|
返回所有账户的余额、冻结、可用资金的总和
|
|
"""
|
|
accounts = await vn_service.get_accounts()
|
|
|
|
total_balance = sum(acc.get("balance", 0.0) for acc in accounts)
|
|
total_frozen = sum(acc.get("frozen", 0.0) for acc in accounts)
|
|
total_available = sum(acc.get("available", 0.0) for acc in accounts)
|
|
|
|
return {
|
|
"total_balance": total_balance,
|
|
"total_frozen": total_frozen,
|
|
"total_available": total_available,
|
|
"account_count": len(accounts),
|
|
}
|
|
|
|
|
|
__all__ = ["router"]
|