engine

package
v0.0.0-...-a0d82f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 64 Imported by: 0

README

GoCryptoTrader Backtester: Engine package

Build Status Software License GoDoc Coverage Status Go Report Card

This engine package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progress on our GoCryptoTrader Kanban board.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

Engine package overview

The engine package is the most important package of the GoCryptoTrader backtester. It is the engine which combines all elements. It is responsible for the following functionality

  • Loading settings from a provided config file
  • Retrieving data
  • Loading the data into assessable chunks
  • Analysing the data via the handleEvent function
  • Looping through all data
  • Outputting results into a report

A flow of the application is as follows: workflow

Please click GoDocs chevron above to view current GoDoc information for this package

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLiveDataTimeout returns when an event has not been processed within the timeframe
	ErrLiveDataTimeout = errors.New("no data processed within timeframe")
)

Functions

func StartRPCServer

func StartRPCServer(server *GRPCServer) error

StartRPCServer starts a gRPC server with TLS auth

Types

type BackTest

type BackTest struct {
	MetaData        TaskMetaData
	DataHolder      data.Holder
	LiveDataHandler Handler
	Strategy        strategies.Handler
	Portfolio       portfolio.Handler
	Exchange        exchange.ExecutionHandler
	Statistic       statistics.Handler
	EventQueue      eventholder.EventHolder
	Reports         report.Handler
	Funding         funding.IFundingManager
	// contains filtered or unexported fields
}

BackTest is the main holder of all backtesting functionality

func NewBacktester

func NewBacktester() (*BackTest, error)

NewBacktester returns a new BackTest instance

func NewBacktesterFromConfigs

func NewBacktesterFromConfigs(strategyCfg *config.Config, backtesterCfg *config.BacktesterConfig) (*BackTest, error)

NewBacktesterFromConfigs creates a new backtester based on config settings

func (*BackTest) CloseAllPositions

func (bt *BackTest) CloseAllPositions() error

CloseAllPositions will close sell any positions held on closure can only be with live testing and where a strategy supports it

func (*BackTest) Equal

func (bt *BackTest) Equal(bt2 *BackTest) bool

Equal checks if the incoming task matches

func (*BackTest) ExecuteStrategy

func (bt *BackTest) ExecuteStrategy(waitForOfflineCompletion bool) error

ExecuteStrategy executes the strategy using the provided configs

func (*BackTest) GenerateSummary

func (bt *BackTest) GenerateSummary() (*TaskSummary, error)

GenerateSummary creates a summary of a strategy task this summary contains many details of a task

func (*BackTest) HasRan

func (bt *BackTest) HasRan() bool

HasRan checks if the task has been executed

func (*BackTest) IsRunning

func (bt *BackTest) IsRunning() bool

IsRunning checks if the task is running

func (*BackTest) MatchesID

func (bt *BackTest) MatchesID(id uuid.UUID) bool

MatchesID checks if the backtesting run's ID matches the supplied

func (*BackTest) Reset

func (bt *BackTest) Reset() error

Reset BackTest values to default

func (*BackTest) Run

func (bt *BackTest) Run() error

Run will iterate over loaded data events save them and then handle the event based on its type

func (*BackTest) RunLive

func (bt *BackTest) RunLive() error

RunLive is a proof of concept function that does not yet support multi currency usage It tasks by constantly checking for new live datas and running through the list of events once new data is processed. It will run until application close event has been received

func (*BackTest) SetupFromConfig

func (bt *BackTest) SetupFromConfig(cfg *config.Config, templatePath, output string, verbose bool) error

SetupFromConfig takes a strategy config and configures a backtester variable to run

func (*BackTest) SetupLiveDataHandler

func (bt *BackTest) SetupLiveDataHandler(eventTimeout, dataCheckInterval time.Duration, realOrders, verbose bool) error

SetupLiveDataHandler creates a live data handler to retrieve and append live data as it comes in

func (*BackTest) SetupMetaData

func (bt *BackTest) SetupMetaData() error

SetupMetaData will populate metadata fields

func (*BackTest) Stop

func (bt *BackTest) Stop() error

Stop shuts down the live data loop

type GRPCServer

type GRPCServer struct {
	btrpc.BacktesterServiceServer
	// contains filtered or unexported fields
}

