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
@@ -52,10 +52,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,
@@ -842,13 +846,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:
@@ -5837,6 +5860,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,
@@ -7353,12 +7377,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"
+6 -1
View File
@@ -712,8 +712,13 @@
<option value="{{ n }}" {% if n == journal_chart_default_limit %}selected{% endif %}>{{ n }}</option>
{% endfor %}
</select>
<label style="font-size:.82rem;color:#9aa">K线截止</label>
<select name="journal_chart_anchor" id="journal-chart-anchor" style="min-width:96px" title="K线窗口右端对齐的时间">
<option value="close" {% if journal_chart_default_anchor == 'close' %}selected{% endif %}>平仓时间</option>
<option value="now" {% if journal_chart_default_anchor == 'now' %}selected{% endif %}>当前时间</option>
</select>
</div>
<div class="sub" style="font-size:.72rem;color:#8892b0;margin-top:4px">双周期上下排列;平仓时间为锚点向前取 K 线;标注开仓、平仓与止损位</div>
<div class="sub" id="journal-chart-anchor-hint" style="font-size:.72rem;color:#8892b0;margin-top:4px">双周期上下排列;截止=平仓时间:开仓前背景至平仓;截止=当前时间:最近 N 根至此刻(可看平仓后走势);标注开仓、平仓与止损位</div>
<div class="form-row" style="margin-top:8px">
<button type="button" style="background:#1f3a5a" onclick="prefillJournalByImage()">AI识别预填(你再手动改原因)</button>
</div>