Files
sanguo_vnpy_v2/scripts/qmt_relogin/qmt_today.py
T

78 lines
2.7 KiB
Python

# -*- coding: utf-8 -*-
"""Read-only: today's QMT panorama — log timeline, processes, bridge liveness."""
import datetime
import io
import os
import re
import subprocess
ACCOUNT = "66639661"
def esc(s):
return str(s).encode("unicode_escape").decode("ascii")
d = open(r"C:\sanguo_bigqmt\qmt_install_dir.txt", encoding="utf-8").read().strip()
root = os.path.dirname(d)
logdir = os.path.join(root, "userdata", "log")
print("=== today's logs (size/mtime) ===")
for f in sorted(os.listdir(logdir)):
if "20260909" in f:
p = os.path.join(logdir, f)
st = os.stat(p)
print(" %-46s %8d mtime=%s" % (
f, st.st_size,
datetime.datetime.fromtimestamp(st.st_mtime).strftime("%H:%M:%S")))
kws = ("登录", "登陆", "login", "Login", "自动", "运行", "模型", "策略",
"启动", "恢复", "auto", "Auto", "Formula", "自启")
f2 = os.path.join(logdir, "XtClient_20260909.log")
print("=== XtClient key windows (08:5x / 11:xx / 12:0x) ===")
try:
with io.open(f2, "r", encoding="gbk", errors="replace") as f:
for ln in f:
hhmm = ln[:5]
if any(k in ln for k in kws) and (
hhmm.startswith("08:5") or hhmm.startswith("11:")
or hhmm.startswith("12:0")):
print(" ", esc(ln.rstrip())[:230])
except OSError as e:
print(" ", e)
f1 = os.path.join(logdir, "XtClient_Formula_20260909.log")
print("=== Formula head 12 ===")
try:
lines = io.open(f1, "r", encoding="gbk", errors="replace").readlines()
for ln in lines[:12]:
print(" ", esc(ln.rstrip())[:200])
print("=== Formula tail 25 (of %d) ===" % len(lines))
for ln in lines[-25:]:
print(" ", esc(ln.rstrip())[:200])
except OSError as e:
print(" ", e)
print("=== processes ===")
raw = subprocess.run(["tasklist"], capture_output=True).stdout
for ln in raw.decode("gbk", errors="replace").splitlines():
if any(x in ln for x in ("Xt", "ython", "redis-server", "Redis")):
print(" ", esc(ln)[:130])
print("=== bridge liveness (read-only RPC) ===")
try:
import redis
with open(r"C:\redis\redis.conf") as f:
pw = re.search(r"^requirepass (\S+)", f.read(), re.M).group(1)
rc = redis.Redis(host="127.0.0.1", port=6379, db=5, password=pw,
decode_responses=True)
q = "bigqmt:rpc:queue:%s" % ACCOUNT
print(" queue llen:", rc.llen(q))
from bigqmt_signal_trader.redis_rpc import call_redis_rpc
r = call_redis_rpc(rc, ACCOUNT, "query_stock_orders",
{"account_id": ACCOUNT}, timeout_seconds=10)
print(" RPC:", esc(str(r))[:400])
except Exception as e:
print(" RPC ERR:", esc(repr(e))[:300])
print("DONE4")