candlestick

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: GPL-3.0 Imports: 5 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPeriodMismatch is returned when the period of the candlestick does not
	// match the period of the list.
	ErrPeriodMismatch = errors.New("period-mismatch")
	// ErrCandlestickType is returned when the struct is not a candlestick.
	ErrCandlestickType = errors.New("struct-not-candlestick")
	// ErrExchangeMismatch is returned when the exchange of the list does not
	// match the exchange of the list to merge.
	ErrExchangeMismatch = errors.New("exchange-mismatch")
	// ErrPairMismatch is returned when the pair of the list does not match the
	// pair of the list to merge.
	ErrPairMismatch = errors.New("pair-mismatch")
)
View Source
var (
	// ErrInvalidPriceType is returned when the price type is invalid.
	ErrInvalidPriceType = errors.New("invalid-price-type")
)

PriceTypes is the list of all available price types.

Functions

This section is empty.

Types

type Candlestick

type Candlestick struct {
	Time       time.Time `bson:"time"    json:"time,omitempty"`
	Open       float64   `bson:"open"     json:"open,omitempty"`
	High       float64   `bson:"high"     json:"high,omitempty"`
	Low        float64   `bson:"low"      json:"low,omitempty"`
	Close      float64   `bson:"close"    json:"close,omitempty"`
	Volume     float64   `bson:"volume"   json:"volume,omitempty"`
	Uncomplete bool      `bson:"uncomplete" json:"uncomplete,omitempty"`
}

Candlestick is a candlestick with the time, open, high, low, close and volume. Uncomplete is true if the candlestick is not closed yet or have not been updated since it was closed.

func MergeListIntoOneCandlestick

func MergeListIntoOneCandlestick(csl *List, per period.Symbol) (time.Time, Candlestick)

MergeListIntoOneCandlestick will merge all the candlesticks of the list into one candlestick. The time of the candlestick will be the first time of the list, rounded to the period. The high will be the highest high, the low the lowest low, the volume the sum of all volumes and the close the close of the last candlestick.

func (Candlestick) Equal

func (cs Candlestick) Equal(b Candlestick) bool

Equal checks equality between the candlesticks.

func (Candlestick) Price

func (cs Candlestick) Price(p PriceType) float64

Price is the price of the candlestick depending on the price type.

func (Candlestick) String

func (cs Candlestick) String() string

String is a string representation of the candlestick.

type List

type List struct {
	Metadata ListMetadata
	Data     timeseries.TimeSerie[Candlestick]
}

List is a list of candlesticks with some metadata.

func NewList

func NewList(exchange, pair string, period period.Symbol) *List

NewList creates a new list of candlesticks with the given metadata.

func NewListWithMetadata

func NewListWithMetadata(md ListMetadata) *List

NewListWithMetadata creates a new list of candlesticks with the same metadata as the given list.

func (List) Extract

func (l List) Extract(start, end time.Time, limit uint) *List

Extract will extract a new list from the current list with the given time range and limit.

func (*List) FillMissing

func (l *List) FillMissing(start, end time.Time, filling Candlestick) error

FillMissing will add the 'filling' candlestick at each interval between 'start' included and 'end' included when there is a missing candlestick at the tested interval.

func (List) First

func (l List) First() (Candlestick, bool)

First will return the first candlestick of the list.

func (List) GetMissingRange

func (l List) GetMissingRange(start, end time.Time, limit uint) []timeseries.TimeRange

GetMissingRange returns an array of missing time range in the candlestick list.

func (List) GetMissingTimes

func (l List) GetMissingTimes(start, end time.Time, limit uint) []time.Time

GetMissingTimes returns an array of missing time in the candlestick list.

func (List) GetUncompleteRange

func (l List) GetUncompleteRange() []timeseries.TimeRange

GetUncompleteRange returns an array of time range from candlesticks that are marked as uncomplete (i.e. data pulled when candlestick covering time was not complete).

func (List) GetUncompleteTimes

func (l List) GetUncompleteTimes() []time.Time

GetUncompleteTimes returns an array of time from candlesticks that are marked as uncomplete (i.e. data pulled when candlestick covering time was not complete).

func (List) Last

func (l List) Last() (Candlestick, bool)

Last will return the last candlestick of the list.

func (*List) Loop

func (l *List) Loop(f func(Candlestick) (bool, error)) error

Loop will loop over the candlesticks of the list and call the given function for each candlestick. If the function returns true, the loop will stop.

func (*List) Merge

func (l *List) Merge(l2 *List, options *timeseries.MergeOptions) error

Merge will merge the given list into the current list.

func (*List) MustSet

func (l *List) MustSet(c Candlestick) *List

MustSet will set the candlestick in the list and panic if there is an error.

func (*List) ReplaceUncomplete

func (l *List) ReplaceUncomplete(l2 *List)

ReplaceUncomplete will replace the uncomplete candlesticks of the current list with the candlesticks of the given list.

func (*List) Set

func (l *List) Set(c Candlestick) error

Set will set the candlestick in the list.

func (List) String

func (l List) String() string

String returns a string representation of the list.

func (List) ToArray

func (l List) ToArray() []Candlestick

ToArray returns an array of candlesticks from the list.

type ListMetadata

type ListMetadata struct {
	Exchange string
	Pair     string
	Period   period.Symbol
}

ListMetadata is the metadata of a list of candlesticks.

type PriceType

type PriceType string

PriceType is the type of price to use.

const (
	// PriceTypeIsOpen is the open price.
	PriceTypeIsOpen PriceType = "open"
	// PriceTypeIsHigh is the high price.
	PriceTypeIsHigh PriceType = "high"
	// PriceTypeIsLow is the low price.
	PriceTypeIsLow PriceType = "low"
	// PriceTypeIsClose is the close price.
	PriceTypeIsClose PriceType = "close"
)

func (PriceType) String

func (pt PriceType) String() string

String returns the string representation of the price type.

func (PriceType) Validate

func (pt PriceType) Validate() error

Validate checks if the price type is valid.

Jump to

Keyboard shortcuts

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