종목변경 시 캔들차트 사라지는 현상 수정

This commit is contained in:
Macbook
2026-05-24 21:51:27 +09:00
parent af230a4233
commit 3c66c562d8
14 changed files with 288 additions and 219 deletions
@@ -75,11 +75,20 @@ public class LiveStrategySettingsService {
/** 관심종목 등록 시 — DB 관심종목 = 전략 체크 대상 행 생성/갱신 */
public void enableForWatchlistMarket(Long userId, String deviceId, String market) {
GcAppSettings app = appSettingsService.getEntity(userId, deviceId);
LiveStrategySettingsDto template = defaultDtoFromApp(market, app);
LiveStrategySettingsDto template = findEntity(userId, deviceId, market)
.map(e -> mergeGlobalTemplate(toDto(e), app, market))
.orElseGet(() -> {
LiveStrategySettingsDto dto = defaultDtoFromApp(market, app);
String inherited = resolveSharedCandleType(userId, deviceId);
if (inherited != null) {
dto.setCandleType(inherited);
}
return mergeGlobalTemplate(dto, app, market);
});
template.setLiveCheck(true);
upsertEntity(userId, deviceId, template);
pinIfReady(market, template);
log.debug("[LiveStrategy] watchlist add → enabled {}", market);
log.debug("[LiveStrategy] watchlist add → enabled {} candleType={}", market, template.getCandleType());
}
/** 관심종목 해제 시 — 해당 종목 전략 체크 비활성화 */
@@ -163,10 +172,17 @@ public class LiveStrategySettingsService {
&& app.getLiveStrategyId() != null;
String candleType = template != null && template.getCandleType() != null
? LiveStrategyTimeframeService.normalize(template.getCandleType())
: null;
: resolveSharedCandleType(userId, deviceId);
for (String symbol : listWatchlistSymbols(userId, deviceId)) {
LiveStrategySettingsDto row = defaultDtoFromApp(symbol, app);
LiveStrategySettingsDto row = findEntity(userId, deviceId, symbol)
.map(e -> mergeGlobalTemplate(toDto(e), app, symbol))
.orElseGet(() -> defaultDtoFromApp(symbol, app));
row.setLiveCheck(active);
row.setStrategyId(app.getLiveStrategyId());
row.setExecutionType(app.getLiveExecutionType() != null
? app.getLiveExecutionType() : row.getExecutionType());
row.setPositionMode(app.getLivePositionMode() != null
? app.getLivePositionMode() : row.getPositionMode());
if (candleType != null) {
row.setCandleType(candleType);
}
@@ -177,6 +193,17 @@ public class LiveStrategySettingsService {
}
}
/** 관심종목 중 이미 저장된 평가 분봉 (전역 템플릿 동기화용) */
private String resolveSharedCandleType(Long userId, String deviceId) {
for (String symbol : listWatchlistSymbols(userId, deviceId)) {
Optional<GcLiveStrategySettings> row = findEntity(userId, deviceId, symbol);
if (row.isPresent() && row.get().getCandleType() != null) {
return LiveStrategyTimeframeService.normalize(row.get().getCandleType());
}
}
return null;
}
private LiveStrategySettingsDto upsertEntity(Long userId, String deviceId,
LiveStrategySettingsDto dto) {
String market = dto.getMarket() != null ? dto.getMarket() : "KRW-BTC";
@@ -207,7 +234,10 @@ public class LiveStrategySettingsService {
if (Boolean.TRUE.equals(dto.isLiveCheck()) && dto.getStrategyId() != null) {
String ct = LiveStrategyTimeframeService.normalize(
dto.getCandleType() != null ? dto.getCandleType() : "1m");
subscriptionManager.ensureMarketPinned(market, ct);
subscriptionManager.ensureMarketPinned(market, "1m");
if (!"1m".equals(ct)) {
subscriptionManager.ensureMarketPinned(market, ct);
}
}
}
@@ -8,6 +8,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Comparator;
import java.util.Optional;
import java.util.Set;
@@ -44,9 +45,12 @@ public class LiveStrategyTimeframeService {
@Transactional(readOnly = true)
public String resolveCandleTypeForMarket(String market) {
return repo.findActiveByMarket(market).stream()
.filter(s -> s.getCandleType() != null && !s.getCandleType().isBlank())
.max(Comparator.comparing(
GcLiveStrategySettings::getUpdatedAt,
Comparator.nullsLast(Comparator.naturalOrder())))
.map(GcLiveStrategySettings::getCandleType)
.map(LiveStrategyTimeframeService::normalize)
.findFirst()
.orElse("1m");
}