feat(crypto策略): 支持巴菲特策略纯 rawMessage 信号推送
Motivation: 新增巴菲特激进/稳健策略(PUTEJJ/PUTEWJ)的跟单推送能力。该类信号仅有 rawMessage、无 action 字段,需按原文直接推送,并过滤启动文案、本地化时间字段。 Changes: * 支持无 action 的纯 rawMessage 信号,映射为 trade.message 事件 * 新增 not_contains 条件操作符,用于过滤启动文案 * 新增 replace 模板函数,将 Time: 替换为推送时间: * 补充巴菲特策略模板、规则与渠道配置文档
This commit is contained in:
@@ -29,7 +29,14 @@ func (c *Converter) Convert(body []byte) (string, map[string]interface{}, error)
|
||||
return "", nil, fmt.Errorf("%w: %v", ErrInvalidSignal, err)
|
||||
}
|
||||
if strings.TrimSpace(sig.Action) == "" {
|
||||
return "", nil, fmt.Errorf("%w: missing action", ErrInvalidSignal)
|
||||
if strings.TrimSpace(sig.RawMessage) == "" {
|
||||
return "", nil, fmt.Errorf("%w: missing action", ErrInvalidSignal)
|
||||
}
|
||||
data, err := toData(body, &sig)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
return "trade.message", data, nil
|
||||
}
|
||||
out := Apply(&sig, c.overrideFor(sig.StrategyCode))
|
||||
snap := c.positions.Apply(out)
|
||||
|
||||
@@ -62,3 +62,19 @@ func TestConvertMissingAction(t *testing.T) {
|
||||
t.Fatalf("err=%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertRawMessageWithoutAction(t *testing.T) {
|
||||
event, data, err := NewConverter(nil).Convert([]byte(`{
|
||||
"strategyCode":"PUTEJJ",
|
||||
"rawMessage":"4.7.15~2026.8.15 本周期 10万本金 期末109640,盈利9.6%"
|
||||
}`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if event != "trade.message" {
|
||||
t.Fatalf("event=%q", event)
|
||||
}
|
||||
if data["rawMessage"] != "4.7.15~2026.8.15 本周期 10万本金 期末109640,盈利9.6%" {
|
||||
t.Fatalf("data=%v", data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ type Signal struct {
|
||||
StopLossRatio *float64 `json:"stopLossRatio"`
|
||||
PnL *float64 `json:"pnl"`
|
||||
AccountBalance *float64 `json:"accountBalance"`
|
||||
RawMessage string `json:"rawMessage"`
|
||||
}
|
||||
|
||||
func (s *Signal) ParsedEventTime() time.Time {
|
||||
|
||||
Reference in New Issue
Block a user