import sys from pathlib import Path sys.path.append(str(Path(__file__).resolve().parent.parent)) from database import TradeDB db = TradeDB() tables = [ ("공통", "매매내역", "trade_history"), ("한국투자증권(KIS) / 키움", "실시간 체결 틱", "ws_ticks"), ("한국투자증권(KIS) / 키움", "실시간 캔들 (분봉)", "ws_candles"), ("한국투자증권(KIS) / 키움", "호가 스냅샷 (Orderbook)", "ws_orderbook"), ("한국투자증권(KIS) / 키움", "호가 스냅샷 (Orderbook)", "kis_ws_orderbook"), ("LS증권", "실시간 체결 틱", "ls_ws_ticks"), ("LS증권", "실시간 캔들 (분봉)", "ls_ws_candles"), ("LS증권", "호가 스냅샷 (Orderbook)", "ls_ws_orderbook"), ] print("| 증권사 | 데이터 유형 | 테이블명 | 2026-08-11 당일 적재 건수 |") print("|---|---|---|---|") today_start = '20260811000000' today_end = '20260812000000' for broker, ttype, table in tables: try: cols = [dict(r)["Field"] for r in db.conn.execute(f"SHOW COLUMNS FROM {table}").fetchall()] time_col = None if "timestamp" in cols: time_col = "timestamp" elif "recv_ts" in cols: time_col = "recv_ts" elif "created_at" in cols: time_col = "created_at" if time_col: sql = f"SELECT COUNT(*) as c FROM {table} WHERE {time_col} >= %s AND {time_col} < %s" c = db.conn.execute(sql, (today_start, today_end)).fetchone()["c"] else: c = "에러: 시간 컬럼 없음" if isinstance(c, int): print(f"| {broker} | {ttype} | `{table}` | {c:,} 건 |") else: print(f"| {broker} | {ttype} | `{table}` | {c} |") except Exception as e: print(f"| {broker} | {ttype} | `{table}` | 에러: {e} |") db.close()