7eec983164
- live_orchestrator warmup: 重放start~昨日raw到策略am使其inited(实走每日单根, 不warmup则ArrayManager永不inited→策略无信号) - routes _DataSourceWrapper 加 fetch_day(给 live_step 拉当日raw) - verify_live_step 容器端到端: 创建live account+live_step(07-07 warmup+step)+存pending, 跑通(pending=0系DoubleMa当日无交叉, 撮合/存已单测)
67 lines
2.7 KiB
Python
67 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""C-S3 实走端到端验证(容器内,task 2):创建 live account + live_step + 查 pending/positions。
|
|
|
|
验证编排 glue:恢复状态 → fetch_day raw → engine.step → 存 pending/positions。
|
|
用历史日期(有 raw)验证;首次 step 策略收单(next_open) → pending 非空。
|
|
用法(容器内):python3 /app/scripts/verify_live_step.py
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, "/app")
|
|
|
|
from sanguo_data.config import find_config_path, load_config
|
|
from sanguo_api.routes_paper import _DataSourceWrapper
|
|
from sanguo_trader.persistence import (
|
|
init_db, save_account, update_account_status,
|
|
load_pending_orders, load_positions, save_daily_balance,
|
|
)
|
|
from sanguo_trader.live_orchestrator import live_step
|
|
|
|
DB = "/volume1/stock/sanguo_vnpy/data/backtest_results.db"
|
|
TODAY = "2026-07-07" # 有 raw 的历史日期(验证用)
|
|
|
|
|
|
def main():
|
|
cfg = load_config(find_config_path())
|
|
init_db(DB)
|
|
aid = save_account(DB, {
|
|
"name": "live_verify_tmp", "mode": "live", "interval": "d",
|
|
"symbols": ["600000"],
|
|
"strategies": [{"name": "DoubleMaStrategy",
|
|
"params": {"fast_window": 5, "slow_window": 10},
|
|
"match_session": "next_open", "symbol": "600000",
|
|
"listing_days": 0}],
|
|
"initial_capital": 1_000_000, "rate": 0.0003, "slippage": 0,
|
|
"pricetick": 0.01, "stamp_duty_rate": 0.0005,
|
|
"transfer_fee_rate": 0.00001, "min_commission": 5.0,
|
|
"start_date": "2024-01-01",
|
|
})
|
|
update_account_status(DB, aid, "running")
|
|
print(f"created live account #{aid} (mode=live)")
|
|
|
|
ds = _DataSourceWrapper(cfg)
|
|
live_step(DB, aid, ds, cfg, today=TODAY)
|
|
|
|
pending = load_pending_orders(DB, aid)
|
|
positions = load_positions(DB, aid, "account")
|
|
print(f"\n=== live_step @ {TODAY} 结果 ===")
|
|
print(f"pending orders: {len(pending)}")
|
|
for p in pending:
|
|
print(f" {p['strategy_id']} {p['symbol']} {p['side']} {p['volume']}@{p['price']} ({p['match_session']})")
|
|
print(f"positions: {positions or '(空,首次 step 未撮合)'}")
|
|
# 清理验证 account
|
|
import sqlite3
|
|
with sqlite3.connect(DB) as c:
|
|
c.execute("DELETE FROM paper_accounts WHERE id=?", (aid,))
|
|
c.execute("DELETE FROM paper_pending_orders WHERE account_id=?", (aid,))
|
|
c.execute("DELETE FROM paper_positions WHERE account_id=?", (aid,))
|
|
c.execute("DELETE FROM paper_daily_balance WHERE account_id=?", (aid,))
|
|
c.commit()
|
|
print(f"\n(已清理验证 account #{aid})")
|
|
print("live_step 端到端 OK ✓" if pending else "live_step 跑通(策略当日无信号)")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|