종목변경 시 캔들차트 사라지는 현상 수정
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package com.goldenchart.config;
|
||||
|
||||
import com.goldenchart.entity.GcAppSettings;
|
||||
import com.goldenchart.entity.GcLiveStrategySettings;
|
||||
import com.goldenchart.entity.GcWatchlist;
|
||||
import com.goldenchart.repository.GcLiveStrategySettingsRepository;
|
||||
import com.goldenchart.repository.GcWatchlistRepository;
|
||||
import com.goldenchart.service.AppSettingsService;
|
||||
import com.goldenchart.service.LiveStrategyEvaluator;
|
||||
import com.goldenchart.service.LiveStrategyTimeframeService;
|
||||
import com.goldenchart.websocket.DynamicSubscriptionManager;
|
||||
import com.goldenchart.websocket.UpbitWebSocketClient;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -23,9 +26,10 @@ import org.springframework.stereotype.Component;
|
||||
public class LiveStrategyStartupRunner implements ApplicationRunner {
|
||||
|
||||
private final AppSettingsService appSettingsService;
|
||||
private final GcWatchlistRepository watchlistRepo;
|
||||
private final DynamicSubscriptionManager subscriptionManager;
|
||||
private final LiveStrategyEvaluator liveStrategyEvaluator;
|
||||
private final GcWatchlistRepository watchlistRepo;
|
||||
private final GcLiveStrategySettingsRepository liveSettingsRepo;
|
||||
private final DynamicSubscriptionManager subscriptionManager;
|
||||
private final LiveStrategyEvaluator liveStrategyEvaluator;
|
||||
private final UpbitWebSocketClient upbitWebSocketClient;
|
||||
|
||||
@Override
|
||||
@@ -33,13 +37,18 @@ public class LiveStrategyStartupRunner implements ApplicationRunner {
|
||||
// 디바이스별 전역 설정이 켜져 있고 전략이 지정된 경우, DB 관심종목 전체 고정 구독
|
||||
int pinned = 0;
|
||||
for (GcWatchlist w : watchlistRepo.findAll()) {
|
||||
Long userId = w.getUserId();
|
||||
String deviceId = w.getDeviceId();
|
||||
if (deviceId == null) continue;
|
||||
GcAppSettings app = appSettingsService.getEntity(null, deviceId);
|
||||
if (userId == null && deviceId == null) continue;
|
||||
GcAppSettings app = appSettingsService.getEntity(userId, deviceId);
|
||||
if (!Boolean.TRUE.equals(app.getLiveStrategyCheck()) || app.getLiveStrategyId() == null) {
|
||||
continue;
|
||||
}
|
||||
String ct = resolvePinnedCandleType(w);
|
||||
subscriptionManager.ensureMarketPinned(w.getSymbol(), "1m");
|
||||
if (!"1m".equals(ct)) {
|
||||
subscriptionManager.ensureMarketPinned(w.getSymbol(), ct);
|
||||
}
|
||||
liveStrategyEvaluator.invalidateCache(w.getSymbol());
|
||||
pinned++;
|
||||
}
|
||||
@@ -49,4 +58,20 @@ public class LiveStrategyStartupRunner implements ApplicationRunner {
|
||||
// WS 연결 직후 addMarket 이 구독 패킷을 놓치는 경우 대비
|
||||
upbitWebSocketClient.resubscribeAll();
|
||||
}
|
||||
|
||||
private String resolvePinnedCandleType(GcWatchlist w) {
|
||||
if (w.getUserId() != null) {
|
||||
return liveSettingsRepo.findByUserIdAndMarket(w.getUserId(), w.getSymbol())
|
||||
.map(GcLiveStrategySettings::getCandleType)
|
||||
.map(LiveStrategyTimeframeService::normalize)
|
||||
.orElse("1m");
|
||||
}
|
||||
if (w.getDeviceId() != null) {
|
||||
return liveSettingsRepo.findByDeviceIdAndMarket(w.getDeviceId(), w.getSymbol())
|
||||
.map(GcLiveStrategySettings::getCandleType)
|
||||
.map(LiveStrategyTimeframeService::normalize)
|
||||
.orElse("1m");
|
||||
}
|
||||
return "1m";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user