atrade/src/main/kotlin/model/AppConfig.kt

59 lines
1.7 KiB
Kotlin
Raw Normal View History

2026-01-10 18:16:50 +09:00
package model
2026-01-13 16:04:25 +09:00
import java.time.LocalDateTime
2026-01-10 18:16:50 +09:00
2026-02-04 15:32:05 +09:00
const val feesAndTaxRate = 0.33
const val minimumNetProfit = 0.4
const val buyWeight = 2.0
2026-02-04 14:52:09 +09:00
2026-01-10 18:16:50 +09:00
data class AppConfig(
2026-01-13 16:04:25 +09:00
// [DB 저장 데이터]
// 실전 3종
val realAppKey: String = "",
val realSecretKey: String = "",
val realAccountNo: String = "",
// 모의 3종
val vtsAppKey: String = "",
val vtsSecretKey: String = "",
val vtsAccountNo: String = "",
// [세션 데이터 - 메모리에서만 관리]
var marketToken: String = "",
var marketTokenExpiredAt: LocalDateTime? = null, // 만료 시간 추가
var tradeToken: String = "",
var tradeTokenExpiredAt: LocalDateTime? = null,
2026-01-14 15:42:26 +09:00
val htsId: String = "",
2026-01-13 16:04:25 +09:00
var websocketToken: String = "",
2026-01-10 18:16:50 +09:00
val isSimulation: Boolean = true,
2026-01-21 18:30:03 +09:00
val modelPath: String = "",
val embedModelPath: String = "") {
2026-01-13 16:04:25 +09:00
val accountNo : String
get() {
return if (isSimulation) vtsAccountNo else realAccountNo
}
}
// [신규] 전역에서 참조할 단일 세션 객체
object KisSession {
var config: AppConfig = AppConfig()
2026-01-19 17:09:37 +09:00
fun getWebSocketKey() = config.websocketToken
2026-01-13 16:04:25 +09:00
// 시장 데이터 토큰 유효성 검사 (만료 5분 전부터는 유효하지 않은 것으로 간주)
fun isMarketTokenValid(): Boolean {
return config.marketToken.isNotEmpty() &&
config.marketTokenExpiredAt?.isAfter(LocalDateTime.now().plusMinutes(5)) ?: false
}
// 매매용 토큰 유효성 검사
fun isTradeTokenValid(): Boolean {
return config.tradeToken.isNotEmpty() &&
config.tradeTokenExpiredAt?.isAfter(LocalDateTime.now().plusMinutes(5)) ?: false
}
}