fix: 애프터마켓 거래종료 19:30 고정 및 19:30 이후 야간 예약매도/최종결산 스케줄 정렬
This commit is contained in:
@@ -115,13 +115,13 @@ object TradingReportManager : TradingReportService {
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 애프터 마켓(시간외) 마감 결산 (18:00 ~ 18:10)
|
||||
// 3. 애프터 마켓(시간외) 거래 종료 마감 결산 (19:30 ~ 19:45)
|
||||
val afterKey = "${today}_AFTER_CLOSE"
|
||||
if (now.isAfter(LocalTime.of(17, 59)) && now.isBefore(LocalTime.of(18, 10))) {
|
||||
if (now.isAfter(LocalTime.of(19, 29)) && now.isBefore(LocalTime.of(19, 45))) {
|
||||
if (!reportedSnapshotMap.containsKey(afterKey)) {
|
||||
reportedSnapshotMap[afterKey] = true
|
||||
println("🌙 [Report] 18:00 애프터마켓(시간외) 마감 스냅샷 및 텔레그램 리포트 자동 실행")
|
||||
recordAssetSnapshot(SnapshotType.AFTER_CLOSE, balance, "시간외 단일가 마감 최종 스냅샷")
|
||||
println("🌙 [Report] 19:30 애프터마켓(시간외) 거래 종료 최종 스냅샷 및 텔레그램 리포트 자동 실행")
|
||||
recordAssetSnapshot(SnapshotType.AFTER_CLOSE, balance, "애프터마켓 19:30 마감 최종 결산 스냅샷")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1614,10 +1614,11 @@ object AutoTradingManager {
|
||||
|
||||
// private var lastForceCheckMinute = -1 // 마지막으로 강제 체크를 수행한 '분'을 저장
|
||||
private val executionCountMap = ConcurrentHashMap<String, Int>()
|
||||
private var lastReservationExecutedDate: String = ""
|
||||
suspend fun sellSchedule() {
|
||||
val now = MarketScheduleManager.now()
|
||||
|
||||
// 📊 [3단계 스케줄 리포팅] 장 시작 전(08:50), 정규장 마감(15:35), 애프터마켓 마감(18:00) 자산 스냅샷 & 텔레그램 리포트 자동 트리거
|
||||
// 📊 [3단계 스케줄 리포팅] 장 시작 전(08:50), 정규장 마감(15:35), 애프터마켓 마감(19:30) 자산 스냅샷 & 텔레그램 리포트 자동 트리거
|
||||
val balanceForReport = currentBalance ?: KisTradeService.fetchIntegratedBalance().getOrNull()
|
||||
balanceForReport?.let { TradingReportManager.checkAndTriggerScheduledReport(it) }
|
||||
|
||||
@@ -1680,17 +1681,21 @@ object AutoTradingManager {
|
||||
}
|
||||
isExecuted = true
|
||||
} else if (MarketScheduleManager.isOvernightReservationTime(now)) {
|
||||
val todayStr = LocalDate.now(MarketScheduleManager.seoulZone).toString()
|
||||
if (lastReservationExecutedDate != todayStr) {
|
||||
lastReservationExecutedDate = todayStr
|
||||
TradingLogStore.addAnalyzer(
|
||||
" - ",
|
||||
" - ",
|
||||
"🌙 [강제 스케줄 실행] 오후 ${now.hour}시 ${currentMinute}분 - 야간 보유주식 자동 예약 매도 주문을 시작합니다.",
|
||||
"🌙 [야간 스케줄 실행] 오후 ${now.hour}시 ${currentMinute}분 - 야간 보유주식 자동 예약 매도 주문을 시작합니다 (19:30 이후 당일 1회 실행).",
|
||||
true
|
||||
)
|
||||
println("🌙 [강제 스케줄 실행] 오후 ${now.hour}시 ${currentMinute}분 - 야간 보유주식 자동 예약 매도 주문을 시작합니다.")
|
||||
println("🌙 [야간 스케줄 실행] 오후 ${now.hour}시 ${currentMinute}분 - 야간 보유주식 자동 예약 매도 주문을 시작합니다.")
|
||||
val balance = currentBalance ?: KisTradeService.fetchIntegratedBalance().getOrNull()
|
||||
balance?.let { orderReservationSell(KisTradeService, it) }
|
||||
isExecuted = true
|
||||
}
|
||||
}
|
||||
if (isExecuted) {
|
||||
executionCountMap[timeKey] = currentCount + 1
|
||||
}
|
||||
|
||||
@@ -82,8 +82,7 @@ object MarketScheduleManager {
|
||||
currentTime.isBefore(LocalTime.of(15, 30)) -> MarketPhase.REGULAR_CLOSING
|
||||
currentTime.isBefore(LocalTime.of(15, 40)) -> MarketPhase.REGULAR_CLOSING
|
||||
currentTime.isBefore(LocalTime.of(16, 0)) -> MarketPhase.AFTER_HOURS
|
||||
currentTime.isBefore(LocalTime.of(18, 0)) -> MarketPhase.AFTER_SINGLE
|
||||
currentTime.isBefore(userReservationTime) -> MarketPhase.AFTER_EXTENDED
|
||||
currentTime.isBefore(LocalTime.of(19, 30)) -> MarketPhase.AFTER_SINGLE
|
||||
currentTime.isBefore(userEndTime) -> MarketPhase.OVERNIGHT_RESERVATION
|
||||
else -> MarketPhase.CLOSED
|
||||
}
|
||||
@@ -141,20 +140,28 @@ object MarketScheduleManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* 장후 대체/시간외 단일가 가동 구간 (15:40 ~ 20:00)
|
||||
* 장후 대체/시간외 단일가 가동 구간 (15:40 ~ 19:30 고정)
|
||||
* 오후 7시 30분에 애프터마켓 거래가 공식 종료됩니다.
|
||||
*/
|
||||
fun isAfterMarketTime(currentTime: LocalTime = now()): Boolean {
|
||||
return currentTime.isAfter(LocalTime.of(15, 40)) && currentTime.isBefore(userEndTime)
|
||||
return currentTime.isAfter(LocalTime.of(15, 40)) && currentTime.isBefore(LocalTime.of(19, 30))
|
||||
}
|
||||
|
||||
/**
|
||||
* 야간 보유주식 자동 예약 매도 구간 (reservationSellHour:Minute ~ userEndTime)
|
||||
* 야간 보유주식 자동 예약 매도 구간 (19:30 이후 ~ userEndTime)
|
||||
* 애프터마켓이 19:30에 마감된 후 안전하게 야간 예약 매도를 실행합니다.
|
||||
*/
|
||||
fun isOvernightReservationTime(currentTime: LocalTime = now()): Boolean {
|
||||
val reservationStart = LocalTime.of(
|
||||
KisSession.tradeConfig.reservationSellHour.coerceIn(0, 23),
|
||||
KisSession.tradeConfig.reservationSellMinute.coerceIn(0, 59)
|
||||
)
|
||||
// 19:30 이전 설정 방지: 최소 19:30 이후부터 실행 보장
|
||||
val effectiveStart = if (reservationStart.isBefore(LocalTime.of(19, 30))) LocalTime.of(19, 30) else reservationStart
|
||||
|
||||
return KisSession.tradeConfig.useReservationSell &&
|
||||
(currentTime.hour == KisSession.tradeConfig.reservationSellHour &&
|
||||
currentTime.minute >= KisSession.tradeConfig.reservationSellMinute &&
|
||||
currentTime.isBefore(userEndTime))
|
||||
(currentTime.isAfter(effectiveStart) || currentTime == effectiveStart) &&
|
||||
currentTime.isBefore(userEndTime)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user