update
This commit is contained in:
parent
588b49ed86
commit
009fb3ea0d
@ -7,6 +7,7 @@ from datetime import datetime
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from app.services.real_trading_service import get_real_trading_service
|
from app.services.real_trading_service import get_real_trading_service
|
||||||
|
from app.services.bitget_trading_api_sdk import get_bitget_trading_api
|
||||||
from app.utils.logger import logger
|
from app.utils.logger import logger
|
||||||
|
|
||||||
|
|
||||||
@ -143,16 +144,17 @@ async def get_order(order_id: str):
|
|||||||
async def get_positions():
|
async def get_positions():
|
||||||
"""获取实盘持仓(从交易所同步)"""
|
"""获取实盘持仓(从交易所同步)"""
|
||||||
try:
|
try:
|
||||||
service = get_real_trading_service()
|
# 即使实盘交易未启用,也可以查看交易所持仓
|
||||||
|
trading_api = get_bitget_trading_api()
|
||||||
|
|
||||||
if not service:
|
if not trading_api:
|
||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
"message": "实盘交易服务未启用",
|
"message": "Bitget API 未配置",
|
||||||
"positions": []
|
"positions": []
|
||||||
}
|
}
|
||||||
|
|
||||||
positions = service.sync_positions_from_exchange()
|
positions = trading_api.get_position()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
@ -166,18 +168,38 @@ async def get_positions():
|
|||||||
|
|
||||||
@router.get("/account")
|
@router.get("/account")
|
||||||
async def get_account_status():
|
async def get_account_status():
|
||||||
"""获取实盘账户状态"""
|
"""获取实盘账户状态(即使实盘交易未启用也可查看)"""
|
||||||
try:
|
try:
|
||||||
service = get_real_trading_service()
|
# 直接使用交易 API,不依赖实盘交易服务
|
||||||
|
trading_api = get_bitget_trading_api()
|
||||||
|
|
||||||
if not service:
|
if not trading_api:
|
||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
"message": "实盘交易服务未启用",
|
"message": "Bitget API 未配置",
|
||||||
"account": None
|
"account": None
|
||||||
}
|
}
|
||||||
|
|
||||||
account = service.get_account_status()
|
# 获取账户余额
|
||||||
|
balance_info = trading_api.get_balance()
|
||||||
|
usdt_info = balance_info.get('USDT', {})
|
||||||
|
|
||||||
|
available = float(usdt_info.get('available', 0))
|
||||||
|
frozen = float(usdt_info.get('frozen', 0))
|
||||||
|
locked = float(usdt_info.get('locked', 0))
|
||||||
|
|
||||||
|
# 获取持仓价值
|
||||||
|
positions = trading_api.get_position()
|
||||||
|
total_position_value = sum(
|
||||||
|
float(p.get('notional', 0)) for p in positions
|
||||||
|
)
|
||||||
|
|
||||||
|
account = {
|
||||||
|
'current_balance': available + frozen + locked,
|
||||||
|
'available': available,
|
||||||
|
'used_margin': frozen + locked,
|
||||||
|
'total_position_value': total_position_value
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
|
|||||||
@ -372,19 +372,28 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 警告横幅 -->
|
<!-- 警告横幅 - 只在API未配置时显示 -->
|
||||||
<div class="warning-banner" v-if="!serviceEnabled || !apiConfigured">
|
<div class="warning-banner" v-if="!apiConfigured">
|
||||||
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
|
||||||
</svg>
|
</svg>
|
||||||
<div class="warning-banner-text">
|
<div class="warning-banner-text">
|
||||||
<template v-if="!serviceEnabled">实盘交易服务未启用,请在配置中设置 REAL_TRADING_ENABLED=true</template>
|
Bitget API 密钥未配置,请在配置文件中设置 BITGET_API_KEY 和 BITGET_API_SECRET
|
||||||
<template v-else-if="!apiConfigured">Bitget API 密钥未配置,请检查配置文件</template>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 账户信息 -->
|
<!-- 实盘交易未启用提示 -->
|
||||||
<div class="account-info" v-if="serviceEnabled">
|
<div class="warning-banner" v-else-if="!serviceEnabled && apiConfigured" style="background: rgba(255, 200, 0, 0.1); border-color: #ffc800;">
|
||||||
|
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" style="color: #ffc800;">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
|
</svg>
|
||||||
|
<div class="warning-banner-text" style="color: #ffc800;">
|
||||||
|
实盘交易服务未启用(REAL_TRADING_ENABLED=false),仅可查看账户数据,无法执行交易
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 账户信息 - API 配置后即可显示 -->
|
||||||
|
<div class="account-info" v-if="apiConfigured">
|
||||||
<div class="account-card">
|
<div class="account-card">
|
||||||
<div class="account-label">账户余额</div>
|
<div class="account-label">账户余额</div>
|
||||||
<div class="account-value">${{ account.current_balance ? account.current_balance.toLocaleString() : '0' }}</div>
|
<div class="account-value">${{ account.current_balance ? account.current_balance.toLocaleString() : '0' }}</div>
|
||||||
@ -407,8 +416,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 统计卡片 -->
|
<!-- 统计卡片 - 只有在实盘交易启用时才显示交易统计 -->
|
||||||
<div class="stats-grid" v-if="stats">
|
<div class="stats-grid" v-if="stats && serviceEnabled">
|
||||||
<div class="stat-card">
|
<div class="stat-card">
|
||||||
<div class="stat-label">胜率</div>
|
<div class="stat-label">胜率</div>
|
||||||
<div class="stat-value" :class="stats.win_rate >= 50 ? 'positive' : 'negative'">
|
<div class="stat-value" :class="stats.win_rate >= 50 ? 'positive' : 'negative'">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user