This commit is contained in:
dekun
2026-05-27 15:32:46 +08:00
parent 7bb3f942ed
commit 6093bf6b94
9 changed files with 269 additions and 24 deletions
+32 -5
View File
@@ -53,10 +53,14 @@ from journal_chart_lib import (
JOURNAL_CHART_TF_CHOICES,
compose_chart_panels,
marker_points_for_timeframe,
parse_journal_chart_anchor,
parse_journal_chart_limit,
parse_journal_chart_timeframes,
JOURNAL_CHART_DEFAULT_ANCHOR,
price_levels_from_marker_payload,
render_candles_subplot,
trade_review_fetch_window,
trim_rows_for_trade_review,
)
from key_sl_tp_lib import (
breakeven_enabled_from_row,
@@ -836,13 +840,32 @@ def generate_multi_timeframe_chart_png(
default_marker_tfs = {str(t).strip().lower() for t in timeframes}
price_levels = price_levels_from_marker_payload(marker_payload)
for tf in timeframes:
rows = []
try:
ohlcv = _fetch_ohlcv_ending_at(exchange_symbol, tf, limit, end_ts_ms)
if not ohlcv and end_ts_ms:
ohlcv = exchange.fetch_ohlcv(exchange_symbol, timeframe=tf, limit=limit)
if layout == "vertical" and marker_payload:
win = trade_review_fetch_window(
marker_payload.get("entry_ts_ms"),
marker_payload.get("exit_ts_ms"),
tf,
limit,
anchor=marker_payload.get("chart_anchor"),
now_ms=marker_payload.get("now_ts_ms"),
)
if win:
ohlcv = exchange.fetch_ohlcv(
exchange_symbol,
timeframe=tf,
since=max(0, int(win["since_ms"])),
limit=int(win["fetch_limit"]),
)
rows = trim_rows_for_trade_review(_ohlcv_to_rows(ohlcv), win)
if not rows:
ohlcv = _fetch_ohlcv_ending_at(exchange_symbol, tf, limit, end_ts_ms)
if not ohlcv and end_ts_ms:
ohlcv = exchange.fetch_ohlcv(exchange_symbol, timeframe=tf, limit=limit)
rows = _ohlcv_to_rows(ohlcv)[-limit:]
except Exception:
ohlcv = []
rows = _ohlcv_to_rows(ohlcv)[-limit:]
rows = []
title = f"{title_prefix} | {tf} x{len(rows)}"
tf_key = str(tf).strip().lower()
if marker_payload:
@@ -5844,6 +5867,7 @@ def render_main_page(page="trade"):
journal_chart_default_tf1=JOURNAL_CHART_DEFAULT_TF1,
journal_chart_default_tf2=JOURNAL_CHART_DEFAULT_TF2,
journal_chart_default_limit=JOURNAL_CHART_DEFAULT_LIMIT,
journal_chart_default_anchor=JOURNAL_CHART_DEFAULT_ANCHOR,
exchange_display=EXCHANGE_DISPLAY_NAME,
max_active_positions=MAX_ACTIVE_POSITIONS,
manual_min_planned_rr=MANUAL_MIN_PLANNED_RR,
@@ -7433,12 +7457,15 @@ def add_journal():
ORDER_CHART_TFS[:2] if ORDER_CHART_TFS else None,
)
journal_limit = parse_journal_chart_limit(d.get("journal_chart_limit"), ORDER_CHART_LIMIT)
chart_anchor = parse_journal_chart_anchor(d.get("journal_chart_anchor"))
marker_payload = {
"entry_ts_ms": _local_input_datetime_to_ms(d.get("open_datetime")),
"exit_ts_ms": _local_input_datetime_to_ms(d.get("close_datetime")),
"entry_price": d.get("entry_price_hint"),
"exit_price": d.get("exit_price_hint"),
"stop_loss_price": d.get("stop_loss_hint"),
"chart_anchor": chart_anchor,
"now_ts_ms": int(app_now().timestamp() * 1000),
}
try:
chart_fname = f"journal_{entry_id}.png"