diff --git a/src/main/kotlin/model/AppConfig.kt b/src/main/kotlin/model/AppConfig.kt index 7fbd4da..7ea4b15 100644 --- a/src/main/kotlin/model/AppConfig.kt +++ b/src/main/kotlin/model/AppConfig.kt @@ -122,7 +122,6 @@ data class AppConfig( return if (isSimulation) vtsAccountNo else realAccountNo } - var firstSet = mutableSetOf() fun setValues(index :ConfigIndex , value : Double) { val oldValue = getValues(index) when (index) { @@ -153,26 +152,24 @@ data class AppConfig( ConfigIndex.GRADE_3_ALLOCATIONRATE -> {GRADE_3_ALLOCATIONRATE = value} ConfigIndex.GRADE_2_ALLOCATIONRATE -> {GRADE_2_ALLOCATIONRATE = value} ConfigIndex.GRADE_1_ALLOCATIONRATE -> {GRADE_1_ALLOCATIONRATE = value} - ConfigIndex.LOSS_MAXRATE -> { loss_max = value} - ConfigIndex.LOSS_MINRATE -> { loss_min = value} - ConfigIndex.LOSS_MAX_MONEY -> { loss_money = value} - ConfigIndex.STOP_LOSS -> { stop_Loss = value > 0.1} + ConfigIndex.LOSS_MAXRATE -> { loss_max = abs(value) * -1 } + ConfigIndex.LOSS_MINRATE -> { loss_min = abs(value) * -1 } + ConfigIndex.LOSS_MAX_MONEY -> { loss_money = abs(value) } + ConfigIndex.STOP_LOSS -> { stop_Loss = value > 0.1 } ConfigIndex.TAKE_PROFIT -> { take_profit = value > 0.1 } - ConfigIndex.MAX_HOLDING_COUNT -> { max_holding_count = value } - + ConfigIndex.MAX_HOLDING_COUNT -> { max_holding_count = value } } - if (firstSet.contains(index)) { + val newValue = getValues(index) + if (oldValue != newValue) { DatabaseFactory.saveConfig(KisSession.config) TradingLogStore.addSettingLog( index.label, oldValue.toString(), - value.toString(), - "πŸ’Ύ μ €μž₯됨: ${index.label} = ${getValues(index)}" + newValue.toString(), + "πŸ’Ύ μ €μž₯됨: ${index.label} = $newValue" ) TradingReportManager.recordConfigChange() - } else { - firstSet.add(index) } } fun getValues(index :ConfigIndex) : Double { @@ -215,9 +212,9 @@ data class AppConfig( ConfigIndex.GRADE_3_ALLOCATIONRATE -> {GRADE_3_ALLOCATIONRATE} ConfigIndex.GRADE_2_ALLOCATIONRATE -> {GRADE_2_ALLOCATIONRATE} ConfigIndex.GRADE_1_ALLOCATIONRATE -> {GRADE_1_ALLOCATIONRATE} - ConfigIndex.LOSS_MAXRATE -> { abs(loss_max) * -1} - ConfigIndex.LOSS_MINRATE -> { abs(loss_min) * -1} - ConfigIndex.LOSS_MAX_MONEY -> { abs(loss_money) * -1} + ConfigIndex.LOSS_MAXRATE -> { abs(loss_max) * -1 } + ConfigIndex.LOSS_MINRATE -> { abs(loss_min) * -1 } + ConfigIndex.LOSS_MAX_MONEY -> { abs(loss_money) } ConfigIndex.STOP_LOSS -> {if(!stop_Loss) 0.0 else 1.0} ConfigIndex.TAKE_PROFIT -> {if(!take_profit) 0.0 else 1.0} ConfigIndex.MAX_COUNT_INDEX -> {MAX_COUNT.toDouble()} diff --git a/src/main/kotlin/service/AutoTradingManager.kt b/src/main/kotlin/service/AutoTradingManager.kt index c7ca823..8879af6 100644 --- a/src/main/kotlin/service/AutoTradingManager.kt +++ b/src/main/kotlin/service/AutoTradingManager.kt @@ -305,13 +305,13 @@ object AutoTradingManager { var stockName = decision.stockName val maxStocks = KisSession.config.getValues(ConfigIndex.MAX_HOLDING_COUNT).toInt() - if (!canAddNewPosition(maxStocks)) { - TradingLogStore.addNotice("SYSTEM", "LIMIT", "μ΅œλŒ€ 보유 μ’…λͺ© λ„λ‹¬λ‘œ μ‹ κ·œ 맀수 μΌμ‹œ 쀑단") + if (!hasCode && !canAddNewPosition(maxStocks)) { + TradingLogStore.addNotice("SYSTEM", "LIMIT", "μ΅œλŒ€ 보유 μ’…λͺ© 수($maxStocks) λ„λ‹¬λ‘œ μ‹ κ·œ 맀수 μΌμ‹œ 쀑단") addToReanalysis(RankingStock(mksc_shrn_iscd = stockCode, hts_kor_isnm = stockName)) TradingLogStore.addWatchLog( decision, "WATCH", - "맀수 μ‹€νŒ¨ : μ΅œλŒ€ 보유 μ’…λͺ© λ„λ‹¬λ‘œ μ‹ κ·œ 맀수 μΌμ‹œ 쀑단 => μž¬λΆ„μ„ λŒ€κΈ°μ—΄μ— μΆ”κ°€" + "맀수 μ‹€νŒ¨ : μ΅œλŒ€ 보유 μ’…λͺ© 수($maxStocks) λ„λ‹¬λ‘œ μ‹ κ·œ 맀수 μΌμ‹œ 쀑단 => μž¬λΆ„μ„ λŒ€κΈ°μ—΄μ— μΆ”κ°€" ) } else if (KisSession.isAvailBuyTime(LocalTime.now()) || hasCode) { @@ -680,9 +680,9 @@ object AutoTradingManager { && holding.profitRate.toDouble() >= KisSession.config.getValues( ConfigIndex.LOSS_MAXRATE ) - && holding.valuationProfitAmount.toDouble() >= KisSession.config.getValues( + && holding.valuationProfitAmount.toDouble() >= (-abs(KisSession.config.getValues( ConfigIndex.LOSS_MAX_MONEY - ) + ))) ) { println( "${holding.name} ${holding.profitRate.toDouble()} ${holding.valuationProfitAmount.toDouble()} ${ @@ -897,9 +897,9 @@ object AutoTradingManager { && holding.profitRate.toDouble() >= KisSession.config.getValues( ConfigIndex.LOSS_MAXRATE ) - && holding.valuationProfitAmount.toDouble() >= KisSession.config.getValues( + && holding.valuationProfitAmount.toDouble() >= (-abs(KisSession.config.getValues( ConfigIndex.LOSS_MAX_MONEY - ) + ))) ) { println( "${holding.name} ${holding.profitRate.toDouble()} ${holding.valuationProfitAmount.toDouble()} ${ @@ -1018,13 +1018,12 @@ object AutoTradingManager { private var lastRetryTime = 0L val binPath = getLlamaBinPath() - fun canAddNewPosition( // λŒ€ν‘œλ‹˜μ˜ μ‹œμŠ€ν…œμ— λ§žλŠ” 미체결 μ£Όλ¬Έ 객체 리슀트 + fun canAddNewPosition( maxAllowedStocks: Int ): Boolean { - - - // ν˜„μž¬ λ…ΈμΆœ μˆ˜κ°€ μ΅œλŒ€ ν—ˆμš©μΉ˜λ³΄λ‹€ μž‘μ„ λ•Œλ§Œ true(맀수 κ°€λŠ₯) λ°˜ν™˜ - return true //(currentBalance?.getHoldings()?.count { it.availOrderCount.toInt() > 0 } ?: 0) > maxAllowedStocks + // ν˜„μž¬ μž”κ³ μ˜ 보유 μ’…λͺ© 수(λ³΄μœ μˆ˜λŸ‰ > 0)κ°€ μ΅œλŒ€ ν—ˆμš©μΉ˜ 미만일 λ•Œλ§Œ μ‹ κ·œ 맀수 κ°€λŠ₯ + val currentHoldingsCount = currentBalance?.getHoldings()?.count { it.quantity.toInt() > 0 } ?: 0 + return currentHoldingsCount < maxAllowedStocks } suspend fun tryRefreshToken() { diff --git a/src/main/kotlin/ui/panel/TradeConfigPanel.kt b/src/main/kotlin/ui/panel/TradeConfigPanel.kt index 5df1019..8118894 100644 --- a/src/main/kotlin/ui/panel/TradeConfigPanel.kt +++ b/src/main/kotlin/ui/panel/TradeConfigPanel.kt @@ -274,7 +274,7 @@ private fun BasicRiskTabContent(tradeConfig: TradeConfig) { label = "μ΅œλŒ€ ν—ˆμš© 손싀 κΈˆμ•‘ (원)", initialValue = KisSession.config.getValues(ConfigIndex.LOSS_MAX_MONEY).toLong().toString(), helperText = "1μ’…λͺ©λ‹Ή μ΅œλŒ€ 손싀 κΈˆμ•‘", - onSave = { KisSession.config.setValues(ConfigIndex.LOSS_MAX_MONEY, it.toDoubleOrNull() ?: -10000.0) } + onSave = { KisSession.config.setValues(ConfigIndex.LOSS_MAX_MONEY, it.toDoubleOrNull() ?: 10000.0) } ) } }