This commit is contained in:
2026-06-04 10:51:24 +09:00
parent aa4f8daadf
commit df5febfb42
2 changed files with 18 additions and 7 deletions
+15 -4
View File
@@ -848,16 +848,27 @@ object AutoTradingManager {
return batch
}
var currentBalance : UnifiedBalance? = null
private var lastFetchTime: Long = 0L // 마지막 성공 시간 (Millisecond)
private val FETCH_INTERVAL = 30 * 60 * 1000 // 30분을 밀리초로 환산 (1800000 ms)
suspend fun checkBalance(isMorning: Boolean = true) {
if (isMorning) {
suspend fun checkBalance() {
val currentTime = System.currentTimeMillis()
if (currentBalance == null || (currentTime - lastFetchTime) > FETCH_INTERVAL) {
KisTradeService.fetchIntegratedBalance().getOrNull()?.let {
currentBalance = it
lastFetchTime = currentTime // 호출 성공 시 현재 시간으로 갱신
println("잔고 동기화 완료")
} ?: run {
println("잔고 조회 실패 (네트워크 오류 등)")
}
if (KisSession.config.take_profit) currentBalance?.let { resumePendingSellOrders(KisTradeService, it) }
if (KisSession.tradeConfig.auto_cancel_pending_buy) { checkAndCancelPendingBuyOrders() }
} else {
// 30분이 지나지 않았다면 기존에 저장된 currentBalance를 그대로 사용
println("30분이 지나지 않아 기존 잔고 데이터 유지 (남은 시간: ${(FETCH_INTERVAL - (currentTime - lastFetchTime)) / 1000}초)")
}
if (KisSession.config.take_profit) currentBalance?.let { resumePendingSellOrders(KisTradeService, it) }
if (KisSession.tradeConfig.auto_cancel_pending_buy) { checkAndCancelPendingBuyOrders() }
}
suspend fun checkAndCancelPendingBuyOrders(