This commit is contained in:
lunaticbum 2026-06-04 10:42:54 +09:00
parent d57f1698af
commit aa4f8daadf
2 changed files with 12 additions and 8 deletions

View File

@ -238,13 +238,16 @@ object AutoTradingManager {
var tax = KisSession.config.getValues(ConfigIndex.TAX_INDEX)
val effectiveProfitRate =
(profitRate1 ?: KisSession.config.getValues(ConfigIndex.PROFIT_INDEX)) + tax
var oldTarget = currentBalance?.getHoldings()?.filter { it.code.equals(decision.stockCode) }?.first()
if (hasCode && oldTarget != null) {
var avgPrive = oldTarget.avgPrice.toDouble()
var qty = oldTarget.quantity.toDouble()
basePrice = ((avgPrive * qty) + (decision.currentPrice * orderQty.toInt())).div(qty!!.toInt() + (orderQty.toInt()))
println("물타기 ${avgPrive}, ${qty} ${basePrice}")
}
try {
var oldTarget = currentBalance?.getHoldings()?.first { it.availOrderCount.toInt() > 0 && it.code.equals(decision.stockCode) }
if (hasCode && oldTarget != null) {
var avgPrive = oldTarget.avgPrice.toDouble()
var qty = oldTarget.quantity.toDouble()
basePrice = ((avgPrive * qty) + (decision.currentPrice * orderQty.toInt())).div(qty!!.toInt() + (orderQty.toInt()))
println("물타기 ${avgPrive}, ${qty} ${basePrice}")
}
} catch (e:Exception) {e.printStackTrace()}
val calculatedTarget =
MarketUtil.roundToTickSize(basePrice * (1 + effectiveProfitRate / 100.0))
@ -326,6 +329,7 @@ object AutoTradingManager {
var onExecutionReceived : ((String, String, String, String, Boolean) -> Unit)? = {code, qty, price,orderNo, isBuy ->
scope.launch {
val exec = ExecutionData(orderNo, code, price, qty, isBuy)
println("exec >> ${exec}")
executionCache[orderNo] = exec
syncAndExecute(orderNo)
}

View File

@ -33,7 +33,7 @@ object MarketUtil {
holiDays.put(todayStr, isHoliday)
println("🌐 [API Call] 오늘($todayStr)의 휴장 여부를 새로 조회하여 DB에 저장했습니다.")
!isHoliday
isHoliday
} catch (e: Exception) {
e.printStackTrace()
false