feat(订阅): 新增 crypto-strategy 信号格式化器
Motivation: crypto-strategy 交易信号采用 envelope 外壳与字符串化/嵌套的 payload,原有 trade_signal 格式化器无法解析,需要独立的转换逻辑以生成通知文本和事件数据。 Changes: * 新增 crypto_strategy 消息转换器,解析 envelope 及嵌套、字符串化、扁平三种 payload 形态 * 根据平仓/止盈/卖出等标志推断交易动作,生成对应事件类型与中文通知文本 * 提取订单号、策略代码、价格、杠杆等字段用于通知数据 * 将消息转换器抽象为接口,订阅器按 formatter 配置选择对应实现 * 更新配置校验以支持 crypto_strategy 格式化器,并补充单元测试
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"aiaa-notification-service/internal/config"
|
||||
"aiaa-notification-service/internal/subscriber/cryptostrategy"
|
||||
"aiaa-notification-service/internal/subscriber/tradesignal"
|
||||
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
@@ -15,19 +16,25 @@ import (
|
||||
|
||||
type Subscriber struct {
|
||||
cfg config.SubscriptionConfig
|
||||
conv *tradesignal.Converter
|
||||
conv MessageConverter
|
||||
lookup SourceLookup
|
||||
process ProcessFunc
|
||||
deduper Deduper
|
||||
}
|
||||
|
||||
func New(cfg config.SubscriptionConfig, lookup SourceLookup, process ProcessFunc, deduper Deduper) (*Subscriber, error) {
|
||||
if cfg.Formatter != "trade_signal" {
|
||||
var conv MessageConverter
|
||||
switch cfg.Formatter {
|
||||
case "trade_signal":
|
||||
conv = tradesignal.NewConverter(cfg.StrategyOverrides)
|
||||
case "crypto_strategy":
|
||||
conv = cryptostrategy.NewConverter()
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown formatter %q", cfg.Formatter)
|
||||
}
|
||||
return &Subscriber{
|
||||
cfg: cfg,
|
||||
conv: tradesignal.NewConverter(cfg.StrategyOverrides),
|
||||
conv: conv,
|
||||
lookup: lookup,
|
||||
process: process,
|
||||
deduper: deduper,
|
||||
|
||||
Reference in New Issue
Block a user