This commit is contained in:
2026-06-09 14:16:18 +09:00
parent 075a085b92
commit affad2743e
2 changed files with 10 additions and 12 deletions
+9 -11
View File
@@ -83,20 +83,18 @@ object AutoTradingManager {
fun startBackgroundScheduler() {
scope.launch {
while (isActive) {
val seoulZone = ZoneId.of("Asia/Seoul")
val now = LocalTime.now(ZoneId.of("Asia/Seoul"))
val nowDate = LocalDate.now(seoulZone)
var checkTime = 60_000 * 3L
val isTradingDay = MarketUtil.canTradeToday()
if (isTradingDay && now.isAfter(KisSession.startTime()) && now.isBefore(KisSession.endTime()) && !shouldShowFullWindow) {
shouldShowFullWindow = true
SystemSleepPreventer.wakeDisplay()
} else if (now.isAfter(LocalTime.of(23, 50)) && now.isBefore(LocalTime.of(8, 0))) {
SystemSleepPreventer.sleepDisplay()
}
if (!isTradingDay) {
checkTime = 60_000 * 30L
// SystemSleepPreventer.wakeDisplay()
} else if ((now.isAfter(LocalTime.of(23, 50)) && now.isBefore(LocalTime.of(8, 0)))) {
// SystemSleepPreventer.sleepDisplay()
}
// if (!isTradingDay) {
// checkTime = 60_000 * 30L
// }
delay(checkTime) // 1분마다 체크
}
}
@@ -244,7 +242,7 @@ object AutoTradingManager {
if (hasCode && oldTarget != null) {
var avgPrive = oldTarget.avgPrice.toDouble()
var qty = oldTarget.quantity.toDouble()
basePrice = avgPrive//((avgPrive * qty) + (decision.currentPrice * orderQty.toInt())).div(qty!!.toInt() + (orderQty.toInt()))
basePrice = avgPrive * 1.1//((avgPrive * qty) + (decision.currentPrice * orderQty.toInt())).div(qty!!.toInt() + (orderQty.toInt()))
println("물타기 ${avgPrive}, ${qty} ${basePrice}")
}
} catch (e:Exception) {e.printStackTrace()}
@@ -850,7 +848,7 @@ object AutoTradingManager {
}
var currentBalance : UnifiedBalance? = null
private var lastFetchTime: Long = 0L // 마지막 성공 시간 (Millisecond)
private val FETCH_INTERVAL = 30 * 60 * 1000 // 30분을 밀리초로 환산 (1800000 ms)
private val FETCH_INTERVAL = 2 * 60 * 1000 // 30분을 밀리초로 환산 (1800000 ms)
suspend fun checkBalance() {
val currentTime = System.currentTimeMillis()
@@ -865,7 +863,7 @@ object AutoTradingManager {
} else {
// 30분이 지나지 않았다면 기존에 저장된 currentBalance를 그대로 사용
println("30분이 지나지 않아 기존 잔고 데이터 유지 (남은 시간: ${(FETCH_INTERVAL - (currentTime - lastFetchTime)) / 1000}초)")
println("${(FETCH_INTERVAL / (1000 * 60))}분이 지나지 않아 기존 잔고 데이터 유지 (남은 시간: ${(FETCH_INTERVAL - (currentTime - lastFetchTime)) / 1000}초)")
}
if (KisSession.config.take_profit) currentBalance?.let { resumePendingSellOrders(KisTradeService, it) }
if (KisSession.tradeConfig.auto_cancel_pending_buy) { checkAndCancelPendingBuyOrders() }