mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 07:26:48 +00:00
Update to GCT script library (#496)
* * Adds script link to GCT logger package * Adds ability to save data as csv via script * addr nits * go mod tidy * add glorious suggestion * rm unused function * fix linter issues * clean up some issues * Add in configuration fields to object for reflection to the csv file * RM line :D * address nits * update to check for target already being set and add more test coverage * force usage of .csv file extention && append date to client filename as to not overwrite file if collision occurs * fix whoopsie * linter issues * purge getter methods * Added glorious suggestion * go mod tidy after merge * niterinos
This commit is contained in:
@@ -17,12 +17,25 @@ var AtrModule = map[string]objects.Object{
|
||||
"calculate": &objects.UserFunction{Name: "calculate", Value: atr},
|
||||
}
|
||||
|
||||
// AverageTrueRange is the string constant
|
||||
const AverageTrueRange = "Average True Range"
|
||||
|
||||
// ATR defines a custom Average True Range indicator tengo object
|
||||
type ATR struct {
|
||||
objects.Array
|
||||
Period int
|
||||
}
|
||||
|
||||
// TypeName returns the name of the custom type.
|
||||
func (o *ATR) TypeName() string {
|
||||
return AverageTrueRange
|
||||
}
|
||||
|
||||
func atr(args ...objects.Object) (objects.Object, error) {
|
||||
if len(args) != 2 {
|
||||
return nil, objects.ErrWrongNumArguments
|
||||
}
|
||||
|
||||
r := &objects.Array{}
|
||||
r := new(ATR)
|
||||
if validator.IsTestExecution.Load() == true {
|
||||
return r, nil
|
||||
}
|
||||
@@ -71,6 +84,7 @@ func atr(args ...objects.Object) (objects.Object, error) {
|
||||
return nil, errors.New(strings.Join(allErrors, ", "))
|
||||
}
|
||||
|
||||
r.Period = inTimePeriod
|
||||
ret := indicators.ATR(ohlcvData[2], ohlcvData[3], ohlcvData[4], inTimePeriod)
|
||||
for x := range ret {
|
||||
r.Value = append(r.Value, &objects.Float{Value: math.Round(ret[x]*100) / 100})
|
||||
|
||||
@@ -17,14 +17,30 @@ var BBandsModule = map[string]objects.Object{
|
||||
"calculate": &objects.UserFunction{Name: "calculate", Value: bbands},
|
||||
}
|
||||
|
||||
// BollingerBands is the string constant
|
||||
const BollingerBands = "Bollinger Bands"
|
||||
|
||||
// BBands defines a custom Bollinger Bands indicator tengo object
|
||||
type BBands struct {
|
||||
objects.Array
|
||||
Period int
|
||||
STDDevUp, STDDevDown float64
|
||||
MAType indicators.MaType
|
||||
}
|
||||
|
||||
// TypeName returns the name of the custom type.
|
||||
func (o *BBands) TypeName() string {
|
||||
return BollingerBands
|
||||
}
|
||||
|
||||
func bbands(args ...objects.Object) (objects.Object, error) {
|
||||
if len(args) != 6 {
|
||||
return nil, objects.ErrWrongNumArguments
|
||||
}
|
||||
|
||||
var ret objects.Array
|
||||
r := new(BBands)
|
||||
if validator.IsTestExecution.Load() == true {
|
||||
return &ret, nil
|
||||
return r, nil
|
||||
}
|
||||
|
||||
ohlcIndicatorType, ok := objects.ToString(args[0])
|
||||
@@ -101,6 +117,11 @@ func bbands(args ...objects.Object) (objects.Object, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r.Period = inTimePeriod
|
||||
r.STDDevDown = inNbDevDn
|
||||
r.STDDevUp = inNbDevUp
|
||||
r.MAType = MAType
|
||||
|
||||
retUpper, retMiddle, retLower := indicators.BBANDS(ohlcvData[selector], inTimePeriod, inNbDevDn, inNbDevDn, MAType)
|
||||
for x := range retMiddle {
|
||||
temp := &objects.Array{}
|
||||
@@ -111,8 +132,8 @@ func bbands(args ...objects.Object) (objects.Object, error) {
|
||||
if retLower != nil {
|
||||
temp.Value = append(temp.Value, &objects.Float{Value: math.Round(retLower[x]*100) / 100})
|
||||
}
|
||||
ret.Value = append(ret.Value, temp)
|
||||
r.Value = append(r.Value, temp)
|
||||
}
|
||||
|
||||
return &ret, nil
|
||||
return r, nil
|
||||
}
|
||||
|
||||
@@ -17,12 +17,26 @@ var EMAModule = map[string]objects.Object{
|
||||
"calculate": &objects.UserFunction{Name: "calculate", Value: ema},
|
||||
}
|
||||
|
||||
// ExponentialMovingAverage is the string constant
|
||||
const ExponentialMovingAverage = "Exponential Moving Average"
|
||||
|
||||
// EMA defines a custom Exponential Moving Average indicator tengo object
|
||||
type EMA struct {
|
||||
objects.Array
|
||||
Period int
|
||||
}
|
||||
|
||||
// TypeName returns the name of the custom type.
|
||||
func (o *EMA) TypeName() string {
|
||||
return ExponentialMovingAverage
|
||||
}
|
||||
|
||||
func ema(args ...objects.Object) (objects.Object, error) {
|
||||
if len(args) != 2 {
|
||||
return nil, objects.ErrWrongNumArguments
|
||||
}
|
||||
|
||||
r := &objects.Array{}
|
||||
r := new(EMA)
|
||||
if validator.IsTestExecution.Load() == true {
|
||||
return r, nil
|
||||
}
|
||||
@@ -54,6 +68,8 @@ func ema(args ...objects.Object) (objects.Object, error) {
|
||||
return nil, errors.New(strings.Join(allErrors, ", "))
|
||||
}
|
||||
|
||||
r.Period = inTimePeriod
|
||||
|
||||
ret := indicators.EMA(ohlcvClose, inTimePeriod)
|
||||
for x := range ret {
|
||||
r.Value = append(r.Value, &objects.Float{Value: math.Round(ret[x]*100) / 100})
|
||||
|
||||
@@ -17,12 +17,27 @@ var MACDModule = map[string]objects.Object{
|
||||
"calculate": &objects.UserFunction{Name: "calculate", Value: macd},
|
||||
}
|
||||
|
||||
// MovingAverageConvergenceDivergence is the string constant
|
||||
const MovingAverageConvergenceDivergence = "Moving Average Convergence Divergence"
|
||||
|
||||
// MACD defines a custom Moving Average Convergence Divergence tengo indicator
|
||||
// object type
|
||||
type MACD struct {
|
||||
objects.Array
|
||||
Period, PeriodSlow, PeriodFast int
|
||||
}
|
||||
|
||||
// TypeName returns the name of the custom type.
|
||||
func (o *MACD) TypeName() string {
|
||||
return MovingAverageConvergenceDivergence
|
||||
}
|
||||
|
||||
func macd(args ...objects.Object) (objects.Object, error) {
|
||||
if len(args) != 4 {
|
||||
return nil, objects.ErrWrongNumArguments
|
||||
}
|
||||
|
||||
r := &objects.Array{}
|
||||
r := new(MACD)
|
||||
if validator.IsTestExecution.Load() == true {
|
||||
return r, nil
|
||||
}
|
||||
@@ -63,6 +78,10 @@ func macd(args ...objects.Object) (objects.Object, error) {
|
||||
return nil, errors.New(strings.Join(allErrors, ", "))
|
||||
}
|
||||
|
||||
r.Period = inTimePeriod
|
||||
r.PeriodFast = inFastPeriod
|
||||
r.PeriodSlow = inSlowPeriod
|
||||
|
||||
macd, macdSignal, macdHist := indicators.MACD(ohlcvClose, inFastPeriod, inSlowPeriod, inTimePeriod)
|
||||
for x := range macdHist {
|
||||
tempMACD := &objects.Array{}
|
||||
|
||||
@@ -17,12 +17,26 @@ var MfiModule = map[string]objects.Object{
|
||||
"calculate": &objects.UserFunction{Name: "calculate", Value: mfi},
|
||||
}
|
||||
|
||||
// MoneyFlowIndex is the string constant
|
||||
const MoneyFlowIndex = "Money Flow Index"
|
||||
|
||||
// MFI defines a custom Money Flow Index tengo indicator object type
|
||||
type MFI struct {
|
||||
objects.Array
|
||||
Period int
|
||||
}
|
||||
|
||||
// TypeName returns the name of the custom type.
|
||||
func (o *MFI) TypeName() string {
|
||||
return MoneyFlowIndex
|
||||
}
|
||||
|
||||
func mfi(args ...objects.Object) (objects.Object, error) {
|
||||
if len(args) != 2 {
|
||||
return nil, objects.ErrWrongNumArguments
|
||||
}
|
||||
|
||||
r := &objects.Array{}
|
||||
r := new(MFI)
|
||||
if validator.IsTestExecution.Load() == true {
|
||||
return r, nil
|
||||
}
|
||||
@@ -69,6 +83,8 @@ func mfi(args ...objects.Object) (objects.Object, error) {
|
||||
return nil, fmt.Errorf(modules.ErrParameterConvertFailed, inTimePeriod)
|
||||
}
|
||||
|
||||
r.Period = inTimePeriod
|
||||
|
||||
ret := indicators.MFI(ohlcvData[2], ohlcvData[3], ohlcvData[4], ohlcvData[5], inTimePeriod)
|
||||
for x := range ret {
|
||||
r.Value = append(r.Value, &objects.Float{Value: math.Round(ret[x]*100) / 100})
|
||||
|
||||
@@ -17,12 +17,25 @@ var ObvModule = map[string]objects.Object{
|
||||
"calculate": &objects.UserFunction{Name: "calculate", Value: obv},
|
||||
}
|
||||
|
||||
// OnBalanceVolume is the string constant
|
||||
const OnBalanceVolume = "On Balance Volume"
|
||||
|
||||
// OBV defines a custom On Balance Volume tengo indicator object type
|
||||
type OBV struct {
|
||||
objects.Array
|
||||
}
|
||||
|
||||
// TypeName returns the name of the custom type.
|
||||
func (o *OBV) TypeName() string {
|
||||
return OnBalanceVolume
|
||||
}
|
||||
|
||||
func obv(args ...objects.Object) (objects.Object, error) {
|
||||
if len(args) != 1 {
|
||||
return nil, objects.ErrWrongNumArguments
|
||||
}
|
||||
|
||||
r := &objects.Array{}
|
||||
r := new(OBV)
|
||||
if validator.IsTestExecution.Load() == true {
|
||||
return r, nil
|
||||
}
|
||||
|
||||
@@ -17,12 +17,26 @@ var RsiModule = map[string]objects.Object{
|
||||
"calculate": &objects.UserFunction{Name: "calculate", Value: rsi},
|
||||
}
|
||||
|
||||
// RelativeStrengthIndex is the string constant
|
||||
const RelativeStrengthIndex = "Relative Strength Index"
|
||||
|
||||
// RSI defines a custom Relative Strength Index indicator tengo object type
|
||||
type RSI struct {
|
||||
objects.Array
|
||||
Period int
|
||||
}
|
||||
|
||||
// TypeName returns the name of the custom type.
|
||||
func (o *RSI) TypeName() string {
|
||||
return RelativeStrengthIndex
|
||||
}
|
||||
|
||||
func rsi(args ...objects.Object) (objects.Object, error) {
|
||||
if len(args) != 2 {
|
||||
return nil, objects.ErrWrongNumArguments
|
||||
}
|
||||
|
||||
r := &objects.Array{}
|
||||
r := new(RSI)
|
||||
if validator.IsTestExecution.Load() == true {
|
||||
return r, nil
|
||||
}
|
||||
@@ -54,6 +68,7 @@ func rsi(args ...objects.Object) (objects.Object, error) {
|
||||
return nil, errors.New(strings.Join(allErrors, ", "))
|
||||
}
|
||||
|
||||
r.Period = inTimePeriod
|
||||
ret := indicators.RSI(ohlcvClose, inTimePeriod)
|
||||
for x := range ret {
|
||||
r.Value = append(r.Value, &objects.Float{Value: math.Round(ret[x]*100) / 100})
|
||||
|
||||
@@ -17,12 +17,26 @@ var SMAModule = map[string]objects.Object{
|
||||
"calculate": &objects.UserFunction{Name: "calculate", Value: sma},
|
||||
}
|
||||
|
||||
// SimpleMovingAverage is the string constant
|
||||
const SimpleMovingAverage = "Simple Moving Average"
|
||||
|
||||
// SMA defines a custom Simple Moving Average indicator tengo object type
|
||||
type SMA struct {
|
||||
objects.Array
|
||||
Period int
|
||||
}
|
||||
|
||||
// TypeName returns the name of the custom type.
|
||||
func (o *SMA) TypeName() string {
|
||||
return SimpleMovingAverage
|
||||
}
|
||||
|
||||
func sma(args ...objects.Object) (objects.Object, error) {
|
||||
if len(args) != 2 {
|
||||
return nil, objects.ErrWrongNumArguments
|
||||
}
|
||||
|
||||
r := &objects.Array{}
|
||||
r := new(SMA)
|
||||
if validator.IsTestExecution.Load() == true {
|
||||
return r, nil
|
||||
}
|
||||
@@ -52,6 +66,7 @@ func sma(args ...objects.Object) (objects.Object, error) {
|
||||
if len(allErrors) > 0 {
|
||||
return nil, errors.New(strings.Join(allErrors, ", "))
|
||||
}
|
||||
r.Period = inTimePeriod
|
||||
ret := indicators.SMA(ohlcvClose, inTimePeriod)
|
||||
for x := range ret {
|
||||
r.Value = append(r.Value, &objects.Float{Value: math.Round(ret[x]*100) / 100})
|
||||
|
||||
Reference in New Issue
Block a user