This commit is contained in:
2026-03-19 11:41:21 +09:00
parent eee4f1bab7
commit f830163940
3 changed files with 82 additions and 43 deletions
+20 -2
View File
@@ -3,6 +3,7 @@ package service
import AutoTradeItem
import network.TradingDecision
import TradingLogStore
import TradingLogStore.decisionLogs
import getLlamaBinPath
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -395,9 +396,13 @@ object AutoTradingManager {
} catch (e: Exception) {}
}
var onMarketClosed: (() -> Unit)? = null
var now = LocalTime.now(ZoneId.of("Asia/Seoul"))
var currentTimeMillis = System.currentTimeMillis()
var waitTime = 0.2
val H16 = LocalTime.of(16, 0)
val H08M50 = LocalTime.of(8, 50)
private fun runDiscoveryLoop(tradeService: KisTradeService, callback: TradingDecisionCallback) {
discoveryJob = scope.launch {
println("🚀 [AutoTrading] 발굴 루프 시작: ${LocalDateTime.now()}")
@@ -406,9 +411,22 @@ object AutoTradingManager {
now = LocalTime.now(ZoneId.of("Asia/Seoul"))
currentTimeMillis = System.currentTimeMillis()
lastTickTime.set(System.currentTimeMillis()) // 생존 신고
// [수정] 16시 이후이거나 8시 30분 이전이면 모든 로직 중단 및 초기화
if (now.isAfter(LocalTime.of(16, 0)) || now.isBefore(LocalTime.of(8, 30))) {
println("🌙 [System] 마감 시간 도달. 자원 정리 후 대기 모드(설정 화면)로 전환합니다.")
SystemSleepPreventer.sleepDisplay() // 모니터 끄기
KisWebSocketManager.disconnect()
BrowserManager.closeIfIdle(0)
LlamaServerManager.stopAll() // AI 서버 완전 종료
TradingLogStore.clear()
onMarketClosed?.invoke() // Main.kt에 설정 화면으로 가라고 신호 전송
stopDiscovery() // 발굴 루프 완전 폭파 (내일 8시 30분에 다시 켜짐)
return@launch
}
when {
//장중
now.isBefore(LocalTime.of(16, 0)) && now.isAfter(LocalTime.of(8, 50)) -> {
now.isBefore(H16) && now.isAfter(H08M50) -> {
waitTime = 0.2
if (now.isAfter(LocalTime.of(8, 0)) && now.isBefore(LocalTime.of(15, 30))) {
if (!KisSession.isMarketTokenValid() || !KisSession.isTradeTokenValid()) {
@@ -491,7 +509,7 @@ object AutoTradingManager {
}
//장외
now.isAfter(LocalTime.of(18, 0)) || now.isBefore(LocalTime.of(8, 50)) -> {
now.isAfter(H16) || now.isBefore(H08M50) -> {
when {
(now.hour == 0 && now.minute == 0 && (isSystemReadyToday || isSystemCleanedUpToday)) -> {
waitTime = 10.0