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.
79 lines
2.1 KiB
79 lines
2.1 KiB
package sig |
|
|
|
import ( |
|
"fmt" |
|
"sig-pub/pkg/indicator" |
|
"sig-pub/pkg/strategy" |
|
"sig-pub/pkg/types" |
|
"sig-pub/pkg/types/series" |
|
) |
|
|
|
type IOffsetStrategyContext interface { |
|
strategy.ISigStrategyContext |
|
SetOffset(offset int16) |
|
} |
|
|
|
type StrategyContext struct { |
|
IOffsetStrategyContext |
|
|
|
indicatorContext IOffsetIndicatorContext |
|
indicatorsReg *indicator.IndicatorRegistry |
|
} |
|
|
|
func NewStrategyContext(indicatorContext IOffsetIndicatorContext, indicatorsReg *indicator.IndicatorRegistry) *StrategyContext { |
|
return &StrategyContext{ |
|
indicatorContext: indicatorContext, |
|
indicatorsReg: indicatorsReg, |
|
} |
|
} |
|
|
|
func (c *StrategyContext) SetOffset(offset int16) { |
|
c.indicatorContext.SetOffset(offset) |
|
} |
|
|
|
func (c *StrategyContext) Get(offset int16) (kline types.Kline) { |
|
return c.indicatorContext.Get(offset) |
|
} |
|
|
|
func (c *StrategyContext) Series(offset, count int16) (klines series.Klines) { |
|
return c.indicatorContext.Series(offset, count) |
|
} |
|
|
|
// 获取窗口类型指标 |
|
func (c *StrategyContext) IndicatorW(name string, window int16) (s indicator.IIndicatorSeries) { |
|
indicator, ok := c.indicatorsReg.IndicatorW(name) |
|
if !ok { |
|
panic(fmt.Errorf("indicatorW %s not exists", name)) |
|
} |
|
return NewWindowIndicatorSeries(window, indicator, c.indicatorContext) |
|
} |
|
|
|
type IOffsetIntervalStrategyContext interface { |
|
strategy.IIntervalStrategyContext |
|
SetOffset(offset int16) |
|
} |
|
|
|
// IntervalStrategyContext 周期策略上下文 |
|
type IntervalStrategyContext struct { |
|
IOffsetIntervalStrategyContext |
|
} |
|
|
|
// Get [0]当前k线 |
|
func (c *IntervalStrategyContext) Get(interval types.Interval, offset int16) (kline types.Kline) { |
|
return |
|
} |
|
|
|
// Series [offset...end] |
|
func (c *IntervalStrategyContext) Series(interval types.Interval, offset, count int16) (klines series.Klines) { |
|
return |
|
} |
|
|
|
// 获取窗口类型指标 |
|
func (c *IntervalStrategyContext) IndicatorW(interval types.Interval, name string, window int16) (series indicator.IIndicatorSeries) { |
|
return |
|
} |
|
|
|
// 获取其它策略 |
|
// func (c *IntervalStrategyContext) SigStrategy(interval types.Interval, name string, sigParam strategy.SigStrategyParam) (sigStrategy strategy.ISigStrategy) { |
|
// return |
|
// }
|
|
|