You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.6 KiB
78 lines
1.6 KiB
package trader |
|
|
|
import ( |
|
"fmt" |
|
"sig-pub/pkg/types" |
|
"sig-pub/pkg/types/series" |
|
"sig-pub/pkg/zlog" |
|
|
|
"github.com/spf13/cast" |
|
) |
|
|
|
// stateful |
|
type StrategyTrendTrace struct { |
|
intervalDatas map[types.Interval]*series.LimitFloats |
|
|
|
argBaseLine int |
|
} |
|
|
|
func NewStrategyTrendTrace() *StrategyTrendTrace { |
|
return &StrategyTrendTrace{} |
|
} |
|
|
|
func (StrategyTrendTrace) Meta() StrategyMeta { |
|
return StrategyMeta{ |
|
SubIntervals: []types.Interval{ |
|
types.Interval5m, types.Interval15m, types.Interval1d, |
|
}, |
|
} |
|
} |
|
|
|
func (s *StrategyTrendTrace) initArgs(args map[string]string) (err error) { |
|
|
|
return |
|
} |
|
|
|
func (s *StrategyTrendTrace) Init(ctx StrategyContext, args map[string]string) (code ErrorCode, err error) { |
|
s.argBaseLine, err = cast.ToIntE(args["baseLine"]) |
|
if err != nil { |
|
return |
|
} |
|
if s.argBaseLine <= 0 { |
|
|
|
} |
|
|
|
s.intervalDatas = map[types.Interval]*series.LimitFloats{ |
|
types.Interval5m: series.NewLimitFloats(s.argBaseLine), |
|
types.Interval15m: series.NewLimitFloats(s.argBaseLine), |
|
types.Interval1d: series.NewLimitFloats(s.argBaseLine), |
|
} |
|
return |
|
} |
|
|
|
func (s *StrategyTrendTrace) Update(ctx StrategyContext, kline types.Kline) (code ErrorCode, err error) { |
|
data, ok := s.intervalDatas[kline.Interval] |
|
if !ok { |
|
zlog.Warningf("ignore interval kline: %v", kline.Interval) |
|
return |
|
} |
|
|
|
v, ok := kline.Close.Float64() |
|
if !ok { |
|
code = ErrorCodeKline |
|
err = fmt.Errorf("kline close value error: %#v", kline) |
|
return |
|
} |
|
data.Push(v) |
|
|
|
// calc klines |
|
s.caculate() |
|
return |
|
} |
|
|
|
func (s *StrategyTrendTrace) caculate() { |
|
// 5m判断趋势, 15m/1h 确认趋势 |
|
datas5m := s.intervalDatas[types.Interval5m] |
|
minV, maxV := datas5m.MinMax() |
|
_, _ = minV, maxV |
|
}
|
|
|