This commit is contained in:
aaron 2026-03-03 16:51:17 +08:00
parent e62d761efb
commit 33e43789ce
2 changed files with 32 additions and 5 deletions

View File

@ -26,16 +26,32 @@ def check_column_exists(table_name, column_name):
return column_name in columns
def create_tables_if_not_exist():
"""创建表(如果不存在)"""
from app.models.paper_trading import PaperOrder as POTable
from app.models.database import Base
# 创建所有表
Base.metadata.create_all(bind=db_service.engine)
logger.info("✅ 数据库表已创建")
def migrate():
"""执行迁移"""
try:
with db_service.engine.connect() as conn:
# 检查表是否存在
# 首先确保表存在
inspector = inspect(db_service.engine)
if 'paper_orders' not in inspector.get_table_names():
logger.info("⚠️ paper_orders 表不存在,先创建表...")
create_tables_if_not_exist()
# 重新检查
inspector = inspect(db_service.engine)
if 'paper_orders' not in inspector.get_table_names():
logger.error("❌ paper_orders 表不存在")
logger.error("创建表失败")
return False
with db_service.engine.connect() as conn:
logger.info("开始迁移 paper_orders 表...")
# 检查并添加 margin 列

View File

@ -1380,6 +1380,11 @@
<th>等级</th>
<th>入场价</th>
<th>出场价</th>
<th>止损</th>
<th>止盈</th>
<th>保证金</th>
<th>杠杆</th>
<th>持仓价值</th>
<th>盈亏</th>
<th>状态</th>
<th>平仓时间</th>
@ -1392,12 +1397,18 @@
<td>{{ order.symbol }}</td>
<td><span class="side-badge" :class="order.side">{{ order.side === 'long' ? '做多' : '做空' }}</span></td>
<td><span class="grade-badge" :class="order.signal_grade">{{ order.signal_grade }}</span></td>
<td>${{ order.filled_price?.toLocaleString() }}</td>
<td>${{ order.filled_price?.toLocaleString() || order.entry_price?.toLocaleString() }}</td>
<td>${{ order.exit_price?.toLocaleString() }}</td>
<td>${{ order.stop_loss?.toLocaleString() }}</td>
<td>${{ order.take_profit?.toLocaleString() }}</td>
<td>${{ order.margin?.toFixed(2) || (order.quantity / 20).toFixed(2) }}</td>
<td>{{ order.leverage || 20 }}x</td>
<td>${{ order.quantity?.toFixed(2) }}</td>
<td>
<span class="pnl" :class="order.pnl_amount >= 0 ? 'positive' : 'negative'">
{{ order.pnl_percent >= 0 ? '+' : '' }}{{ order.pnl_percent?.toFixed(2) }}%
(${{ order.pnl_amount >= 0 ? '+' : '' }}{{ order.pnl_amount?.toFixed(2) }})
<br>
<small>(${{ order.pnl_amount >= 0 ? '+' : '' }}{{ order.pnl_amount?.toFixed(2) }})</small>
</span>
</td>
<td><span class="status-badge" :class="order.status">{{ formatStatus(order.status) }}</span></td>