period

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: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPeriod is returned when the period is invalid.
	ErrInvalidPeriod = errors.New("invalid period")
)

Functions

This section is empty.

Types

type Symbol

type Symbol string

Symbol is a period symbol.

const (
	// M1 is a period of 1 minute.
	M1 Symbol = "M1"
	// M3 is a period of 3 minutes.
	M3 Symbol = "M3"
	// M5 is a period of 5 minutes.
	M5 Symbol = "M5"
	// M15 is a period of 15 minutes.
	M15 Symbol = "M15"
	// M30 is a period of 30 minutes.
	M30 Symbol = "M30"
	// H1 is a period of 1 hour.
	H1 Symbol = "H1"
	// H2 is a period of 2 hours.
	H2 Symbol = "H2"
	// H4 is a period of 4 hours.
	H4 Symbol = "H4"
	// H6 is a period of 6 hours.
	H6 Symbol = "H6"
	// H8 is a period of 8 hours.
	H8 Symbol = "H8"
	// H12 is a period of 12 hours.
	H12 Symbol = "H12"
	// D1 is a period of 1 day.
	D1 Symbol = "D1"
	// D3 is a period of 3 days.
	D3 Symbol = "D3"
	// W1 is a period of 1 week.
	W1 Symbol = "W1"
)

func FromDuration

func FromDuration(d time.Duration) (Symbol, error)

FromDuration converts a duration into its corresponding symbol.

func FromSeconds

func FromSeconds(i int64) (Symbol, error)

FromSeconds returns a period from seconds.

func FromString

func FromString(symbol string) (Symbol, error)

FromString converts a string in a symbol and checks if it's valid.

func Symbols

func Symbols() []Symbol

Symbols returns all the available periods.

func UniqueArray

func UniqueArray(sym1, sym2 []Symbol) []Symbol

UniqueArray returns a unique array of symbols.

func (Symbol) CountBetweenTimes

func (s Symbol) CountBetweenTimes(t1, t2 time.Time) int64

CountBetweenTimes returns the number of candlesticks between times.

func (Symbol) Duration

func (s Symbol) Duration() time.Duration

Duration converts a symbol into its corresponding duration.

func (Symbol) IsAligned

func (s Symbol) IsAligned(t time.Time) bool

IsAligned checks if the given time is aligned with the period.

func (Symbol) Opt

func (s Symbol) Opt() *Symbol

Opt returns a pointer to the symbol.

func (Symbol) RoundInterval

func (s Symbol) RoundInterval(start, end *time.Time) (time.Time, time.Time)

RoundInterval takes an interval (represented by start, end) and returns the closest time before or equal to 'start' corresponding to the period and the closest time after or equal to 'end' corresponding to the period.

Example: if M1 then 1:30 to 2:30 will become 1:00 to 3:00.

func (Symbol) RoundTime

func (s Symbol) RoundTime(t time.Time) time.Time

RoundTime rounds the given time to the closest period.

func (Symbol) String

func (s Symbol) String() string

String returns the string representation of the symbol.

func (Symbol) Validate

func (s Symbol) Validate() error

Validate checks the symbol is a valid period.

Jump to

Keyboard shortcuts

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