Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GCTScript) add technical analysis support via go-talib script bindings #467

Open
wants to merge 51 commits into
base: master
from

Conversation

@xtda
Copy link
Member

xtda commented Mar 10, 2020

PR Description

This PR adds script bindings for go-talib adding support for technical indicators to be used within scripts

fmt := import("fmt")
exch := import("exchange")
t := import("times")
ind := import("indicator/rsi")

load := func() {
   start := t.add(t.now(), -t.hour*24*30)
   ohlcvData := exch.ohlcv("BTC Markets", "BTC-AUD", "-", "", start, t.now(), "1d")
   rsi := ind.rsi(ohlcvData.candles, 14)
   fmt.println(rsi)
}

load()

Support has been added so far for:

  • RSI
  • EMA
  • SMA
  • OBV
  • MFI
  • MACD
  • Atr
  • Bbands

I am looking at adding more and any other suggestions that people want

At the moment data is manually passed back using an array but when #454 gets merged in support will be added as well to just get ohlc data direct from exchange and pass to required indicator

Type of change

  • New feature (non-breaking change which adds functionality)

How has this been tested

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration and
also consider improving test coverage whilst working on a certain feature or package.

  • go test ./... -race
  • golangci-lint run

Example scripts have been written and included in /gctscript/examples/ta

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation and regenerated documentation via the documentation tool
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally and on Travis with my changes
  • Any dependent changes have been merged and published in downstream modules
xtda added 13 commits Mar 3, 2020
…o append helper method
@xtda xtda self-assigned this Mar 10, 2020
Copy link

codelingo bot left a comment

LGTM

@xtda xtda added reconstructing and removed review me labels Mar 11, 2020
Copy link
Collaborator

shazbert left a comment

Awesome PR! Just a few things I found.

gctscript/modules/ta/indicators/index.go Outdated Show resolved Hide resolved
gctscript/modules/ta/indicators/index.go Outdated Show resolved Hide resolved
gctscript/modules/ta/indicators/indicators_test.go Outdated Show resolved Hide resolved
gctscript/modules/ta/indicators/volume.go Outdated Show resolved Hide resolved
@codecov

This comment has been minimized.

Copy link

codecov bot commented Mar 12, 2020

Codecov Report

Merging #467 into master will not change coverage by %.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #467   +/-   ##
=======================================
  Coverage   46.02%   46.02%           
=======================================
  Files         220      220           
  Lines       49406    49406           
=======================================
  Hits        22737    22737           
  Misses      24393    24393           
  Partials     2276     2276           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f76aef2...f76aef2. Read the comment docs.

Copy link

codelingo bot left a comment

LGTM

…orrect now passing full OHLCV data back to script binding
Copy link

codelingo bot left a comment

LGTM

xtda added 4 commits Mar 25, 2020
Copy link
Collaborator

MadCozBadd left a comment

Rest looking good man! nice PR

gctscript/modules/ta/indicators/macd.go Show resolved Hide resolved
gctscript/modules/ta/indicators/sma.go Show resolved Hide resolved

import objects "github.com/d5/tengo/v2"

var BBandsModule = map[string]objects.Object{}

This comment has been minimized.

Copy link
@MadCozBadd

MadCozBadd Mar 26, 2020

Collaborator

comment plz

gctscript/modules/ta/indicators/ema.go Show resolved Hide resolved
Copy link
Collaborator

shazbert left a comment

Just had a quick looky, found some things.

"github.com/thrasher-corp/gocryptotrader/gctscript/modules"
)

var supportedDurations = []string{"1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "6h", "12h", "24h", "1d", "3d", "1w"}

This comment has been minimized.

Copy link
@shazbert

shazbert Mar 26, 2020

Collaborator

If you don't want to I will just resolve.

gctscript/modules/ta/indicators/macd.go Outdated Show resolved Hide resolved
@xtda xtda added reconstructing and removed review me labels Mar 26, 2020
xtda added 7 commits Mar 26, 2020
xtda added 2 commits Mar 30, 2020
candles.Value = append(candles.Value, candle)
}

retValue := make(map[string]objects.Object, 4)

This comment has been minimized.

Copy link
@shazbert

shazbert Mar 30, 2020

Collaborator

bump?

Copy link
Collaborator

gloriousCode left a comment

Tested and everything matches real data 🦀 more tiny nits :D but I'm thinking this is all good to go

return 4, nil
case "vol":
return 5, nil
default:

This comment has been minimized.

Copy link
@gloriousCode

gloriousCode Mar 30, 2020

Collaborator

All these default cases could be tested to increase coverage and handling

}

var ret []float64
if validator.IsTestExecution.Load() != true {

This comment has been minimized.

Copy link
@gloriousCode

gloriousCode Mar 30, 2020

Collaborator

Really small nit, I think these could be changed around across indicators to reduce nesting of the expected path and exit sooner

	r := &objects.Array{}
	if validator.IsTestExecution.Load() == true {
		return r, nil
	}
	ret = indicators.Ma(ohlcvClose, inTimePeriod, indicators.EMA)
@xtda xtda added reconstructing and removed review me labels Mar 31, 2020
… pass errors back
@xtda xtda added review me and removed reconstructing labels Mar 31, 2020
Copy link
Collaborator

shazbert left a comment

tACK - All works! 💃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.