common

package
v0.0.0-...-afb6f75 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 12 Imported by: 74

README

GoCryptoTrader Backtester: Common package

Build Status Software License GoDoc Coverage Status Go Report Card

This common 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 this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

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

Common package overview

Common contains some basic data types which are used throughout.

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

View Source
const (
	// CandleStr is a config readable data type to tell the backtester to retrieve candle data
	CandleStr = "candle"
	// TradeStr is a config readable data type to tell the backtester to retrieve trade data
	TradeStr = "trade"

	// DataCandle is an int64 representation of a candle data type
	DataCandle int64 = iota
	// DataTrade is an int64 representation of a trade data type
	DataTrade
)
View Source

ASCIILogo is a sweet logo that is optionally printed to the command line window

Variables

View Source
var (
	// ErrNilEvent is a common error for whenever a nil event occurs when it shouldn't have
	ErrNilEvent = errors.New("nil event received")
	// ErrInvalidDataType occurs when an invalid data type is defined in the config
	ErrInvalidDataType = errors.New("invalid datatype received")
	// ErrFileNotFound returned when the file is not found
	ErrFileNotFound = errors.New("file not found")
)
View Source
var (
	Backtester         *log.SubLogger
	LiveStrategy       *log.SubLogger
	Setup              *log.SubLogger
	Strategy           *log.SubLogger
	Config             *log.SubLogger
	Portfolio          *log.SubLogger
	Exchange           *log.SubLogger
	Fill               *log.SubLogger
	Report             *log.SubLogger
	Statistics         *log.SubLogger
	CurrencyStatistics *log.SubLogger
	FundingStatistics  *log.SubLogger
	Holdings           *log.SubLogger
	Data               *log.SubLogger
	FundManager        *log.SubLogger
)

custom subloggers for backtester use

View Source
var CMDColours = Colours{
	Default:  "\u001b[0m",
	Green:    "\033[38;5;157m",
	White:    "\033[38;5;255m",
	Grey:     "\033[38;5;240m",
	DarkGrey: "\033[38;5;243m",
	H1:       "\033[38;5;33m",
	H2:       "\033[38;5;39m",
	H3:       "\033[38;5;45m",
	H4:       "\033[38;5;51m",
	Success:  "\033[38;5;40m",
	Info:     "\u001B[32m",
	Debug:    "\u001B[34m",
	Warn:     "\u001B[33m",
	Error:    "\033[38;5;196m",
}

CMDColours holds colour information for CMD output

Functions

func CanTransact

func CanTransact(side gctorder.Side) bool

CanTransact checks whether an order side is valid to the backtester's standards

func DataTypeToInt

func DataTypeToInt(dataType string) (int64, error)

DataTypeToInt converts the config string value into an int

func FitStringToLimit

func FitStringToLimit(str, spacer string, limit int, upper bool) string

FitStringToLimit ensures a string is of the length of the limit either by truncating the string with ellipses or padding with the spacer

func GenerateFileName

func GenerateFileName(fileName, extension string) (string, error)

GenerateFileName will convert a proposed filename into something that is more OS friendly

func Logo() string

Logo returns the logo

func PurgeColours

func PurgeColours()

PurgeColours removes colour information

func RegisterBacktesterSubLoggers

func RegisterBacktesterSubLoggers() error

RegisterBacktesterSubLoggers sets up all custom Backtester sub-loggers

func SetColours

func SetColours(colours *Colours)

SetColours sets cmd output colours at startup. Doing it at any other point risks races and this really isn't worth adding a mutex for

Types

type Colours

type Colours struct {
	Default  string
	Green    string
	White    string
	Grey     string
	DarkGrey string
	H1       string
	H2       string
	H3       string
	H4       string
	Success  string
	Info     string
	Debug    string
	Warn     string
	Error    string
}

Colours defines colour types for CMD output

type Directioner

type Directioner interface {
	SetDirection(side order.Side)
	GetDirection() order.Side
}

Directioner dictates the side of an order

type Event

type Event interface {
	GetBase() *event.Base
	GetOffset() int64
	SetOffset(int64)
	IsEvent() bool
	GetTime() time.Time
	Pair() currency.Pair
	GetUnderlyingPair() currency.Pair
	GetExchange() string
	GetInterval() kline.Interval
	GetAssetType() asset.Item
	GetConcatReasons() string
	GetReasons() []string
	GetClosePrice() decimal.Decimal
	AppendReason(string)
	AppendReasonf(string, ...interface{})
}

Event interface implements required GetTime() & Pair() return

Jump to

Keyboard shortcuts

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