...
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import model.AppConfig
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.javatime.datetime
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
@@ -7,13 +8,17 @@ import java.time.LocalDateTime
|
||||
// 1. 앱 설정 테이블
|
||||
object ConfigTable : Table("app_config") {
|
||||
val id = integer("id").autoIncrement()
|
||||
val appKey = varchar("app_key", 255)
|
||||
val secretKey = varchar("secret_key", 255)
|
||||
val accountNo = varchar("account_no", 20)
|
||||
val isSimulation = bool("is_simulation")
|
||||
val modelPath = varchar("model_path", 512).default("") // 이 라인이 있어야 합니다.
|
||||
val realAppKey = varchar("real_app_key", 255).default("")
|
||||
val realSecretKey = varchar("real_secret_key", 255).default("")
|
||||
val realAccountNo = varchar("real_account_no", 20).default("")
|
||||
val vtsAppKey = varchar("vts_app_key", 255).default("")
|
||||
val vtsSecretKey = varchar("vts_secret_key", 255).default("")
|
||||
val vtsAccountNo = varchar("vts_account_no", 20).default("")
|
||||
val isSimulation = bool("is_simulation").default(true)
|
||||
val modelPath = varchar("model_path", 512).default("")
|
||||
override val primaryKey = PrimaryKey(id)
|
||||
}
|
||||
|
||||
// 2. 거래 내역 테이블 (대량 데이터용)
|
||||
object TradeLogTable : Table("trade_logs") {
|
||||
val id = long("id").autoIncrement()
|
||||
@@ -56,14 +61,40 @@ object DatabaseFactory {
|
||||
}
|
||||
}
|
||||
|
||||
// fun fetchRecentLogs(limit: Int = 50): List<TradeLog> {
|
||||
// return transaction {
|
||||
// TradeLogTable.selectAll()
|
||||
// .orderBy(TradeLogTable.timestamp to SortOrder.DESC)
|
||||
// .limit(limit)
|
||||
// .map {
|
||||
// // ResultRow를 객체로 변환
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
fun findConfigByAccount(accountNo: String): AppConfig? {
|
||||
return transaction {
|
||||
ConfigTable.select {
|
||||
(ConfigTable.realAccountNo eq accountNo) or (ConfigTable.vtsAccountNo eq accountNo)
|
||||
}.lastOrNull()?.let {
|
||||
AppConfig(
|
||||
realAppKey = it[ConfigTable.realAppKey],
|
||||
realSecretKey = it[ConfigTable.realSecretKey],
|
||||
realAccountNo = it[ConfigTable.realAccountNo],
|
||||
vtsAppKey = it[ConfigTable.vtsAppKey],
|
||||
vtsSecretKey = it[ConfigTable.vtsSecretKey],
|
||||
vtsAccountNo = it[ConfigTable.vtsAccountNo],
|
||||
isSimulation = it[ConfigTable.isSimulation],
|
||||
modelPath = it[ConfigTable.modelPath]
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun saveConfig(config: AppConfig) {
|
||||
transaction {
|
||||
// 기존 설정을 모두 지우고 최신 설정 하나만 유지
|
||||
ConfigTable.deleteAll()
|
||||
ConfigTable.insert {
|
||||
it[realAppKey] = config.realAppKey
|
||||
it[realSecretKey] = config.realSecretKey
|
||||
it[vtsAppKey] = config.vtsAppKey
|
||||
it[vtsSecretKey] = config.vtsSecretKey
|
||||
it[realAccountNo] = config.realAccountNo
|
||||
it[vtsAccountNo] = config.vtsAccountNo
|
||||
it[isSimulation] = config.isSimulation
|
||||
it[modelPath] = config.modelPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user