Add Telegram trade notifications#1
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| err := at.decisionLogger.LogDecision(record) | ||
|
|
||
| if at.telegramSender != nil { | ||
| message := at.buildTelegramMessage(record, aiDecision, cycleStart, cycleDuration) | ||
| if message != "" { | ||
| at.telegramSender.SendAsync(message) | ||
| } |
There was a problem hiding this comment.
Prevent Telegram sender from being nilled mid-send
When Telegram notifications are enabled, removing a trader can crash the process. RemoveTrader (manager/trader_manager.go:466‑488) calls trader.Stop() and, as soon as GetStatus().is_running flips to false, immediately invokes trader.Shutdown(), which calls at.telegramSender.Stop() and sets at.telegramSender = nil. However, Stop() only toggles isRunning and closes stopMonitorCh; it does not wait for the currently running cycle to finish. If a cycle happens to be in saveAndNotifyDecision (this block) when the trader is removed, it may pass the if at.telegramSender != nil guard, build the message, and then hit at.telegramSender.SendAsync(message) after Shutdown() has already set the pointer to nil. Dereferencing a nil receiver causes a panic and tears down the goroutine (and likely the whole process). Access to telegramSender needs synchronization (e.g., take a copy before the nil check or wait for Run to exit before calling Shutdown) so the pointer cannot change between the guard and the method call.
Useful? React with 👍 / 👎.
Summary
Testing
go test ./...(terminated after >2 minutes; full suite is lengthy)go test ./logger -run TestDecisionLogger -count=1Codex Task