...
This commit is contained in:
@@ -4,6 +4,9 @@ import AutoTradeItem
|
||||
import network.TradingDecision
|
||||
import TradingLogStore
|
||||
import TradingLogStore.decisionLogs
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import getLlamaBinPath
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -61,6 +64,31 @@ object AutoTradingManager {
|
||||
// private val processedCodes = mutableSetOf<String>() // 중복 처리 방지용 (선택 사항)
|
||||
private val reanalysisList = mutableListOf<RankingStock>()
|
||||
private val retryCountMap = mutableMapOf<String, Int>()
|
||||
var shouldShowFullWindow by mutableStateOf(false)
|
||||
fun startBackgroundScheduler() {
|
||||
// scope.launch {
|
||||
// while (isActive) {
|
||||
// val now = LocalTime.now(ZoneId.of("Asia/Seoul"))
|
||||
//
|
||||
// // 1. 오전 8시 30분 ~ 15시 30분 사이인지 확인
|
||||
// if (now.isAfter(LocalTime.of(8, 30)) && now.isBefore(LocalTime.of(15, 30))) {
|
||||
// // 2. 아직 오늘 시스템 준비가 안 되었고, 설정값이 있는 경우
|
||||
// if (!isSystemReadyToday && KisSession.config.realAppKey.isNotEmpty()) {
|
||||
// println("⏰ [Scheduler] 자동 실행 시간이 되어 인증을 시작합니다.")
|
||||
// SystemSleepPreventer.wakeDisplay() //
|
||||
//
|
||||
// // 인증 및 토큰 갱신 시도
|
||||
// val success = KisAuthService.refreshAllTokens() && KisTradeService.refreshWebsocketKey()
|
||||
// if (success) {
|
||||
// isSystemReadyToday = true
|
||||
// startAutoDiscoveryLoop() // 자동 매매 루프 시작
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// delay(60_000) // 1분마다 체크
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
val globalCallback = { completeTradingDecision: TradingDecision?, isSuccess: Boolean ->
|
||||
if (isSuccess && completeTradingDecision != null) {
|
||||
@@ -389,6 +417,7 @@ object AutoTradingManager {
|
||||
}
|
||||
KisWebSocketManager.connect()
|
||||
isSystemReadyToday = true
|
||||
shouldShowFullWindow = true
|
||||
} else {
|
||||
println("❌ [System] 토큰 갱신 실패. 2분 후 재시도합니다.")
|
||||
}
|
||||
@@ -425,6 +454,16 @@ object AutoTradingManager {
|
||||
// Main.kt에 설정 화면으로 가라고 신호 전송
|
||||
stopDiscovery() // 발굴 루프 완전 폭파 (내일 8시 30분에 다시 켜짐)
|
||||
return@launch
|
||||
} else if (now.isAfter(H08M30) && now.isBefore(H08M50) && !isSystemReadyToday) {
|
||||
if (MarketUtil.canTradeToday()) {
|
||||
println("✅ [System] 오늘은 영업일입니다. 시스템을 가동합니다.")
|
||||
tryRefreshToken() // 토큰 갱신 및 화면 표시 신호(shouldShowFullWindow = true)
|
||||
} else {
|
||||
println("💤 [System] 오늘은 휴장일(또는 주말)입니다. 대기 모드를 유지합니다.")
|
||||
isSystemReadyToday = false
|
||||
delay(3600_000) // 휴장일이면 1시간 뒤에 다시 체크하도록 긴 지연시간 부여
|
||||
continue
|
||||
}
|
||||
}
|
||||
when {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user