datasource

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2025 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ERR_FILE_DAMAGED = errors.New("file damaged")
)

Functions

func MergeData

func MergeData[T float32 | float64](destData []Record[T], sourceData []Record[T], multiplier int) []Record[T]

Types

type BaseDataSource

type BaseDataSource[T float32 | float64] interface {
	GetData(security *Security, period Period) (error, []Record[T])
	GetDataEx(security *Security, period Period, startDate uint64, count int) (error, []Record[T])

	GetRangeData(security *Security, period Period, startDate, endDate uint64) (error, []Record[T])
	GetDataFromLast(security *Security, period Period, endDate uint64, count int) (error, []Record[T])
	GetLastRecord(security *Security, period Period) (error, *Record[T])

	GetForwardAdjustedRangeData(security *Security, period Period, startDate, endDate uint64) (error, []Record[T])

	AppendData(security *Security, period Period, data []Record[T]) error // Append data
	SaveData(security *Security, period Period, data []Record[T]) error   // Replace data with new data

	RemoveData(security *Security, period Period, startDate, endDate uint64) error
}

endDate: inclusive

type CompositeDataSource

type CompositeDataSource[T float32 | float64] interface {
	BaseDataSource[T]
	AddSubDatasource(ds BaseDataSource[T])
}

type Converter

type Converter[T float32 | float64] interface {
	Convert(sourceData []Record[T]) []Record[T]
}

func NewForwardAdjustConverter

func NewForwardAdjustConverter[T float32 | float64](period Period, items []InfoExItem) Converter[T]

func NewPeriodConverter

func NewPeriodConverter[T float32 | float64](srcPeriod Period, destPeriod Period) Converter[T]

type DataSource

type DataSource[T float32 | float64] interface {
	InfoExDataSource
	BaseDataSource[T]

	// market - 市场代码, sz-深交所, sh-上交所
	GetStockCodes(exchange string) []string
	GetStockNameHistory(security *Security) []StockNameItem
	GetStockName(security *Security) string
	GetStockNames() map[string]string

	Reset()

	SupportedPeriods() []Period

	GetForwardAdjustedData(security *Security, period Period) (error, []Record[T])
	GetForwardAdjustedRangeData(security *Security, period Period, startDate, endDate uint64) (error, []Record[T])
	GetForwardAdjustedDataFromLast(security *Security, period Period, endDate uint64, count int) (error, []Record[T])

	AppendRawData(security *Security, period Period, data []byte) error // Append raw data

	// Remove data which date is greater or equal to date
	TruncateTo(security *Security, period Period, date uint64) error
}

type DateRange

type DateRange struct {
	Security  *Security
	StartDate uint64 // inclusive, 0 if no start date
	EndDate   uint64 // exclusive, 0 if no end date
}

type DateRangeMapper

type DateRangeMapper interface {
	MapDateRanges(security *Security) []DateRange
}

type InfoExDataSource

type InfoExDataSource interface {
	GetStockInfoEx(security *Security) (error, []InfoExItem)
	SetInfoEx(infoEx map[string][]InfoExItem) error
}

type MappedDataSource

type MappedDataSource[T float32 | float64] interface {
	BaseDataSource[T]
	SetMapper(mapper DateRangeMapper)
	SetTargetDataSource(ds BaseDataSource[T])
}

type RecordMarshaller

type RecordMarshaller[T float32 | float64] interface {
	ToBytes(record *Record[T]) ([]byte, error)
	FromBytes(bytes []byte, record *Record[T]) error
}

type RecordReader

type RecordReader[T float32 | float64] interface {
	Read(start, end int) (error, []Record[T])
	Count() (error, int)
}

func NewRecordReader

func NewRecordReader[T float32 | float64](file *os.File, recordSize int, marshaller RecordMarshaller[T]) RecordReader[T]

type RecordWriter

type RecordWriter[T float32 | float64] interface {
	Write(from int, data []Record[T]) error
	WriteRaw(from int, data []byte) error
}

func NewRecordWriter

func NewRecordWriter[T float32 | float64](file *os.File, recordSize int, marshaller RecordMarshaller[T]) RecordWriter[T]

type StockNameItem

type StockNameItem struct {
	Date uint32
	Name string
}

type TickDataSource

type TickDataSource interface {
	Save(security *Security, ticks []TickItem) error
	Get(security *Security, startTs, endTs uint64) (error, []TickItem)
	Remove(security *Security, startTs, endTs uint64) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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