data

package
v0.0.0-...-068a453 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 12 Imported by: 23

README

GoCryptoTrader Backtester: Data package

Build Status Software License GoDoc Coverage Status Go Report Card

This data 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

Data package overview

The data package defines and implements a base version of the Streamer interface which is part of the Handler interface. These interfaces allow for the translation of data into individual intervals to be accessed and assessed as part of the backtest package. This is a base implementation, the more proper implementation that is used throughout the backtester is under ./kline

This can also be used to implement other means to load data for the backtester to process, however kline is currently the only supported method.

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 (
	// ErrHandlerNotFound returned when a handler is not found for specified exchange, asset, pair
	ErrHandlerNotFound = errors.New("handler not found")
	// ErrInvalidEventSupplied returned when a bad event is supplied
	ErrInvalidEventSupplied = errors.New("invalid event supplied")
	// ErrEmptySlice is returned when the supplied slice is nil or empty
	ErrEmptySlice = errors.New("empty slice")
	// ErrEndOfData is returned when attempting to load the next offset when there is no more
	ErrEndOfData = errors.New("no more data to retrieve")
)

Functions

This section is empty.

Types

type Base

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

Base is the base implementation of some interface functions where further specific functions are implemented in DataFromKline

func (*Base) AppendStream

func (b *Base) AppendStream(s ...Event) error

AppendStream appends new datas onto the stream, however, will not add duplicates. Used for live analysis

func (*Base) GetDetails

func (b *Base) GetDetails() (string, asset.Item, currency.Pair, error)

GetDetails returns data about the Base Holder

func (*Base) GetStream

func (b *Base) GetStream() (Events, error)

GetStream will return entire Data list

func (*Base) History

func (b *Base) History() (Events, error)

History will return all previous Data events that have happened

func (*Base) IsLastEvent

func (b *Base) IsLastEvent() (bool, error)

IsLastEvent determines whether the latest event is the last event for live Data, this will be false, as all appended Data is the latest available Data and this signal cannot be completely relied upon

func (*Base) IsLive

func (b *Base) IsLive() (bool, error)

IsLive returns if the Data source is a live one less scrutiny on checks is required on live Data sourcing

func (*Base) Latest

func (b *Base) Latest() (Event, error)

Latest will return latest Data event

func (*Base) List

func (b *Base) List() (Events, error)

List returns all future Data events from the current iteration ill-advised to use this in strategies because you don't know the future in real life

func (*Base) Next

func (b *Base) Next() (Event, error)

Next will return the next event in the list and also shift the offset one

func (*Base) Offset

func (b *Base) Offset() (int64, error)

Offset returns the current iteration of candle Data the backtester is assessing

func (*Base) Reset

func (b *Base) Reset() error

Reset loaded Data to blank state

func (*Base) SetLive

func (b *Base) SetLive(isLive bool) error

SetLive sets if the Data source is a live one less scrutiny on checks is required on live Data sourcing

func (*Base) SetStream

func (b *Base) SetStream(s []Event) error

SetStream sets the Data stream for candle analysis

type Event

type Event interface {
	common.Event
	GetUnderlyingPair() currency.Pair
	GetClosePrice() decimal.Decimal
	GetHighPrice() decimal.Decimal
	GetLowPrice() decimal.Decimal
	GetOpenPrice() decimal.Decimal
	GetVolume() decimal.Decimal
}

Event interface used for loading and interacting with Data

type Events

type Events []Event

Events allows for some common functions on a slice of events

func (Events) First

func (e Events) First() (Event, error)

First returns the first element of a slice

func (Events) Last

func (e Events) Last() (Event, error)

Last returns the last element of a slice

type Handler

type Handler interface {
	Loader
	Streamer
	GetDetails() (string, asset.Item, currency.Pair, error)
	Reset() error
}

Handler interface for Loading and Streaming Data

type HandlerHolder

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

HandlerHolder stores an event handler per exchange asset pair

func NewHandlerHolder

func NewHandlerHolder() *HandlerHolder

NewHandlerHolder returns a new HandlerHolder

func (*HandlerHolder) GetAllData

func (h *HandlerHolder) GetAllData() ([]Handler, error)

GetAllData returns all set Data in the Data map

func (*HandlerHolder) GetDataForCurrency

func (h *HandlerHolder) GetDataForCurrency(ev common.Event) (Handler, error)

GetDataForCurrency returns the Handler for a specific exchange, asset, currency

func (*HandlerHolder) Reset

func (h *HandlerHolder) Reset() error

Reset returns the struct to defaults

func (*HandlerHolder) SetDataForCurrency

func (h *HandlerHolder) SetDataForCurrency(e string, a asset.Item, p currency.Pair, k Handler) error

SetDataForCurrency assigns a Data Handler to the Data map by exchange, asset and currency

type Holder

type Holder interface {
	SetDataForCurrency(string, asset.Item, currency.Pair, Handler) error
	GetAllData() ([]Handler, error)
	GetDataForCurrency(ev common.Event) (Handler, error)
	Reset() error
}

Holder interface dictates what a Data holder is expected to do

type Loader

type Loader interface {
	Load() error
	AppendStream(s ...Event) error
}

Loader interface for Loading Data into backtest supported format

type Streamer

type Streamer interface {
	Next() (Event, error)
	GetStream() (Events, error)
	History() (Events, error)
	Latest() (Event, error)
	List() (Events, error)
	IsLastEvent() (bool, error)
	Offset() (int64, error)

	StreamOpen() ([]decimal.Decimal, error)
	StreamHigh() ([]decimal.Decimal, error)
	StreamLow() ([]decimal.Decimal, error)
	StreamClose() ([]decimal.Decimal, error)
	StreamVol() ([]decimal.Decimal, error)

	HasDataAtTime(time.Time) (bool, error)
}

Streamer interface handles loading, parsing, distributing BackTest Data

Directories

Path Synopsis
api
csv

Jump to

Keyboard shortcuts

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