...
This commit is contained in:
@@ -614,6 +614,22 @@ object TradingLogStore {
|
||||
}
|
||||
|
||||
fun addNotice(name : String, code : String, log: String) {
|
||||
var isSendable = false
|
||||
val current = System.currentTimeMillis()
|
||||
|
||||
if (KisSession.tradeConfig.useTagsShare.contains("NOTICE") &&
|
||||
KisSession.tradeConfig.useLogKeywordsShare.any { log.contains(it) }) {
|
||||
|
||||
// 대소문자 구분 없이 key를 찾기 위해 원본 code를 가공하거나 그대로 사용
|
||||
val lastSentTime = noticeFilter[code.uppercase()]
|
||||
|
||||
// 기록이 없거나(처음 보냄), 마지막 발송 기준 30분이 지났다면
|
||||
if (lastSentTime == null || (current - lastSentTime > 1000 * 60 * 30L)) {
|
||||
isSendable = true
|
||||
noticeFilter[code.uppercase()] = current // 즉시 발송 시간 갱신하여 중복 방지
|
||||
}
|
||||
}
|
||||
|
||||
synchronized(this) {
|
||||
if (decisionLogs.size > 1000) decisionLogs.removeAt(0)
|
||||
decisionLogs.add(
|
||||
@@ -623,28 +639,24 @@ object TradingLogStore {
|
||||
decision = "NOTICE",
|
||||
confidence = 100.0,
|
||||
reason = log
|
||||
).apply {
|
||||
if (KisSession.tradeConfig.useTagsShare.contains(decision) && KisSession.tradeConfig.useLogKeywordsShare.any {
|
||||
log.contains(
|
||||
it
|
||||
)
|
||||
}) {
|
||||
var current = System.currentTimeMillis()
|
||||
var sendable = noticeFilter.filter { it.key.equals(code, true) && ((current - it.value) > 1000 * 60 * 30L)}.isNotEmpty()
|
||||
if (sendable) {
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
NewsService.sendTelegramMessage("${this@apply.decision}$name[$code] ${log}")
|
||||
|
||||
}}
|
||||
noticeFilter[code] = current
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
if (isSendable) {
|
||||
applicationScope.launch {
|
||||
try {
|
||||
NewsService.sendTelegramMessage("NOTICE $name[$code] $log")
|
||||
} catch (e: Exception) {
|
||||
// 발송 실패 시 원상복구를 원한다면 주석 해제 (단, 일시적 네트웍 장애 시 도배 위험 있음)
|
||||
// noticeFilter.remove(code.uppercase())
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private val applicationScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
var noticeFilter = hashMapOf<String, Long>()
|
||||
fun addNotice(name : String, code : String, log: String, qty: Int? = null) {
|
||||
synchronized(this) {
|
||||
|
||||
Reference in New Issue
Block a user