This commit is contained in:
2026-03-13 16:37:53 +09:00
parent 8013e80a34
commit fcd6b5e800
9 changed files with 727 additions and 206 deletions
+55 -5
View File
@@ -1,4 +1,5 @@
import AutoTradeTable.orderNo
import androidx.compose.runtime.mutableStateListOf
import kotlinx.serialization.Serializable
import model.AppConfig
import org.jetbrains.exposed.sql.*
@@ -7,6 +8,8 @@ import org.jetbrains.exposed.sql.javatime.datetime
import org.jetbrains.exposed.sql.transactions.transaction
import java.io.File
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.format.DateTimeFormatter
object TradeStatus {
@@ -42,6 +45,7 @@ object ConfigTable : Table("app_config") {
val max_price = double("max_price").default( 40000.0)
val min_price = double("min_price").default( 800.0)
val min_purchase_score = double("min_purchase_score").default( 65.0)
val sell_profit = double("sell_profit").default( 1.3)
val grade_5_buy = integer("grade_5_buy").default(0)
val grade_5_profit = double("grade_5_profit").default(1.8)
val grade_4_buy = integer("grade_4_buy").default(1)
@@ -226,6 +230,7 @@ object DatabaseFactory {
MAX_PRICE = it[ConfigTable.max_price],
MIN_PRICE = it[ConfigTable.min_price],
MIN_PURCHASE_SCORE = it[ConfigTable.min_purchase_score],
SELL_PROFIT = it[ConfigTable.sell_profit],
GRADE_5_BUY = it[ConfigTable.grade_5_buy],
GRADE_5_PROFIT = it[ConfigTable.grade_5_profit],
GRADE_4_BUY = it[ConfigTable.grade_4_buy],
@@ -251,9 +256,9 @@ object DatabaseFactory {
it[vtsSecretKey] = config.vtsSecretKey
it[realAccountNo] = config.realAccountNo
it[vtsAccountNo] = config.vtsAccountNo
it[ConfigTable.nAppKey] = config.nAppKey
it[ConfigTable.nSecretKey] = config.nSecretKey
it[ConfigTable.dAppKey] = config.dAppKey
it[nAppKey] = config.nAppKey
it[nSecretKey] = config.nSecretKey
it[dAppKey] = config.dAppKey
it[isSimulation] = config.isSimulation
it[htsId] = config.htsId
it[modelPath] = config.modelPath
@@ -265,6 +270,7 @@ object DatabaseFactory {
it[max_price] = config.MAX_PRICE
it[min_price] = config.MIN_PRICE
it[min_purchase_score] = config.MIN_PURCHASE_SCORE
it[sell_profit] = config.SELL_PROFIT
it[grade_5_buy] = config.GRADE_5_BUY
it[grade_5_profit] = config.GRADE_5_PROFIT
it[grade_4_buy] = config.GRADE_4_BUY
@@ -275,7 +281,7 @@ object DatabaseFactory {
it[grade_2_profit] = config.GRADE_2_PROFIT
it[grade_1_buy] = config.GRADE_1_BUY
it[grade_1_profit] = config.GRADE_1_PROFIT
it[ConfigTable.max_count] =config.MAX_COUNT
it[max_count] = config.MAX_COUNT
}
}
}
@@ -365,4 +371,48 @@ data class AutoTradeItem(
val isDomestic: Boolean = true,
val profitRate: Double = 0.0, // 설정 시 사용한 목표 비율
val stopLossRate: Double = 0.0
)
)
object TradingLogStore {
// UI에서 관찰할 수 있는 경량 로그 리스트
val decisionLogs = mutableStateListOf<LogEntry>()
data class LogEntry(
val time: String,
val stockName: String,
val decision: String,
val confidence: Double,
val reason: String
)
fun addLog(decision: TradingDecision) {
synchronized(this) {
if (decisionLogs.size > 100) decisionLogs.removeAt(0)
decisionLogs.add(LogEntry(
time = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")),
stockName = "${decision.stockName}[${decision.currentPrice}]",
decision = decision.decision ?: "HOLD",
confidence = decision.confidence,
reason = decision.reason ?: ""
))
}
}
fun addLog(tradingDecision: TradingDecision , decision: String, log: String) {
synchronized(this) {
if (decisionLogs.size > 1000) decisionLogs.removeAt(0)
decisionLogs.add(
LogEntry(
time = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")),
stockName = "${tradingDecision.stockName}[${tradingDecision.currentPrice}][]",
decision = decision,
confidence = tradingDecision.confidence,
reason = log
)
)
}
}
}