diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..13ee2b0 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "nuxt.isNuxtApp": false +} \ No newline at end of file diff --git a/commonstock/ATR.go b/commonstock/ATR.go new file mode 100644 index 0000000..69c62a9 --- /dev/null +++ b/commonstock/ATR.go @@ -0,0 +1,57 @@ +package commonstock + +import ( + "math" + "time" + + "github.com/idoall/TokenExchangeCommon/commonmodels" +) + +// ATR struct +type ATR struct { + Period int //默认计算几天的MA,KDJ一般是9,OBV是10、20、30 + data []ATRPoint + kline []*commonmodels.Kline +} + +type ATRPoint struct { + Time time.Time + TR float64 + ATR float64 +} + +// NewATR new Func +func NewATR(list []*commonmodels.Kline, period int) *ATR { + m := &ATR{kline: list, Period: period} + return m +} + +// Calculation Func +func (e *ATR) Calculation() *ATR { + + for i := 0; i < len(e.kline); i++ { + klineItem := e.kline[i] + var ATRPointStruct ATRPoint + ATRPointStruct.TR = math.Max(klineItem.High-klineItem.Low, math.Max(klineItem.High-klineItem.Close, klineItem.Close-klineItem.Low)) + ATRPointStruct.Time = e.kline[i].KlineTime + e.data = append(e.data, ATRPointStruct) + } + + var tempKline []*commonmodels.Kline + for _, v := range e.data { + tempKline = append(tempKline, &commonmodels.Kline{ + Close: v.TR, + }) + } + + var atr = NewEMA(tempKline, e.Period).Calculation().GetPoints() + for i := 0; i < len(atr); i++ { + e.data[i].ATR = atr[i].Value + } + return e +} + +// GetPoints Func +func (e *ATR) GetPoints() []ATRPoint { + return e.data +} diff --git a/commonstock/MACD.go b/commonstock/MACD.go index 82ed83b..d3d40ca 100644 --- a/commonstock/MACD.go +++ b/commonstock/MACD.go @@ -35,6 +35,7 @@ type MACDPoint struct { DIF float64 DEA float64 MACD float64 + Hist float64 } // NewMACD new Func diff --git a/commonutils/checkmail/checkmail_test.go b/commonutils/checkmail/checkmail_test.go index 8f95ad6..22480dd 100644 --- a/commonutils/checkmail/checkmail_test.go +++ b/commonutils/checkmail/checkmail_test.go @@ -33,7 +33,7 @@ func TestValidateHost(t *testing.T) { continue } - err := checkmail.ValidateHost(s.mail) + err := ValidateHost(s.mail) if err != nil && s.account == true { t.Errorf(`"%s" => unexpected error: "%v"`, s.mail, err) } @@ -45,7 +45,7 @@ func TestValidateHost(t *testing.T) { func TestValidateFormat(t *testing.T) { for _, s := range samples { - err := checkmail.ValidateFormat(s.mail) + err := ValidateFormat(s.mail) if err != nil && s.format == true { t.Errorf(`"%s" => unexpected error: "%v"`, s.mail, err) } diff --git a/go.mod b/go.mod index 8ffcf1d..1539b39 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,14 @@ module github.com/idoall/TokenExchangeCommon +go 1.17 + require ( - github.com/davecgh/go-spew v1.1.1 // indirect github.com/json-iterator/go v1.1.5 - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 - github.com/stretchr/testify v1.2.2 // indirect ) -go 1.13 +require ( + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.1 // indirect + github.com/stretchr/testify v1.8.2 // indirect +) diff --git a/go.sum b/go.sum index 9bb8b0e..8a19d68 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,4 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswDE= @@ -10,5 +11,14 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 h1:pntxY8Ary0t43dCZ5dqY4YTJCObLY1kIXl0uzMv+7DE= github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=