From dc8d2f44073f8c1630be0190e3654e662bbb9481 Mon Sep 17 00:00:00 2001 From: "kihong.kim" Date: Mon, 8 Dec 2025 11:07:54 +0900 Subject: [PATCH] Calculate price change based on KST 09:00 daily open MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add loadDailyOpenPrice() to fetch daily candle open price - Change price change calculation from previous candle to KST 09:00 basis - Binance daily candle starts at UTC 00:00 (= KST 09:00) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- app.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 0bee9d4..7c7509a 100644 --- a/app.js +++ b/app.js @@ -11,6 +11,8 @@ class TradingView { this.signals = []; this.gcDcMarkers = []; this.showGCDC = false; + this.dailyOpenPrice = null; // KST 09:00 기준 시가 + this.dailyOpenTime = null; // 기준 시간 this.init(); } @@ -18,10 +20,49 @@ class TradingView { async init() { this.setupCharts(); this.setupEventListeners(); + await this.loadDailyOpenPrice(); await this.loadHistoricalData(); this.connectWebSocket(); } + // KST 오전 9시 기준 시가를 가져오는 함수 + async loadDailyOpenPrice() { + try { + // 현재 KST 시간 계산 + const now = new Date(); + const kstOffset = 9 * 60 * 60 * 1000; // UTC+9 + const kstNow = new Date(now.getTime() + kstOffset); + + // 오늘 KST 09:00 시간 계산 + const kstToday9am = new Date(kstNow); + kstToday9am.setUTCHours(0, 0, 0, 0); // KST 09:00 = UTC 00:00 + + // 현재 시간이 KST 09:00 이전이면 어제 09:00 기준 + if (kstNow.getUTCHours() < 0 || (kstNow.getUTCHours() === 0 && kstNow.getUTCMinutes() === 0)) { + kstToday9am.setUTCDate(kstToday9am.getUTCDate() - 1); + } + + // UTC 기준으로 변환 (KST 09:00 = UTC 00:00) + const startTime = kstToday9am.getTime() - kstOffset; + + // 바이낸스 1일봉 데이터 가져오기 (limit=2로 오늘과 어제) + const url = `https://api.binance.com/api/v3/klines?symbol=${this.symbol}&interval=1d&limit=2`; + const response = await fetch(url); + const data = await response.json(); + + if (data && data.length > 0) { + // 가장 최근 1일봉의 시가 (UTC 00:00 = KST 09:00 기준) + const latestCandle = data[data.length - 1]; + this.dailyOpenPrice = parseFloat(latestCandle[1]); // Open price + this.dailyOpenTime = new Date(latestCandle[0]); // Open time (UTC) + + console.log('Daily open price (KST 09:00):', this.dailyOpenPrice); + } + } catch (error) { + console.error('Error loading daily open price:', error); + } + } + setupCharts() { const chartOptions = { layout: { @@ -537,7 +578,6 @@ class TradingView { if (this.candleData.length === 0) return; const currentCandle = this.candleData[this.candleData.length - 1]; - const prevCandle = this.candleData[this.candleData.length - 2]; const priceEl = document.getElementById('current-price'); const changeEl = document.getElementById('price-change'); @@ -547,13 +587,15 @@ class TradingView { maximumFractionDigits: 2 })}`; - if (prevCandle) { - const change = currentCandle.close - prevCandle.close; - const changePercent = (change / prevCandle.close) * 100; + // KST 09:00 기준 변동률 계산 + if (this.dailyOpenPrice) { + const change = currentCandle.close - this.dailyOpenPrice; + const changePercent = (change / this.dailyOpenPrice) * 100; const isUp = change >= 0; changeEl.textContent = `${isUp ? '+' : ''}${change.toFixed(2)} (${isUp ? '+' : ''}${changePercent.toFixed(2)}%)`; changeEl.className = isUp ? 'up' : 'down'; + changeEl.title = 'KST 09:00 기준 변동률'; } }