fix(交易信号): 修复未追踪仓位时平均单价渲染为 %!f(<nil>) 的问题
- 本地无均价记录时回退使用上游 totalAvgPx - 跟单模板在无均价时不再输出平均单价行
This commit is contained in:
@@ -50,8 +50,7 @@ func (c *Converter) Convert(body []byte) (string, map[string]interface{}, error)
|
||||
return "", nil, fmt.Errorf("%w: %v", ErrPositionStore, err)
|
||||
}
|
||||
var opts FormatOptions
|
||||
if snap.HasAvg {
|
||||
avg := snap.AvgPrice
|
||||
if avg, ok := avgPriceFor(snap, out); ok {
|
||||
opts.AvgPrice = &avg
|
||||
}
|
||||
text := Format(out, opts)
|
||||
@@ -60,12 +59,24 @@ func (c *Converter) Convert(body []byte) (string, map[string]interface{}, error)
|
||||
return "", nil, err
|
||||
}
|
||||
data["formatted"] = text
|
||||
if snap.HasAvg {
|
||||
data["avgPrice"] = snap.AvgPrice
|
||||
if opts.AvgPrice != nil {
|
||||
data["avgPrice"] = *opts.AvgPrice
|
||||
}
|
||||
return "trade." + strings.ToLower(out.Action), data, nil
|
||||
}
|
||||
|
||||
// avgPriceFor prefers the tracked average and falls back to the upstream
|
||||
// totalAvgPx when the tracker never saw the position open.
|
||||
func avgPriceFor(snap Snapshot, sig *Signal) (float64, bool) {
|
||||
if snap.HasAvg {
|
||||
return snap.AvgPrice, true
|
||||
}
|
||||
if sig.TotalAvgPx != nil && *sig.TotalAvgPx > 0 {
|
||||
return *sig.TotalAvgPx, true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func (c *Converter) overrideFor(code string) *config.StrategyOverride {
|
||||
if c == nil || len(c.overrides) == 0 || code == "" {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user