Files
nofx/news/news.go
wwg d2af549bac feat(config): 增加新闻源配置与数据库迁移支持
- 在config.json.example中添加新闻源相关配置示例,支持telegram频道订阅
- 扩展数据库表结构,新增traders表多字段支持信号源和杠杆参数
- 新增NewsConfig结构体及相关telegram新闻配置数据模型
- 在交易决策上下文结构Context中添加新闻数据news字段支持传递新闻
- 在交易决策构建用户提示信息时加入相关新闻内容
- 优化数据库操作代码,支持交易所和交易员配置的完整字段读取与更新
- 添加数据库exchanges表迁移逻辑,重建表结构和触发器以支持新字段
- 引入第三方库github.com/samber/lo用于集合操作
- 在go.mod添加新的依赖模块,并更新相关依赖版本
2025-11-01 23:10:02 +08:00

74 lines
2.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package news
import (
"fmt"
"time"
)
const (
// ProviderTelegrame 电报
ProviderTelegram = "telegram"
)
// NewsItem 表示一条新闻条目的核心数据结构。
// 该结构体通常用于金融资讯、舆情分析等场景,存储新闻的元数据、内容及情感分析结果。
type NewsItem struct {
// Symbol 代表与该新闻相关的金融产品代码(如股票代码 "AAPL")。
// 该字段是新闻关联资产的关键标识符。
Symbol string `json:"symbol"`
// Headline 是新闻的标题。
// 此字段为必填项,应简洁概括新闻主要内容。
Headline string `json:"headline"`
// Source 指明新闻的发布来源(例如:"路透社"、"彭博社")。
// 该字段为可选字段,若为空则不会在 JSON 输出中体现。
Source string `json:"source,omitempty"`
// URL 是新闻原文的完整链接。
// 该字段为可选字段,若为空则不会在 JSON 输出中体现。
URL string `json:"url,omitempty"`
// PublishedAt 记录新闻准确的发布时间。
// 使用 time.Time 类型以确保时间数据的一致性和可序列化。
PublishedAt time.Time `json:"published_at"`
// Sentiment 表示对新闻内容进行情感分析得出的分值。
// 取值范围为 -100 到 100其中 -100 代表极度负面100 代表极度正面0 为中性。
// 该字段为可选字段,若未进行分析则不会在 JSON 输出中体现。
Sentiment int `json:"sentiment,omitempty"`
// Impact 评估该新闻可能对市场产生的影响程度。
// 取值范围为 0 到 100数值越大表示潜在影响越大。
// 该字段为可选字段,若未进行评估则不会在 JSON 输出中体现。
Impact int `json:"impact,omitempty"`
// Summary 是新闻内容的简要摘要或关键要点。
// 该字段为可选字段,若为空则不会在 JSON 输出中体现。
Summary string `json:"summary,omitempty"`
// Tags 是与新闻内容相关的关键词标签列表(例如:["科技", "财报", "Apple"])。
// 该字段为可选字段,若为空切片则不会在 JSON 输出中体现。
Tags []string `json:"tags,omitempty"`
}
func (ni NewsItem) String() string {
return fmt.Sprintf("代币符号: %s\n标题: %s\n来源: %s\n发布时间: %s\n情感分数: %d\n影响指数: %d\n摘要: %s\n标签: %v\n%s\n",
ni.Symbol,
ni.Headline,
ni.Source,
ni.PublishedAt.Format("2006-01-02 15:04:05"),
ni.Sentiment,
ni.Impact,
ni.Summary,
ni.Tags,
"-----------",
)
}
// Provider 新闻提供者接口(由调用方实现)
type Provider interface {
// FetchNews 按币种批量获取最新新闻返回值按symbol分组
FetchNews(symbols []string, limit int) (map[string][]NewsItem, error)
}