import json import sys def analyze_trades(file_path): try: with open(file_path, 'r', encoding='utf-8') as f: trades = json.load(f) except Exception as e: print(f"Error reading file: {e}") return print(f"Analyzing {len(trades)} trades...") tp_losses = [] sync_exits = [] for t in trades: pnl = t.get('盈亏', 0) reason = t.get('离场原因', '') duration = t.get('持仓时长分钟') if reason == 'take_profit' and pnl < 0: tp_losses.append(t) if reason == 'sync' and duration == 0: sync_exits.append(t) print("\n[Anomalies 1: Negative PnL with 'take_profit' reason]") for t in tp_losses: print(f"ID: {t.get('交易ID')} | Symbol: {t.get('交易对')} | Side: {t.get('方向')} | " f"Entry: {t.get('入场价')} | Exit: {t.get('出场价')} | " f"PnL: {t.get('盈亏')} | TP Price: {t.get('止盈价')}") print("\n[Anomalies 2: Immediate Sync Exits (Duration 0)]") for t in sync_exits: print(f"ID: {t.get('交易ID')} | Symbol: {t.get('交易对')} | PnL: {t.get('盈亏')} | " f"Entry Time: {t.get('入场时间')} | Exit Time: {t.get('平仓时间')}") if __name__ == "__main__": analyze_trades('/Users/vivian/work/python/auto_trade_sys/交易记录_2026-02-04T06-46-43.json')