chartype

package module
v0.0.0-...-005f493 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package chartype provides types and functions for convenient work with market data structures.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidCandleField is returned when candle field
	// with invalid value is being used.
	ErrInvalidCandleField = errors.New("invalid candle field")
)
View Source
var (
	// ErrInvalidTickerField is returned when ticker field
	// with invalid value is being used.
	ErrInvalidTickerField = errors.New("invalid ticker field")
)

Functions

func FromCandles

func FromCandles(cc []Candle, cf CandleField) []decimal.Decimal

FromCandles extracts specific candle fields from all provided candles and puts them in plain number slice.

Types

type Candle

type Candle struct {
	Timestamp time.Time       `json:"timestamp" db:"timestamp"`
	Open      decimal.Decimal `json:"open" db:"open"`
	High      decimal.Decimal `json:"high" db:"high"`
	Low       decimal.Decimal `json:"low" db:"low"`
	Close     decimal.Decimal `json:"close" db:"close"`
	Volume    decimal.Decimal `json:"volume" db:"volume"`
}

Candle stores specific timeframe's starting, closing, highest and lowest price points.

func ParseCandle

func ParseCandle(t time.Time, os, hs, ls, cs, vs string) (Candle, error)

ParseCandle parses provided string parameters into newly created candle's fields and returns it.

type CandleField

type CandleField int

CandleField specifies which field should be extracted from the candle for further calculations. Can be included in configuration structures.

const (
	// CandleOpen specifies starting candle's value.
	CandleOpen CandleField = iota + 1

	// CandleHigh specifies highest candle's value.
	CandleHigh

	// CandleLow specifies lowest candle's value.
	CandleLow

	// CandleClose specifies last candle's value.
	CandleClose

	// CandleVolume specifies candle's volume value.
	CandleVolume
)

func (CandleField) Extract

func (cf CandleField) Extract(c Candle) decimal.Decimal

Extract returns candle's value as specified in the candle field type.

func (CandleField) MarshalText

func (cf CandleField) MarshalText() ([]byte, error)

MarshalText turns candle field to appropriate string representation.

func (*CandleField) UnmarshalText

func (cf *CandleField) UnmarshalText(d []byte) error

UnmarshalText turns string to appropriate candle field value.

func (CandleField) Validate

func (cf CandleField) Validate() error

Validate checks whether the candle field is one of supported field types or not.

type Packet

type Packet struct {
	Ticker  Ticker   `json:"ticker"`
	Candles []Candle `json:"candles"`
}

Packet holds ticker information as well as all known candles for a specific timeframe.

type Ticker

type Ticker struct {
	Last          decimal.Decimal `json:"last"`
	Ask           decimal.Decimal `json:"ask"`
	Bid           decimal.Decimal `json:"bid"`
	Change        decimal.Decimal `json:"change"`
	PercentChange decimal.Decimal `json:"percent_change"`
	Volume        decimal.Decimal `json:"volume"`
}

Ticker holds current ask, last and bid prices.

func ParseTicker

func ParseTicker(ls, as, bs, cs, pcs, vs string) (Ticker, error)

ParseTicker parses provided string parameters into decimal type values, adds them into a new ticker instance and returns it.

type TickerField

type TickerField int

TickerField specifies which field should be extracted from the ticker for further calculations. Can be included in configuration structures.

const (
	// TickerLast specifies last ticker value.
	TickerLast TickerField = iota + 1

	// TickerAsk specifies ask ticker value.
	TickerAsk

	// TickerBid specifies bid ticker value.
	TickerBid

	// TickerChange specifies 24 hours price units change in
	// last ticker price.
	TickerChange

	// TickerPercentChange specifies 24 hour price percent change in
	// last ticker price.
	TickerPercentChange

	// TickerVolume specifies volume ticker value.
	TickerVolume
)

func (TickerField) Extract

func (tf TickerField) Extract(t Ticker) decimal.Decimal

Extract returns ticker's value as specified in the ticker field type.

func (TickerField) MarshalText

func (tf TickerField) MarshalText() ([]byte, error)

MarshalText turns ticker field to appropriate string representation.

func (*TickerField) UnmarshalText

func (tf *TickerField) UnmarshalText(d []byte) error

UnmarshalText turns string to appropriate ticker field value.

func (TickerField) Validate

func (tf TickerField) Validate() error

Validate checks whether the ticker field is one of supported field types or not.

Jump to

Keyboard shortcuts

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