This commit is contained in:
lunaticbum 2026-06-04 10:51:24 +09:00
parent aa4f8daadf
commit df5febfb42
2 changed files with 18 additions and 7 deletions

View File

@ -610,8 +610,8 @@ object KisTradeService {
println("📡 [Step $pageCount] 요청 전송 중... (tr_cont: $trCont)") println("📡 [Step $pageCount] 요청 전송 중... (tr_cont: $trCont)")
val response = client.get("$baseUrl/uapi/domestic-stock/v1/trading/inquire-balance") { val response = client.get("$baseUrl/uapi/domestic-stock/v1/trading/inquire-balance") {
header("authorization", "Bearer ${config.tradeToken}") header("authorization", "Bearer ${config.tradeToken}")
header("appkey", if (config.isSimulation) config.vtsAppKey else config.realAppKey) header("appkey", config.realAppKey)
header("appsecret", if (config.isSimulation) config.vtsSecretKey else config.realSecretKey) header("appsecret", config.realSecretKey)
header("tr_id", trId) header("tr_id", trId)
header("tr_cont", trCont) header("tr_cont", trCont)
@ -654,7 +654,7 @@ object KisTradeService {
pageCount++ pageCount++
trCont = "N" trCont = "N"
println("⏳ [연속 조회] 250ms 대기 후 다음 페이지 요청...") println("⏳ [연속 조회] 250ms 대기 후 다음 페이지 요청...")
delay(400) // API 과부하 방지 delay(500) // API 과부하 방지
} }
} while (trCont == "N") } while (trCont == "N")

View File

@ -848,16 +848,27 @@ object AutoTradingManager {
return batch return batch
} }
var currentBalance : UnifiedBalance? = null 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) { suspend fun checkBalance() {
if (isMorning) { val currentTime = System.currentTimeMillis()
if (currentBalance == null || (currentTime - lastFetchTime) > FETCH_INTERVAL) {
KisTradeService.fetchIntegratedBalance().getOrNull()?.let { KisTradeService.fetchIntegratedBalance().getOrNull()?.let {
currentBalance = it currentBalance = it
lastFetchTime = currentTime // 호출 성공 시 현재 시간으로 갱신
println("잔고 동기화 완료")
} ?: run {
println("잔고 조회 실패 (네트워크 오류 등)")
}
} else {
// 30분이 지나지 않았다면 기존에 저장된 currentBalance를 그대로 사용
println("30분이 지나지 않아 기존 잔고 데이터 유지 (남은 시간: ${(FETCH_INTERVAL - (currentTime - lastFetchTime)) / 1000}초)")
} }
if (KisSession.config.take_profit) currentBalance?.let { resumePendingSellOrders(KisTradeService, it) } if (KisSession.config.take_profit) currentBalance?.let { resumePendingSellOrders(KisTradeService, it) }
if (KisSession.tradeConfig.auto_cancel_pending_buy) { checkAndCancelPendingBuyOrders() } if (KisSession.tradeConfig.auto_cancel_pending_buy) { checkAndCancelPendingBuyOrders() }
} else {
}
} }
suspend fun checkAndCancelPendingBuyOrders( suspend fun checkAndCancelPendingBuyOrders(