This commit is contained in:
aaron 2026-02-21 19:41:08 +08:00
parent ae9f4cf87c
commit c0fac4b870

View File

@ -151,14 +151,32 @@ def check_abnormal_orders():
# 6. 最近的活动日志 # 6. 最近的活动日志
print("【6】最近10条订单变更记录按时间倒序:") print("【6】最近10条订单变更记录按时间倒序:")
print("-" * 80) print("-" * 80)
recent_orders = db.query(PaperOrder).order_by( # 使用 COALESCE 来优先显示 closed_at其次 opened_at最后 created_at
PaperOrder.updated_at.desc() recent_orders = db.execute(text("""
).limit(10).all() SELECT
COALESCE(closed_at, opened_at, created_at) as last_time,
symbol,
side,
status,
entry_price,
filled_price
FROM paper_orders
ORDER BY last_time DESC
LIMIT 10
""")).fetchall()
for order in recent_orders: for order in recent_orders:
print(f" {order.updated_at.strftime('%H:%M:%S')} | {order.symbol} | " last_time = order[0]
f"{order.side.value:4s} | {order.status.value:15s} | " symbol = order[1]
f"入场:{order.entry_price} 成交:{order.filled_price}") side = order[2]
status = order[3]
entry_price = order[4]
filled_price = order[5]
time_str = last_time.strftime('%H:%M:%S') if last_time else 'N/A'
filled_str = f"{filled_price:.2f}" if filled_price else "NULL"
print(f" {time_str} | {symbol} | {side:4s} | {status:15s} | "
f"入场:{entry_price:.2f} 成交:{filled_str}")
print() print()
print("=" * 80) print("=" * 80)