Files
kis_trader/scratch/check_db_tables_and_stats.py

55 lines
1.8 KiB
Python

import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
from database import TradeDB
db = TradeDB()
try:
tables = [list(dict(r).values())[0] for r in db.conn.execute("SHOW TABLES").fetchall()]
print("Tables:", tables)
print("\n[LS Ticks]")
ls_ticks = db.conn.execute("""
SELECT HOUR(ts) as hr, count(*)
FROM ls_ws_ticks
WHERE date(ts) = '2026-08-31'
GROUP BY HOUR(ts)
""").fetchall()
for row in ls_ticks: print(dict(row))
print("\n[Target Candidates]")
tc = db.conn.execute("""
SELECT HOUR(scan_time) as hr, count(*)
FROM target_candidates
WHERE date(scan_time) = '2026-08-31'
GROUP BY HOUR(scan_time)
""").fetchall()
for row in tc: print(dict(row))
if 'kis_ws_orderbooks' in tables:
print("\n[KIS Orderbooks - kis_ws_orderbooks]")
obs = db.conn.execute("""
SELECT HOUR(timestamp) as hr, count(*)
FROM kis_ws_orderbooks
WHERE date(timestamp) = '2026-08-31'
GROUP BY HOUR(timestamp)
""").fetchall()
for row in obs: print(dict(row))
elif 'ws_orderbook' in tables:
print("\n[KIS Orderbooks - ws_orderbook]")
try:
cols = [dict(r)["Field"] for r in db.conn.execute("SHOW COLUMNS FROM ws_orderbook").fetchall()]
ts_col = 'ts' if 'ts' in cols else ('timestamp' if 'timestamp' in cols else 'snap_time')
obs = db.conn.execute(f"""
SELECT HOUR({ts_col}) as hr, count(*)
FROM ws_orderbook
WHERE date({ts_col}) = '2026-08-31'
GROUP BY HOUR({ts_col})
""").fetchall()
for row in obs: print(dict(row))
except Exception as e:
print(e)
finally:
db.close()