...
This commit is contained in:
parent
558a39e2d3
commit
d0bdc57a1e
@ -627,11 +627,15 @@ object KisTradeService {
|
||||
|
||||
if (!response.status.isSuccess()) {
|
||||
println("❌ [Step $pageCount] $markgetCode HTTP 에러 발생: ${response.status}")
|
||||
return Result.failure(Exception("HTTP Error: ${response.status}"))
|
||||
if (allHoldings.isNotEmpty() && totalBalance != null) {
|
||||
return Result.success(totalBalance.copy(output1 = allHoldings))
|
||||
}
|
||||
return Result.failure(Exception("HTTP Error: ${response.status} ${response.body<String>()}"))
|
||||
}
|
||||
|
||||
val body = response.body<StockBalanceResponse>()
|
||||
println("✅ [Step $pageCount] $markgetCode 수신 완료 - 종목 수: ${body.output1.size}")
|
||||
println("✅ [Step $pageCount] $markgetCode 수신 완료 - 종목 수: \n${body.output2}\n\n")
|
||||
// println("✅ [Step $pageCount] $markgetCode 수신 완료 - 종목 수: ${body.output1.size}")
|
||||
|
||||
allHoldings.addAll(body.output1)
|
||||
if (totalBalance == null) totalBalance = body
|
||||
@ -647,7 +651,7 @@ object KisTradeService {
|
||||
pageCount++
|
||||
trCont = "N"
|
||||
println("⏳ [연속 조회] 250ms 대기 후 다음 페이지 요청...")
|
||||
delay(250) // API 과부하 방지
|
||||
delay(350) // API 과부하 방지
|
||||
}
|
||||
|
||||
} while (trCont == "N")
|
||||
|
||||
@ -836,7 +836,9 @@ object AutoTradingManager {
|
||||
|
||||
suspend fun checkBalance(isMorning: Boolean = true) {
|
||||
if (isMorning) {
|
||||
currentBalance = KisTradeService.fetchIntegratedBalance().getOrNull()
|
||||
KisTradeService.fetchIntegratedBalance().getOrNull()?.let {
|
||||
currentBalance = it
|
||||
}
|
||||
if (KisSession.config.take_profit) currentBalance?.let { resumePendingSellOrders(KisTradeService, it) }
|
||||
if (KisSession.tradeConfig.auto_cancel_pending_buy) { checkAndCancelPendingBuyOrders() }
|
||||
} else {
|
||||
@ -906,7 +908,7 @@ object AutoTradingManager {
|
||||
|
||||
suspend fun executeMarketLoop() {
|
||||
checkBalance()
|
||||
val myCash = currentBalance?.deposit?.replace(",", "")?.toLongOrNull() ?: 0L
|
||||
val myCash = currentBalance?.deposit?.replace(",", "")?.toLongOrNull() ?: KisSession.config.getValues(ConfigIndex.MAX_PRICE_INDEX).toLong()
|
||||
val myHoldings = currentBalance?.getHoldings()?.filter { !it.isTodayEntry }?.map { it.code }?.toSet() ?: emptySet()
|
||||
val pendingStocks = DatabaseFactory.findAllMonitoringTrades().map { it.code }
|
||||
|
||||
@ -1086,7 +1088,7 @@ object AutoTradingManager {
|
||||
}
|
||||
val currentPrice = today.stck_prpr.toDouble()
|
||||
|
||||
if (currentPrice > myCash || currentPrice > maxBudget || currentPrice > maxPrice || currentPrice < minPrice) {
|
||||
if ((myCash > 10L && currentPrice > myCash) || currentPrice > maxBudget || currentPrice > maxPrice || currentPrice < minPrice) {
|
||||
print("-> 가격 정책으로 제외 [1주:${currentPrice}, 자산:${myCash}, 최소 기준:${minPrice}, 최대 기준:${maxPrice}] | ")
|
||||
return@withTimeout
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user