misc: binance momentum, telegram, frontend updates
This commit is contained in:
@@ -33,6 +33,14 @@ func main() {
|
||||
loadDotEnv()
|
||||
cfg := LoadConfig()
|
||||
|
||||
// Initialize Telegram sender
|
||||
telegramSender := NewTelegramSender(cfg.TelegramBotToken, cfg.TelegramChatID)
|
||||
if telegramSender.IsEnabled() {
|
||||
log.Printf("[Telegram] Alerts enabled -> chat %s", cfg.TelegramChatID)
|
||||
} else {
|
||||
log.Println("[Telegram] Alerts disabled (missing token or chat ID)")
|
||||
}
|
||||
|
||||
store := NewPriceStore()
|
||||
|
||||
// Initialize momentum tracker (for momentum scanning mode)
|
||||
@@ -79,8 +87,18 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize Binance momentum detector (1-minute Binance price change)
|
||||
binanceMomentumDetector := NewBinanceMomentumDetector(
|
||||
cfg.BinanceMomentumWindowSec, 50, // actual loop tick is fixed 50ms
|
||||
cfg.BinanceMomentumThresholdPct, cfg.BinanceMomentumCooldownSec,
|
||||
)
|
||||
if cfg.BinanceMomentumEnabled {
|
||||
log.Printf("[BinanceMomentum] Detection enabled (window=%ds, threshold=%.1f%%, cooldown=%ds)",
|
||||
cfg.BinanceMomentumWindowSec, cfg.BinanceMomentumThresholdPct, cfg.BinanceMomentumCooldownSec)
|
||||
}
|
||||
|
||||
// Initialize dashboard (web server + SSE)
|
||||
dashboard := NewDashboard(store, database, ":8888", cfg, momentumTracker, trendDetector, cumulativeTracker, trendFilter, surgeDetector)
|
||||
dashboard := NewDashboard(store, database, ":8888", cfg, momentumTracker, trendDetector, cumulativeTracker, trendFilter, surgeDetector, binanceMomentumDetector)
|
||||
go dashboard.Run()
|
||||
|
||||
// Context for graceful shutdown
|
||||
@@ -172,6 +190,30 @@ func main() {
|
||||
now := time.Now()
|
||||
snap := store.GetAll()
|
||||
|
||||
// Feed Binance prices to momentum detector
|
||||
if cfg.BinanceMomentumEnabled {
|
||||
for _, tc := range TrackedCoins {
|
||||
if exMap := snap[tc.Name]; exMap != nil {
|
||||
if bnPrice, ok := exMap[ExBinance]; ok && bnPrice > 0 {
|
||||
binanceMomentumDetector.Record(tc.Name, bnPrice)
|
||||
}
|
||||
}
|
||||
}
|
||||
alerts := binanceMomentumDetector.Detect()
|
||||
for _, alert := range alerts {
|
||||
log.Printf("[BinanceMomentum] %s %s %.2f%% ($%.4f)",
|
||||
alert.Coin, alert.Direction, alert.ChangePct, alert.Price)
|
||||
dashboard.BroadcastEvent("binance_alert", alert)
|
||||
if telegramSender.IsEnabled() {
|
||||
go func(a BinanceAlert) {
|
||||
if err := telegramSender.SendAlert(a); err != nil {
|
||||
log.Printf("[Telegram] Failed to send alert for %s: %v", a.Coin, err)
|
||||
}
|
||||
}(alert)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Feed prices to momentum tracker (for momentum scanning or trend detection)
|
||||
if cfg.MomentumEnabled || cfg.TrendEnabled {
|
||||
for coin, exMap := range snap {
|
||||
|
||||
Reference in New Issue
Block a user