Files
kis_trader/scratch/check_ob_current.py

26 lines
1.2 KiB
Python

import sys, os
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
from database import TradeDB
db = TradeDB()
try:
# ws_orderbook 실제 테이블명 확인
tables = [dict(r)['Tables_in_kis_quant_db'] for r in db.conn.execute("SHOW TABLES").fetchall()]
ob_tables = [t for t in tables if 'orderbook' in t.lower() or 'order' in t.lower()]
print("[호가 관련 테이블 목록]")
for t in ob_tables:
cnt = dict(db.conn.execute(f"SELECT count(*) as c FROM `{t}`").fetchone())['c']
print(f" {t}: {cnt}")
# 환경변수 재확인
print("\n[WS_ORDERBOOK_SAVE_KIS DB 값]")
cols = [dict(r)["Field"] for r in db.conn.execute("SHOW COLUMNS FROM env_config").fetchall()]
print(" env_config 컬럼:", cols)
key_col = 'env_key' if 'env_key' in cols else ('`key`' if 'key' in cols else cols[0])
val_col = 'env_value' if 'env_value' in cols else ('value' if 'value' in cols else cols[1])
print(f" key_col={key_col}, val_col={val_col}")
row = db.conn.execute(f"SELECT * FROM env_config WHERE {key_col} = 'WS_ORDERBOOK_SAVE_KIS'").fetchone()
print(" 값:", dict(row) if row else "없음!")
finally:
db.close()