import sqlite3 from datetime import datetime import os # 找到最新的数据库文件 data_dir = 'data' db_files = [f for f in os.listdir(data_dir) if f.startswith('trading_data_') and f.endswith('.db')] db_files.sort(reverse=True) if not db_files: print("没有找到数据库文件") exit(1) db_path = os.path.join(data_dir, db_files[0]) print(f"使用数据库: {db_path}") conn = sqlite3.connect(db_path) cursor = conn.cursor() # 先查看所有表 print('\n=== 数据库中的表 ===') cursor.execute("SELECT name FROM sqlite_master WHERE type='table'") tables = cursor.fetchall() for table in tables: print(f" - {table[0]}") # 查看price_data表的结构 print('\n=== price_data 表结构 ===') try: cursor.execute("PRAGMA table_info(price_data)") columns = cursor.fetchall() for col in columns: print(f" {col[1]}: {col[2]}") except Exception as e: print(f" 错误: {e}") print('\n=== Price Data (最新10条) ===') try: cursor.execute('SELECT * FROM price_data ORDER BY timestamp DESC LIMIT 10') rows = cursor.fetchall() for row in rows: ts = datetime.fromtimestamp(row[1]).strftime('%Y-%m-%d %H:%M:%S') print(f"所有列: {row}") print(f" 时间: {ts}") print(f" ID: {row[0]}, 时间戳: {row[1]}, 会话ID: {row[2]}, 标的: {row[3]}") print(f" Lighter价格: {row[4]}, Binance价格: {row[5]}, 价差(bps): {row[6]}") print() except Exception as e: print(f" 错误: {e}") print('\n=== Trading Events (最新10条) ===') cursor.execute('SELECT * FROM trading_events ORDER BY timestamp DESC LIMIT 10') rows = cursor.fetchall() if rows: for row in rows: ts = datetime.fromtimestamp(row[1]).strftime('%Y-%m-%d %H:%M:%S') print(f"所有列: {row}") print(f" 时间: {ts}") print(f" ID: {row[0]}, 时间戳: {row[1]}, 会话ID: {row[2]}, 标的: {row[3]}") print(f" 事件类型: {row[4]}, 价格: {row[5]}, 数量: {row[6]}, 策略状态: {row[7]}") print(f" 价差(bps): {row[8]}, 成功: {row[9]}, 错误信息: {row[10]}") print() else: print(" (无数据)") print('\n=== 数据统计 ===') cursor.execute('SELECT COUNT(*) FROM price_data') print(f"价格数据总数: {cursor.fetchone()[0]}") cursor.execute('SELECT COUNT(*) FROM trading_events') print(f"交易事件总数: {cursor.fetchone()[0]}") conn.close()