diff --git a/src/main/kotlin/report/TradingReportManager.kt b/src/main/kotlin/report/TradingReportManager.kt index eac7590..16f1f55 100644 --- a/src/main/kotlin/report/TradingReportManager.kt +++ b/src/main/kotlin/report/TradingReportManager.kt @@ -59,9 +59,9 @@ object TradingReportManager : TradingReportService { private val activePositions = mutableMapOf() override fun recordAssetSnapshot(type: SnapshotType, balance: UnifiedBalance, remark: String?) { - if (!KisSession.tradeConfig.useAutoRepost) { - return - } +// if (!KisSession.tradeConfig.useAutoRepost) { +// return +// } CoroutineScope(Dispatchers.IO).launch { println("❌ [Report] 리포트 비동기 생성 중 오류 발생: gggg") val todayDate = LocalDate.now().toString() diff --git a/src/main/kotlin/service/AutoTradingManager.kt b/src/main/kotlin/service/AutoTradingManager.kt index effdb55..a77fbef 100644 --- a/src/main/kotlin/service/AutoTradingManager.kt +++ b/src/main/kotlin/service/AutoTradingManager.kt @@ -442,11 +442,32 @@ object AutoTradingManager { && holding.valuationProfitAmount.toDouble() >= KisSession.config.getValues(ConfigIndex.LOSS_MAX_MONEY)) { println("${holding.name} ${holding.profitRate.toDouble()} ${holding.valuationProfitAmount.toDouble()} ${KisSession.config.getValues(ConfigIndex.LOSS_MAX_MONEY)} , ${KisSession.config.getValues(ConfigIndex.LOSS_MINRATE)} , ${KisSession.config.getValues(ConfigIndex.STOP_LOSS)}") val profit = holding.profitRate.toDouble() - TradingLogStore.addNotice( - "보유주식[${holding.name}]", - holding.code, - "수익률($profit%) -> ${holding.valuationProfitAmount} 손해 중이며 현제 손절 가이드에 적합함." - ) +// TradingLogStore.addNotice( +// "보유주식[${holding.name}]", +// holding.code, +// "수익률($profit%) -> ${holding.valuationProfitAmount} 손해 중이며 현제 손절 가이드에 적합함." +// ) + + var targetPrice = holding.avgPrice.toDouble() + + tradeService.postOrder( + stockCode = holding.code, + qty = holding.availOrderCount, + price = targetPrice.toInt().toString(), + isBuy = false, + orderDivision = if (marketCode.equals("Y")) "07" else "", + marketCode = if (marketCode.equals("Y")) "KRX" else "NXT" + ).onSuccess { newOrderNo -> + println("✅ [${if(marketCode.equals("Y"))"시간외 단일가" else "대체거래소"} 손절가이드에 따라 매매 주문 완료] ${holding.name}: $newOrderNo") + TradingLogStore.addSellLog( + holding.code, + targetPrice.toString(), + "SELL", + "☠️ 보유 주식 손절 처리 [수익률 : ${profit}%] ${holding.valuationProfitAmount} 손해 중이며 ${if(marketCode.equals("Y"))"시간외 단일가" else "대체거래소"}에 손절가이드에 따라 매매 주문 완료." + ) + }.onFailure { err-> + println("✅ [${if(marketCode.equals("Y"))"시간외 단일가" else "대체거래소"} 손절가이드에 따라 매매 주문 실패] ${holding.name}: $err") + } } analyzeDeepLossHoldingsAfterMarket(holding) } @@ -482,7 +503,9 @@ object AutoTradingManager { targetPrice = targetPrice isBefore930 = true } else { - targetPrice = MarketUtil.roundToTickSize(targetPrice + MarketUtil.getTickSize(targetPrice)) + targetPrice = MarketUtil.roundToTickSize( + targetPrice + MarketUtil.getTickSize(targetPrice) + ) } println("🔄 [보유 주식 주문] ${holding.name} (${holding.code}) 매도 목표 ${targetPrice} 미체결 매도 건 재주문 시도") tradeService.postOrder( @@ -498,18 +521,20 @@ object AutoTradingManager { "SELL", "🎊 보유 주식[예상수익 : ${holding.profitRate}] ${if (isBefore930) "09:30 이전 현시세{${holding.currentPrice}}로 매도[$targetPrice] 주문" else "09:30 이후 시세{${holding.currentPrice}} 기준 호가 위 매도[$targetPrice] 주문"} 완료" ) - DatabaseFactory.saveAutoTrade(AutoTradeItem( - orderNo = newOrderNo, - code = holding.code, - name = holding.name, - quantity = holding.quantity.toInt(), - profitRate = 0.0, - stopLossRate = 0.0, - targetPrice = targetPrice.toDouble(), - stopLossPrice = 0.0, - status = "SELLING", - isDomestic = true - )) + DatabaseFactory.saveAutoTrade( + AutoTradeItem( + orderNo = newOrderNo, + code = holding.code, + name = holding.name, + quantity = holding.quantity.toInt(), + profitRate = 0.0, + stopLossRate = 0.0, + targetPrice = targetPrice.toDouble(), + stopLossPrice = 0.0, + status = "SELLING", + isDomestic = true + ) + ) syncAndExecute(newOrderNo) }.onFailure { TradingLogStore.addSellLog( @@ -528,8 +553,9 @@ object AutoTradingManager { && holding.valuationProfitAmount.toDouble() >= KisSession.config.getValues(ConfigIndex.LOSS_MAX_MONEY)) { println("${holding.name} ${holding.profitRate.toDouble()} ${holding.valuationProfitAmount.toDouble()} ${KisSession.config.getValues(ConfigIndex.LOSS_MAX_MONEY)} , ${KisSession.config.getValues(ConfigIndex.LOSS_MINRATE)} , ${KisSession.config.getValues(ConfigIndex.STOP_LOSS)}") val profit = holding.profitRate.toDouble() - var targetPrice = holding.currentPrice.toDouble() - targetPrice = MarketUtil.roundToTickSize(targetPrice + (MarketUtil.getTickSize(targetPrice) * 3.0)) +// var targetPrice = holding.currentPrice.toDouble() +// targetPrice = MarketUtil.roundToTickSize(targetPrice + (MarketUtil.getTickSize(targetPrice) * 3.0)) + var targetPrice = holding.avgPrice.toDouble() tradeService.postOrder( stockCode = holding.code, @@ -542,7 +568,7 @@ object AutoTradingManager { holding.code, targetPrice.toString(), "SELL", - "☠️ 보유 주식 손절 처리 [수익률 : ${profit}%] ${holding.valuationProfitAmount} 손해 중이며 현시세{${holding.currentPrice}}로 기준 호가 위 매도[$targetPrice] 주문 완료" + "☠️ 보유 주식 손절 처리 [수익률 : ${profit}%] ${holding.valuationProfitAmount} 손해 중이며 현제 손절 가이드에 적합함 시장가 매도." ) }.onFailure { err-> println("✅ [보유 주식 손절 처리] 실패 ${err.message}")