Files
kis_bot/scratch/db_check2.py

46 lines
1.4 KiB
Python

import sys
from datetime import datetime
sys.path.append('/home/hoon/kis_bot')
from database import TradeDB
def check_db():
db = TradeDB()
try:
today = datetime.now().strftime("%Y-%m-%d")
print(f"--- Trades for {today} ---")
# Check trade history
query_trades = """
SELECT strategy, code, name, buy_price, buy_qty, sell_price, sell_qty, status, buy_time
FROM trade_history
WHERE DATE(buy_time) = %s
"""
trades = db.conn.execute(query_trades, (today,)).fetchall()
for t in trades:
print(dict(t))
print(f"--- Active Trades for {today} ---")
# Check active trades
query_active = """
SELECT strategy, code, name, buy_price, qty, buy_time
FROM active_trades
WHERE DATE(buy_time) = %s
"""
active_trades = db.conn.execute(query_active, (today,)).fetchall()
for t in active_trades:
print(dict(t))
# Check config tables for momentum, scalp, tail(range_break or whatever tail is)
print("--- Env Configs ---")
query_env = "SELECT env_key, env_val FROM env_config WHERE env_key LIKE '%MOMENTUM%' OR env_key LIKE '%SCALP%' OR env_key LIKE '%TAIL%'"
envs = db.conn.execute(query_env).fetchall()
for e in envs:
print(dict(e))
finally:
db.close()
if __name__ == "__main__":
check_db()