feat: Add Telegram news integration for market sentiment analysis (PR #277)

- Add Telegram channel monitoring for market news
- Integrate news sentiment into AI decision making
- Improve context awareness for trading decisions
- Fix missing InsideCoins field in ConfigFile structure
- Merge with existing partial_close and position tracking features
This commit is contained in:
ZhouYongyou
2025-11-03 22:19:38 +08:00
11 changed files with 799 additions and 74 deletions

View File

@@ -6,9 +6,12 @@ import (
"log"
"nofx/market"
"nofx/mcp"
"nofx/news"
"nofx/pool"
"strings"
"time"
"github.com/samber/lo"
)
// PositionInfo 持仓信息
@@ -55,17 +58,18 @@ type OITopData struct {
// Context 交易上下文传递给AI的完整信息
type Context struct {
CurrentTime string `json:"current_time"`
RuntimeMinutes int `json:"runtime_minutes"`
CallCount int `json:"call_count"`
Account AccountInfo `json:"account"`
Positions []PositionInfo `json:"positions"`
CandidateCoins []CandidateCoin `json:"candidate_coins"`
MarketDataMap map[string]*market.Data `json:"-"` // 不序列化,但内部使用
OITopDataMap map[string]*OITopData `json:"-"` // OI Top数据映射
Performance interface{} `json:"-"` // 历史表现分析logger.PerformanceAnalysis
BTCETHLeverage int `json:"-"` // BTC/ETH杠杆倍数从配置读取
AltcoinLeverage int `json:"-"` // 山寨币杠杆倍数(从配置读取)
CurrentTime string `json:"current_time"`
RuntimeMinutes int `json:"runtime_minutes"`
CallCount int `json:"call_count"`
Account AccountInfo `json:"account"`
Positions []PositionInfo `json:"positions"`
CandidateCoins []CandidateCoin `json:"candidate_coins"`
MarketDataMap map[string]*market.Data `json:"-"` // 不序列化,但内部使用
OITopDataMap map[string]*OITopData `json:"-"` // OI Top数据映射
Performance interface{} `json:"-"` // 历史表现分析logger.PerformanceAnalysis
BTCETHLeverage int `json:"-"` // BTC/ETH杠杆倍数从配置读取
AltcoinLeverage int `json:"-"` // 山寨币杠杆倍数(从配置读取)
News map[string][]news.NewsItem `json:"news,omitempty"` // 新闻数据可选按symbol分组传给AI
}
// Decision AI的交易决策
@@ -398,6 +402,18 @@ func buildUserPrompt(ctx *Context) string {
}
}
// 新闻内容
newsItem := make([]news.NewsItem, 0, 100)
for _, symbol := range lo.Keys(ctx.News) {
newsItem = append(newsItem, ctx.News[symbol]...)
}
if len(newsItem) > 0 {
sb.WriteString("\n## 相关新闻\n")
for _, item := range newsItem {
sb.WriteString(item.String())
}
}
sb.WriteString("---\n\n")
sb.WriteString("现在请分析并输出决策(思维链 + JSON\n")