market

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package market provides an API to read and process market price data

Index

Constants

View Source
const MetaTraderTimeFormat = "02/01/2006 15:04"

MetaTraderTimeFormat is the time format expected by the MetaTrader decoder when cols [0] and [1] are used.

Variables

View Source
var (
	// ErrNotEnoughColumns is returned when the CSV price record does not have enough columns.
	ErrNotEnoughColumns = errors.New("not enough columns")

	// ErrInvalidTimeFormat is returned when the CSV price record does not have a valid time unix milli format.
	ErrInvalidTimeFormat = errors.New("cannot parse time string")

	// ErrInvalidPriceFormat is returned when the CSV price record does not prices in expected format.
	ErrInvalidPriceFormat = errors.New("OHLC prices must be in valid decimal format")

	// ErrInvalidVolumeFormat is returned when the CSV price record does not have a valid volume format.
	ErrInvalidVolumeFormat = errors.New("volume must be in valid float format")
)

Functions

This section is empty.

Types

type Asset

type Asset struct {
	Symbol string `csv:"symbol"`
}

Asset represents a tradeable asset identified by its symbol, e.g. BTCUSD.

func NewAsset

func NewAsset(symbol string) Asset

NewAsset creates a new Asset with the given symbol.

func (*Asset) Equal

func (a *Asset) Equal(other Asset) bool

Equal asserts equality based on the symbol.

type CSVKlineDecoder added in v0.0.18

type CSVKlineDecoder func(record []string) (Kline, error)

CSVKlineDecoder is an extension point for CSVKlineReader to support custom file formats.

type CSVKlineReader

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

CSVKlineReader is a KlineReader that reads from a CSV file.

func NewBinanceCSVKlineReader added in v0.0.18

func NewBinanceCSVKlineReader(csv *csv.Reader) *CSVKlineReader

NewBinanceCSVKlineReader creates a new CSVKlineReader for Binance CSV files.

func NewCSVKlineReader

func NewCSVKlineReader(csv *csv.Reader) *CSVKlineReader

NewCSVKlineReader creates a new CSVKlineReader with the default Binance decoder.

func NewCSVKlineReaderWithDecoder added in v0.0.18

func NewCSVKlineReaderWithDecoder(csv *csv.Reader, decoder CSVKlineDecoder) *CSVKlineReader

NewCSVKlineReaderWithDecoder creates a new CSVKlineReader with the given decoder.

func NewMetaTraderCSVKlineReader added in v0.0.18

func NewMetaTraderCSVKlineReader(csv *csv.Reader) *CSVKlineReader

NewMetaTraderCSVKlineReader creates a new CSVKlineReader for MetaTrader CSV files.

func (*CSVKlineReader) Read

func (r *CSVKlineReader) Read() (Kline, error)

Read reads the next Kline from the underlying CSV data.

func (*CSVKlineReader) ReadAll

func (r *CSVKlineReader) ReadAll() ([]Kline, error)

ReadAll reads all the Klines from the underlying CSV data.

type Kline

type Kline struct {
	Start  time.Time
	O      decimal.Decimal
	H      decimal.Decimal
	L      decimal.Decimal
	C      decimal.Decimal
	Volume float64
}

Kline represents a single candlestick.

func BinanceCSVKlineDecoder added in v0.0.18

func BinanceCSVKlineDecoder(record []string) (Kline, error)

BinanceCSVKlineDecoder decodes a CSV record from Binance into a Kline.

func MetaTraderCSVKlineDecoder added in v0.0.18

func MetaTraderCSVKlineDecoder(record []string) (Kline, error)

MetaTraderCSVKlineDecoder decodes a CSV record from MetaTrader into a Kline.

func ReadKlinesFromCSV

func ReadKlinesFromCSV(path string) ([]Kline, error)

ReadKlinesFromCSV reads all the .csv files in a given directory or a single file into a slice of Klines. Wraps a default CSVKlineReader with Binance decoder for convenience. For finer grained memory management use the base kline reader.

func ReadKlinesFromCSVWithDecoder added in v0.0.18

func ReadKlinesFromCSVWithDecoder(path string, maker MakeCSVKlineReader) ([]Kline, error)

ReadKlinesFromCSVWithDecoder permits using a custom CSVKlineReader.

type KlineReader

type KlineReader interface {
	Read() (Kline, error)
	ReadAll() ([]Kline, error)
}

KlineReader is an interface for reading candlesticks.

type MakeCSVKlineReader added in v0.0.18

type MakeCSVKlineReader func(csv *csv.Reader) *CSVKlineReader

MakeCSVKlineReader is a factory method type that creates a new CSVKlineReader.

type Receiver

type Receiver interface {
	ReceivePrice(context.Context, Kline) error
}

Receiver is a core interface implemented by many types that receive market data.

Jump to

Keyboard shortcuts

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