gocryptotrader icon indicating copy to clipboard operation
gocryptotrader copied to clipboard

backtester: custom strategy plugins

Open gloriousCode opened this issue 2 years ago • 1 comments

image

PR Description

This PR allows for a user to build custom strategies that are not part of the main codebase. This PR uses Golang plugins which you can read about here. They do not work on Windows, however, they do work on WSL, Linux and macOS, so I consider them usable on all platforms.

I've documented what's required for these to work here

tl;dr how do?

For a quick testing run, do the following:

  • navigate to /backtester/plugins/strategies/example/ and run go build -buildmode=plugin
  • navigate to /backtester and run go build
  • run ./backtester --strategypluginpath="/backtester/plugins/strategies/example/example.so" --configpath=/backtester/config/examples/custom-plugin-strategy.strat"

Type of change

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

How has this been tested

  • [x] go test ./... -race
  • [x] golangci-lint run
  • [x] Running the custom strategy

Checklist

  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [x] I have made corresponding changes to the documentation and regenerated documentation via the documentation tool
  • [x] My changes generate no new warnings
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [x] New and existing unit tests pass locally and on Github Actions/AppVeyor with my changes
  • [x] Any dependent changes have been merged and published in downstream modules

gloriousCode avatar Jul 01 '22 04:07 gloriousCode

I had the thought last night that in combination with this PR and the Backtester becoming a long-living application, it would be better to load multiple custom strategies at once. So I've updated it to take in a slice instead 🎉

gloriousCode avatar Jul 22 '22 02:07 gloriousCode