GRPCServer struct

func SetupRPCServer

func SetupRPCServer(cfg *config.BacktesterConfig, manager *TaskManager) (*GRPCServer, error)

SetupRPCServer sets up the gRPC server

func (*GRPCServer) ClearAllTasks

ClearAllTasks removes all tasks from memory, but only if they are not running

func (*GRPCServer) ClearTask

ClearTask removes a task from memory, but only if it is not running

func (*GRPCServer) ExecuteStrategyFromConfig

ExecuteStrategyFromConfig will backtest a strategy config built from a GRPC command this should be a preferred method of interacting with backtester, as it allows for very quick minor tweaks to strategy to determine the best result - SO LONG AS YOU DONT OVERFIT

func (*GRPCServer) ExecuteStrategyFromFile

ExecuteStrategyFromFile will backtest a strategy from the filepath provided

func (*GRPCServer) ListAllTasks

ListAllTasks returns all strategy tasks managed by the server

func (*GRPCServer) StartAllTasks

StartAllTasks starts all strategy tasks

func (*GRPCServer) StartRPCRESTProxy

func (s *GRPCServer) StartRPCRESTProxy() error

StartRPCRESTProxy starts a gRPC proxy

func (*GRPCServer) StartTask

StartTask starts a strategy that was set to not start automatically

func (*GRPCServer) StopAllTasks

StopAllTasks stops all strategy tasks in its tracks

func (*GRPCServer) StopTask

StopTask stops a strategy task in its tracks

type Handler

type Handler interface {
	AppendDataSource(*liveDataSourceSetup) error
	FetchLatestData() (bool, error)
	Start() error
	IsRunning() bool
	DataFetcher() error
	Stop() error
	Reset() error
	Updated() chan bool
	HasShutdown() chan bool
	HasShutdownFromError() chan bool
	SetDataForClosingAllPositions(events ...signal.Event) error
	UpdateFunding(force bool) error
	IsRealOrders() bool
}

Handler is all the functionality required in order to run a backtester with live data

type TaskManager

type TaskManager struct {
	// contains filtered or unexported fields
}

TaskManager contains all strategy tasks

func NewTaskManager

func NewTaskManager() *TaskManager

NewTaskManager creates a run manager to allow the backtester to manage multiple strategies

func (*TaskManager) AddTask

func (r *TaskManager) AddTask(b *BackTest) error

AddTask adds a run to the manager

func (*TaskManager) ClearAllTasks

func (r *TaskManager) ClearAllTasks() (clearedRuns, remainingRuns []*TaskSummary, err error)

ClearAllTasks removes all tasks from memory, but only if they are not running

func (*TaskManager) ClearTask

func (r *TaskManager) ClearTask(id uuid.UUID) error

ClearTask removes a run from memory, but only if it is not running

func (*TaskManager) GetSummary

func (r *TaskManager) GetSummary(id uuid.UUID) (*TaskSummary, error)

GetSummary returns details about a completed strategy task

func (*TaskManager) List

func (r *TaskManager) List() ([]*TaskSummary, error)

List details all strategy tasks

func (*TaskManager) StartAllTasks

func (r *TaskManager) StartAllTasks() ([]uuid.UUID, error)

StartAllTasks executes all strategies

func (*TaskManager) StartTask

func (r *TaskManager) StartTask(id uuid.UUID) error

StartTask executes a strategy if found

func (*TaskManager) StopAllTasks

func (r *TaskManager) StopAllTasks() ([]*TaskSummary, error)

StopAllTasks stops all running strategies

func (*TaskManager) StopTask

func (r *TaskManager) StopTask(id uuid.UUID) error

StopTask stops a strategy task if enabled, this will run CloseAllPositions

type TaskMetaData

type TaskMetaData struct {
	ID                   uuid.UUID
	Strategy             string
	DateLoaded           time.Time
	DateStarted          time.Time
	DateEnded            time.Time
	Closed               bool
	ClosePositionsOnStop bool
	LiveTesting          bool
	RealOrders           bool
}

TaskMetaData contains details about a run such as when it was loaded

type TaskSummary

type TaskSummary struct {
	MetaData TaskMetaData
}

TaskSummary holds details of a BackTest rather than passing entire contents around

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL