18 changed files with 152 additions and 33 deletions
@ -0,0 +1,24 @@
|
||||
package indicator |
||||
|
||||
import ( |
||||
"github.com/markcheno/go-talib" |
||||
) |
||||
|
||||
// RSI stateless indicator
|
||||
// 相对强弱指数 (RSI) rsi define: https://www.investopedia.com/terms/r/rsi.asp
|
||||
type SMA struct { |
||||
} |
||||
|
||||
// indicator interface
|
||||
func (c *SMA) Name() string { |
||||
return "sma" |
||||
} |
||||
|
||||
// Calculate 计算单根k线sma指标
|
||||
func (c *SMA) Calculate(ctx IIndicatorContext, window int16) (vector float64) { |
||||
closeSeries := ctx.Series(0, window).Close() |
||||
sma := talib.Sma(closeSeries, int(window)) |
||||
_ = sma[len(sma)-1] |
||||
vector = closeSeries.Avg() |
||||
return |
||||
} |
||||
@ -0,0 +1,11 @@
|
||||
package strategy |
||||
|
||||
// IExchangesSigStrategy 多交易所策略
|
||||
type IExchangesSigStrategy interface { |
||||
ISigStrategy |
||||
} |
||||
|
||||
// IExchangesIntervalsStrategy 多交易所多周期策略
|
||||
type IExchangesIntervalsStrategy interface { |
||||
ISigStrategy |
||||
} |
||||
@ -0,0 +1,30 @@
|
||||
package strategy |
||||
|
||||
import ( |
||||
"sig-pub/pkg/indicator" |
||||
"sig-pub/pkg/types" |
||||
"sig-pub/pkg/types/series" |
||||
) |
||||
|
||||
// 多周期k线策略
|
||||
type IIntervalsSigStrategy interface { |
||||
New() IIntervalsSigStrategy |
||||
Meta() StrategyMeta |
||||
Update(ctx IIntervalsSigStrategyContext) |
||||
DriverIntervals() []types.Interval // 驱动k线周期, 当驱动周期k线更新时则判断调用Update方法
|
||||
SubscribeIntervals() []types.Interval // 订阅k线周期, 当同一时间的订阅周期都更新时调用Update方法
|
||||
} |
||||
|
||||
// ISigStrategyContext 策略外部访问能力
|
||||
// klineSeries, Indicator
|
||||
type IIntervalsSigStrategyContext interface { |
||||
Buy() // 发出多信号
|
||||
Sell() // 发出空信号
|
||||
|
||||
// Get [0]当前k线
|
||||
Get(interval types.Interval, offset int16) types.Kline |
||||
// Series [offset...end]
|
||||
Series(interval types.Interval, offset, count int16) (klines series.Klines) |
||||
// 获取窗口类型指标
|
||||
IndicatorW(interval types.Interval, name string, window int16) indicator.IIndicatorSeries |
||||
} |
||||
@ -1,18 +0,0 @@
|
||||
package strategy |
||||
|
||||
import "sig-pub/pkg/types" |
||||
|
||||
// 多k线周期策略
|
||||
type MultiIntervalStrategy interface { |
||||
ISigStrategy |
||||
DriverInterval() types.Interval // 驱动k线周期, 当驱动周期k线更新时则判断调用Update方法
|
||||
SubscribeIntervals() []types.Interval // 订阅k线周期, 当同一时间的订阅周期都更新时调用Update方法
|
||||
} |
||||
|
||||
type MultiExchangeStrategy interface { |
||||
ISigStrategy |
||||
} |
||||
|
||||
type MultiIntervalExchangeStrategy interface { |
||||
ISigStrategy |
||||
} |
||||
Loading…
Reference in new issue