...
This commit is contained in:
@@ -12,6 +12,7 @@ import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import io.ktor.http.*
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import io.ktor.utils.io.CancellationException
|
||||
import kotlinx.serialization.json.Json
|
||||
import model.CandleData
|
||||
import model.RankingResponse
|
||||
@@ -22,6 +23,7 @@ import model.StockBalanceResponse
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
@@ -30,6 +32,7 @@ import model.*
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import kotlin.coroutines.coroutineContext
|
||||
|
||||
object KisTradeService {
|
||||
private val client = HttpClient(CIO) {
|
||||
@@ -525,6 +528,7 @@ object KisTradeService {
|
||||
|
||||
try {
|
||||
do {
|
||||
if (!coroutineContext.isActive) throw _root_ide_package_.io.ktor.utils.io.CancellationException("UI에서 작업을 취소함") // [추가]
|
||||
println("📡 [Step $pageCount] 요청 전송 중... (tr_cont: $trCont)")
|
||||
val response = client.get("$baseUrl/uapi/domestic-stock/v1/trading/inquire-balance") {
|
||||
header("authorization", "Bearer ${config.tradeToken}")
|
||||
@@ -582,6 +586,10 @@ object KisTradeService {
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
if (e is CancellationException) {
|
||||
println("ℹ️ [잔고조회] 사용자가 화면을 벗어나 조회를 중단합니다.")
|
||||
throw e
|
||||
}
|
||||
println("💥 [Fatal Error] 잔고 조회 중 예외 발생: ${e.message}")
|
||||
e.printStackTrace()
|
||||
return Result.failure(e)
|
||||
|
||||
Reference in New Issue
Block a user