Documentation ¶
Index ¶
- Variables
- func StartRPCServer(server *GRPCServer) error
- type BackTest
- func (bt *BackTest) CloseAllPositions() error
- func (bt *BackTest) Equal(bt2 *BackTest) bool
- func (bt *BackTest) ExecuteStrategy(waitForOfflineCompletion bool) error
- func (bt *BackTest) GenerateSummary() (*TaskSummary, error)
- func (bt *BackTest) HasRan() bool
- func (bt *BackTest) IsRunning() bool
- func (bt *BackTest) MatchesID(id uuid.UUID) bool
- func (bt *BackTest) Reset() error
- func (bt *BackTest) Run() error
- func (bt *BackTest) RunLive() error
- func (bt *BackTest) SetupFromConfig(cfg *config.Config, templatePath, output string, verbose bool) error
- func (bt *BackTest) SetupLiveDataHandler(eventTimeout, dataCheckInterval time.Duration, realOrders, verbose bool) error
- func (bt *BackTest) SetupMetaData() error
- func (bt *BackTest) Stop() error
- type GRPCServer
- func (s *GRPCServer) ClearAllTasks(_ context.Context, _ *btrpc.ClearAllTasksRequest) (*btrpc.ClearAllTasksResponse, error)
- func (s *GRPCServer) ClearTask(_ context.Context, req *btrpc.ClearTaskRequest) (*btrpc.ClearTaskResponse, error)
- func (s *GRPCServer) ExecuteStrategyFromConfig(_ context.Context, request *btrpc.ExecuteStrategyFromConfigRequest) (*btrpc.ExecuteStrategyResponse, error)
- func (s *GRPCServer) ExecuteStrategyFromFile(_ context.Context, request *btrpc.ExecuteStrategyFromFileRequest) (*btrpc.ExecuteStrategyResponse, error)
- func (s *GRPCServer) ListAllTasks(_ context.Context, _ *btrpc.ListAllTasksRequest) (*btrpc.ListAllTasksResponse, error)
- func (s *GRPCServer) StartAllTasks(_ context.Context, _ *btrpc.StartAllTasksRequest) (*btrpc.StartAllTasksResponse, error)
- func (s *GRPCServer) StartRPCRESTProxy() error
- func (s *GRPCServer) StartTask(_ context.Context, req *btrpc.StartTaskRequest) (*btrpc.StartTaskResponse, error)
- func (s *GRPCServer) StopAllTasks(_ context.Context, _ *btrpc.StopAllTasksRequest) (*btrpc.StopAllTasksResponse, error)
- func (s *GRPCServer) StopTask(_ context.Context, req *btrpc.StopTaskRequest) (*btrpc.StopTaskResponse, error)
- type Handler
- type TaskManager
- func (r *TaskManager) AddTask(b *BackTest) error
- func (r *TaskManager) ClearAllTasks() (clearedRuns, remainingRuns []*TaskSummary, err error)
- func (r *TaskManager) ClearTask(id uuid.UUID) error
- func (r *TaskManager) GetSummary(id uuid.UUID) (*TaskSummary, error)
- func (r *TaskManager) List() ([]*TaskSummary, error)
- func (r *TaskManager) StartAllTasks() ([]uuid.UUID, error)
- func (r *TaskManager) StartTask(id uuid.UUID) error
- func (r *TaskManager) StopAllTasks() ([]*TaskSummary, error)
- func (r *TaskManager) StopTask(id uuid.UUID) error
- type TaskMetaData
- type TaskSummary
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
CloseAllPositions will close sell any positions held on closure can only be with live testing and where a strategy supports it
func (*BackTest) ExecuteStrategy ¶
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) Run ¶
Run will iterate over loaded data events save them and then handle the event based on its type
func (*BackTest) RunLive ¶
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 ¶
SetupMetaData will populate metadata fields
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 ¶
func (s *GRPCServer) ClearAllTasks(_ context.Context, _ *btrpc.ClearAllTasksRequest) (*btrpc.ClearAllTasksResponse, error)
ClearAllTasks removes all tasks from memory, but only if they are not running
func (*GRPCServer) ClearTask ¶
func (s *GRPCServer) ClearTask(_ context.Context, req *btrpc.ClearTaskRequest) (*btrpc.ClearTaskResponse, error)
ClearTask removes a task from memory, but only if it is not running
func (*GRPCServer) ExecuteStrategyFromConfig ¶
func (s *GRPCServer) ExecuteStrategyFromConfig(_ context.Context, request *btrpc.ExecuteStrategyFromConfigRequest) (*btrpc.ExecuteStrategyResponse, error)
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 ¶
func (s *GRPCServer) ExecuteStrategyFromFile(_ context.Context, request *btrpc.ExecuteStrategyFromFileRequest) (*btrpc.ExecuteStrategyResponse, error)
ExecuteStrategyFromFile will backtest a strategy from the filepath provided
func (*GRPCServer) ListAllTasks ¶
func (s *GRPCServer) ListAllTasks(_ context.Context, _ *btrpc.ListAllTasksRequest) (*btrpc.ListAllTasksResponse, error)
ListAllTasks returns all strategy tasks managed by the server
func (*GRPCServer) StartAllTasks ¶
func (s *GRPCServer) StartAllTasks(_ context.Context, _ *btrpc.StartAllTasksRequest) (*btrpc.StartAllTasksResponse, error)
StartAllTasks starts all strategy tasks
func (*GRPCServer) StartRPCRESTProxy ¶
func (s *GRPCServer) StartRPCRESTProxy() error
StartRPCRESTProxy starts a gRPC proxy
func (*GRPCServer) StartTask ¶
func (s *GRPCServer) StartTask(_ context.Context, req *btrpc.StartTaskRequest) (*btrpc.StartTaskResponse, error)
StartTask starts a strategy that was set to not start automatically
func (*GRPCServer) StopAllTasks ¶
func (s *GRPCServer) StopAllTasks(_ context.Context, _ *btrpc.StopAllTasksRequest) (*btrpc.StopAllTasksResponse, error)
StopAllTasks stops all strategy tasks in its tracks
func (*GRPCServer) StopTask ¶
func (s *GRPCServer) StopTask(_ context.Context, req *btrpc.StopTaskRequest) (*btrpc.StopTaskResponse, error)
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
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