修复复盘

This commit is contained in:
dekun
2026-05-21 20:12:25 +08:00
parent 1c449e2d97
commit f7dce1a004
6 changed files with 288 additions and 238 deletions
+14 -7
View File
@@ -59,8 +59,10 @@ from history_window_lib import (
PRESET_UTC_LAST7D,
PRESET_UTC_TODAY,
list_window_redirect_query,
normalize_bj_datetime_storage,
resolve_list_window,
resolve_window,
sql_list_time_field,
utc_window_to_bj_sql_strings,
)
@@ -4166,8 +4168,8 @@ def render_main_page(page="trade"):
for o in raw_order_list:
order_list.append(enrich_order_item(row_to_dict(o), current_capital))
raw_records = conn.execute(
"SELECT * FROM trade_records WHERE COALESCE(closed_at, created_at, opened_at) >= ? "
"AND COALESCE(closed_at, created_at, opened_at) <= ? ORDER BY id DESC LIMIT 1000",
f"SELECT * FROM trade_records WHERE {sql_list_time_field('closed_at', 'created_at', 'opened_at')} >= ? "
f"AND {sql_list_time_field('closed_at', 'created_at', 'opened_at')} <= ? ORDER BY id DESC LIMIT 1000",
(start_bj, end_bj),
).fetchall()
records = [to_effective_trade_dict(r) for r in raw_records]
@@ -5139,8 +5141,8 @@ def export_trade_records():
"SELECT id,symbol,monitor_type,key_signal_type,direction,trigger_price,stop_loss,initial_stop_loss,take_profit,"
"margin_capital,leverage,pnl_amount,hold_seconds,hold_minutes,planned_rr,actual_rr,risk_amount,"
"opened_at,closed_at,result,miss_reason,entry_reason,reviewed_entry_reason,created_at "
"FROM trade_records WHERE COALESCE(closed_at, created_at, opened_at) >= ? "
"AND COALESCE(closed_at, created_at, opened_at) <= ? ORDER BY id ASC",
f"FROM trade_records WHERE {sql_list_time_field('closed_at', 'created_at', 'opened_at')} >= ? "
f"AND {sql_list_time_field('closed_at', 'created_at', 'opened_at')} <= ? ORDER BY id ASC",
(start_bj, end_bj),
).fetchall()
conn.close()
@@ -5502,7 +5504,12 @@ def add_journal():
new_trade_while_occupied, note, image)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""",
(
entry_id, d.get("open_datetime"), d.get("close_datetime"), hold_duration, d.get("coin"), d.get("tf"),
entry_id,
normalize_bj_datetime_storage(d.get("open_datetime")),
normalize_bj_datetime_storage(d.get("close_datetime")),
hold_duration,
d.get("coin"),
d.get("tf"),
d.get("pnl"), entry_reason_norm, exit_reason_stored, d.get("expect_rr"), real_rr_text,
early_exit_raw, early_exit_reason_saved, early_exit_trigger, early_exit_note,
None, None, None, mood_issues,
@@ -5525,8 +5532,8 @@ def api_journals():
start_bj, end_bj = utc_window_to_bj_sql_strings(win["start_utc"], win["end_utc"], APP_TZ)
conn = get_db()
rows = conn.execute(
"SELECT * FROM journal_entries WHERE COALESCE(close_datetime, created_at, open_datetime) >= ? "
"AND COALESCE(close_datetime, created_at, open_datetime) <= ? ORDER BY created_at DESC LIMIT 500",
f"SELECT * FROM journal_entries WHERE {sql_list_time_field('close_datetime', 'created_at', 'open_datetime')} >= ? "
f"AND {sql_list_time_field('close_datetime', 'created_at', 'open_datetime')} <= ? ORDER BY created_at DESC LIMIT 500",
(start_bj, end_bj),
).fetchall()
conn.close()