csvsource

package
v1.64.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: AGPL-3.0 Imports: 19 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	SPOT      MarketType = "spot"
	FUTURES   MarketType = "futures"
	TRADES    DataType   = "trades"
	AGGTRADES DataType   = "aggTrades"
)

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.
	ErrInvalidIDFormat = errors.New("cannot parse trade id string")

	// ErrInvalidBoolFormat is returned when the CSV isBuyerMaker record does not have a valid bool representation.
	ErrInvalidBoolFormat = errors.New("cannot parse bool to string")

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

	// ErrInvalidOrderSideFormat is returned when the CSV side record does not have a valid buy or sell string.
	ErrInvalidOrderSideFormat = errors.New("cannot parse order side string")

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

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

Functions

func Download

func Download(
	path, symbol string,
	exchange types.ExchangeName,
	market MarketType,
	granularity DataType,
	since, until time.Time,
) (err error)

func ReadAllCsv

func ReadAllCsv(dir string, interval time.Duration) ([]types.KLine, error)

ReadAllCsv 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 ReadTicksFromCSV

func ReadTicksFromCSV(
	path, symbol string,
	intervals []types.Interval,
) (
	klineMap map[types.Interval][]types.KLine,
	err error,
)

ReadTicksFromCSV reads all the .csv files in a given directory or a single file into KLines.

func WriteKLines

func WriteKLines(path, symbol string, klines []types.KLine) (err error)

WriteKLines writes csv to path.

Types

type CSVKLineReader

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

CSVKLineReader is a KLineReader that reads from a CSV file.

func NewCSVKLineReader

func NewCSVKLineReader(csv *csv.Reader) *CSVKLineReader

NewCSVKLineReader creates a new CSVKLineReader with the default Binance decoder.

func (*CSVKLineReader) Read

func (r *CSVKLineReader) Read(interval time.Duration) (types.KLine, error)

Read reads the next KLine from the underlying CSV data.

func (*CSVKLineReader) ReadAll

func (r *CSVKLineReader) ReadAll(interval time.Duration) ([]types.KLine, error)

ReadAll reads all the KLines from the underlying CSV data.

type CSVTickConverter

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

CSVTickConverter takes a tick and internally converts it to a KLine slice

func (*CSVTickConverter) AddKLine

func (c *CSVTickConverter) AddKLine(interval types.Interval, k types.KLine)

func (*CSVTickConverter) CsvTickToKLine

func (c *CSVTickConverter) CsvTickToKLine(tick *CsvTick) (closesKLine bool)

Convert ticks to KLine with interval

func (*CSVTickConverter) GetKLineResults

func (c *CSVTickConverter) GetKLineResults() map[types.Interval][]types.KLine

GetKLineResults returns the converted ticks as kLine of all constructed intervals

func (*CSVTickConverter) GetTicks

func (c *CSVTickConverter) GetTicks() []*CsvTick

func (*CSVTickConverter) LatestKLine

func (c *CSVTickConverter) LatestKLine(interval types.Interval) (k *types.KLine)

GetKLineResult returns the converted ticks as kLine of interval

type CSVTickReader

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

CSVTickReader reads CsvTick records from a CSV file.

func NewCSVTickReader

func NewCSVTickReader(csv *csv.Reader) *CSVTickReader

NewCSVTickReader creates a new CSVTickReader.

func (*CSVTickReader) Read

func (r *CSVTickReader) Read() (*CsvTick, error)

Read reads the next CsvTick from the underlying CSV data.

func (*CSVTickReader) ReadAll

func (r *CSVTickReader) ReadAll() (ticks []*CsvTick, err error)

ReadAll reads all CsvTicks from the underlying CSV data.

type CsvConfig

type CsvConfig struct {
	Market      MarketType `json:"market"`
	Granularity DataType   `json:"granularity"`
}

type CsvTick

type CsvTick struct {
	Exchange        types.ExchangeName `json:"exchange"`
	Market          MarketType         `json:"market"`
	TradeID         uint64             `json:"tradeID"`
	Symbol          string             `json:"symbol"`
	TickDirection   string             `json:"tickDirection"`
	Side            types.SideType     `json:"side"`
	IsBuyerMaker    bool
	Size            fixedpoint.Value           `json:"size"`
	Price           fixedpoint.Value           `json:"price"`
	HomeNotional    fixedpoint.Value           `json:"homeNotional"`
	ForeignNotional fixedpoint.Value           `json:"foreignNotional"`
	Timestamp       types.MillisecondTimestamp `json:"timestamp"`
}

func CSVTickDecoder

func CSVTickDecoder(row []string) (*CsvTick, error)

CSVTickDecoder decodes a normalized CSV record into a CsvTick. The normalized format is: trade_id, side, size, price, timestamp where side is "buy" or "sell" and timestamp is in milliseconds.

func (*CsvTick) ToGlobalTrade

func (c *CsvTick) ToGlobalTrade() (*types.Trade, error)

type DataType

type DataType string

type ICSVTickConverter

type ICSVTickConverter interface {
	CsvTickToKLine(tick *CsvTick) (closesKLine bool)
	GetTicks() []*CsvTick
	LatestKLine(interval types.Interval) (k *types.KLine)
	GetKLineResults() map[types.Interval][]types.KLine
}

func NewCSVTickConverter

func NewCSVTickConverter(intervals []types.Interval) ICSVTickConverter

type KLineReader

type KLineReader interface {
	Read(interval time.Duration) (types.KLine, error)
	ReadAll(interval time.Duration) ([]types.KLine, error)
}

KLineReader is an interface for reading candlesticks.

type MarketType

type MarketType string

type TickReader

type TickReader interface {
	Read() (*CsvTick, error)
	ReadAll() (ticks []*CsvTick, err error)
}

TickReader is an interface for reading CsvTicks.

Jump to

Keyboard shortcuts

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