fix: 분봉 당일시가대비 baseline 오류 + 우상단 전일대비 텍스트 제거

- 당일시가(dayOpen)를 range 슬라이스 전 '오늘 첫 봉' 시가로 고정 → 1h/30min 등
  구간을 좁혀도 baseline 동일. 마지막 봉 당일시가대비 = 현재가 등락율 일치.
  (기존: candles[0]가 슬라이스된 구간 첫 봉이라 baseline이 틀렸음)
- 우상단 '전일대비 X%' 텍스트 제거(관리자 요청). 전일종가 기준선은 유지.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hyowons
2026-06-10 14:15:03 +09:00
parent 51d0384ed4
commit 8bfaecbd1e
2 changed files with 8 additions and 11 deletions
+3 -1
View File
@@ -10024,6 +10024,8 @@ class Handler(BaseHTTPRequestHandler):
if not mins:
self.send_error(404, 'no minute candles')
return
# 당일 시가 = 오늘 첫 봉 시가. range 슬라이스 전에 캡처 — 구간을 좁혀도 baseline 고정.
day_open = mins[0].get('open') or 0
# range 슬라이스 — 최근 N 봉만.
if range_minutes is not None:
num_bars = max(1, range_minutes // tic_scope)
@@ -10061,7 +10063,7 @@ class Handler(BaseHTTPRequestHandler):
prev_close = _pc
except Exception:
pass
svg = sa.render_svg_chart(snap, range_key='1Y', ref_price=prev_close, intraday=True)
svg = sa.render_svg_chart(snap, range_key='1Y', ref_price=prev_close, intraday=True, day_open=day_open)
body = svg.encode('utf-8')
body, enc = _maybe_gzip(body, self.headers.get('Accept-Encoding'))
self.send_response(200)
@@ -546,7 +546,7 @@ VOL_BOT = VOL_TOP + VOL_PANEL_H
CHART_RANGE_DAYS = {'1Y': 250, '6M': 120, '1M': 21}
def render_svg_chart(snap: dict, range_key: str = '1Y', ref_price: float | None = None, intraday: bool = False) -> str:
def render_svg_chart(snap: dict, range_key: str = '1Y', ref_price: float | None = None, intraday: bool = False, day_open: float | None = None) -> str:
"""캔들 + SMA 3선 + 거래량 막대 인라인 SVG.
range_key: '1Y' (250일) | '6M' (120일) | '1M' (21일). 같은 snapshot 데이터에서 슬라이스만.
@@ -611,8 +611,9 @@ def render_svg_chart(snap: dict, range_key: str = '1Y', ref_price: float | None
],
'ymin': y_min,
'ymax': y_max,
# 분봉일 때만 당일 시가(첫 봉 시가) — 크로스헤어 툴팁의 '당일시가 대비 등락률'용.
'dayOpen': (candles[0]['open'] if (intraday and candles) else 0),
# 분봉일 때만 당일 시가 — 크로스헤어 툴팁의 '당일시가 대비 등락률'용.
# day_open(슬라이스 전 오늘 첫 봉 시가)을 caller가 넘기면 그걸 baseline으로 (구간 슬라이스 영향 X).
'dayOpen': (int(day_open) if (intraday and day_open) else 0),
'priceTop': PRICE_TOP,
'priceBot': PRICE_BOT,
'volTop': VOL_TOP,
@@ -712,13 +713,7 @@ def render_svg_chart(snap: dict, range_key: str = '1Y', ref_price: float | None
parts.append(
f'<text x="{CHART_W - CHART_PAD_R + 6}" y="{ry-4:.1f}" text-anchor="start" fill="#eab308" font-size="24">전일</text>'
)
last_close = candles[-1]['close']
pct = (last_close / ref_price - 1) * 100
pc = '#ef4444' if pct > 0 else '#3b82f6' if pct < 0 else '#9ca3af' # 한국 관습: 상승=빨강
parts.append(
f'<text x="{CHART_W - CHART_PAD_R - 8}" y="{PRICE_TOP + 36}" text-anchor="end" '
f'fill="{pc}" font-size="30" font-weight="700">{last_close:,} 전일대비 {pct:+.2f}%</text>'
)
# 우상단 '전일대비 X%' 텍스트는 제거(관리자 요청) — 전일종가 기준선만 유지.
# SMA 범례
legend_y = PRICE_TOP + 14