Documentation
¶
Overview ¶
Package asset contains the asset related functions.
This package belongs to the Indicator project. Indicator is a Golang module that supplies a variety of technical indicators, strategies, and a backtesting framework for analysis.
License ¶
Copyright (c) 2021-2026 Onur Cinar. The source code is provided under GNU AGPLv3 License. https://github.com/cinar/indicator
Disclaimer ¶
The information provided on this project is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.
Index ¶
- Constants
- Variables
- func RegisterRepositoryBuilder(name string, builder RepositoryBuilderFunc)
- func SnapshotsAsClosings(snapshots <-chan *Snapshot) <-chan float64
- func SnapshotsAsDates(snapshots <-chan *Snapshot) <-chan time.Time
- func SnapshotsAsHighs(snapshots <-chan *Snapshot) <-chan float64
- func SnapshotsAsLows(snapshots <-chan *Snapshot) <-chan float64
- func SnapshotsAsOpenings(snapshots <-chan *Snapshot) <-chan float64
- func SnapshotsAsVolumes(snapshots <-chan *Snapshot) <-chan float64
- type FileSystemRepository
- func (r *FileSystemRepository) Append(name string, snapshots <-chan *Snapshot) error
- func (r *FileSystemRepository) Assets() ([]string, error)
- func (r *FileSystemRepository) Get(name string) (<-chan *Snapshot, error)
- func (r *FileSystemRepository) GetSince(name string, date time.Time) (<-chan *Snapshot, error)
- func (r *FileSystemRepository) LastDate(name string) (time.Time, error)
- type InMemoryRepository
- func (r *InMemoryRepository) Append(name string, snapshots <-chan *Snapshot) error
- func (r *InMemoryRepository) Assets() ([]string, error)
- func (r *InMemoryRepository) Get(name string) (<-chan *Snapshot, error)
- func (r *InMemoryRepository) GetSince(name string, date time.Time) (<-chan *Snapshot, error)
- func (r *InMemoryRepository) LastDate(name string) (time.Time, error)
- type Repository
- type RepositoryBuilderFunc
- type SQLRepository
- func (s *SQLRepository) Append(name string, snapshots <-chan *Snapshot) error
- func (s *SQLRepository) Assets() ([]string, error)
- func (s *SQLRepository) Close() error
- func (s *SQLRepository) Drop() error
- func (s *SQLRepository) Get(name string) (<-chan *Snapshot, error)
- func (s *SQLRepository) GetSince(name string, date time.Time) (<-chan *Snapshot, error)
- func (s *SQLRepository) LastDate(name string) (time.Time, error)
- type SQLRepositoryDialect
- type Snapshot
- type Sync
- type TiingoEndOfDay
- type TiingoMeta
- type TiingoRepository
- func (*TiingoRepository) Append(_ string, _ <-chan *Snapshot) error
- func (*TiingoRepository) Assets() ([]string, error)
- func (r *TiingoRepository) Get(name string) (<-chan *Snapshot, error)
- func (r *TiingoRepository) GetSince(name string, date time.Time) (<-chan *Snapshot, error)
- func (r *TiingoRepository) LastDate(name string) (time.Time, error)
Constants ¶
const ( // InMemoryRepositoryBuilderName is the name for the in memory repository builder. InMemoryRepositoryBuilderName = "memory" // FileSystemRepositoryBuilderName is the name for the file system repository builder. FileSystemRepositoryBuilderName = "filesystem" // TiingoRepositoryBuilderName is the name of the Tiingo repository builder. TiingoRepositoryBuilderName = "tiingo" )
const ( // DefaultSyncWorkers is the default number of workers to use to synchronize. DefaultSyncWorkers = 1 // DefaultSyncDelay is the default delay in seconds between each get request. DefaultSyncDelay = 5 )
Variables ¶
var ErrRepositoryAssetEmpty = errors.New("asset empty")
ErrRepositoryAssetEmpty indicates that the given asset has no snapshots.
var ErrRepositoryAssetNotFound = errors.New("asset is not found")
ErrRepositoryAssetNotFound indicates that the given asset name is not found in the repository.
Functions ¶
func RegisterRepositoryBuilder ¶ added in v2.1.2
func RegisterRepositoryBuilder(name string, builder RepositoryBuilderFunc)
RegisterRepositoryBuilder registers the given builder.
func SnapshotsAsClosings ¶
SnapshotsAsClosings extracts the close field from each snapshot in the provided channel and returns a new channel containing only those close values.The original snapshots channel can no longer be directly used afterward.
func SnapshotsAsDates ¶
SnapshotsAsDates extracts the date field from each snapshot in the provided channel and returns a new channel containing only those date values.The original snapshots channel can no longer be directly used afterward.
func SnapshotsAsHighs ¶
SnapshotsAsHighs extracts the high field from each snapshot in the provided channel and returns a new channel containing only those high values.The original snapshots channel can no longer be directly used afterward.
func SnapshotsAsLows ¶
SnapshotsAsLows extracts the low field from each snapshot in the provided channel and returns a new channel containing only those low values.The original snapshots channel can no longer be directly used afterward.
func SnapshotsAsOpenings ¶
SnapshotsAsOpenings extracts the open field from each snapshot in the provided channel and returns a new channel containing only those open values.The original snapshots channel can no longer be directly used afterward.
func SnapshotsAsVolumes ¶
SnapshotsAsVolumes extracts the volume field from each snapshot in the provided channel and returns a new channel containing only those volume values.The original snapshots channel can no longer be directly used afterward.
Types ¶
type FileSystemRepository ¶
type FileSystemRepository struct {
// contains filtered or unexported fields
}
FileSystemRepository stores and retrieves asset snapshots using the local file system.
func NewFileSystemRepository ¶
func NewFileSystemRepository(base string, csvOptions ...helper.CsvOption[Snapshot]) *FileSystemRepository
NewFileSystemRepository initializes a file system repository with the given base directory and the CSV options.
func (*FileSystemRepository) Append ¶
func (r *FileSystemRepository) Append(name string, snapshots <-chan *Snapshot) error
Append adds the given snapshows to the asset with the given name.
func (*FileSystemRepository) Assets ¶
func (r *FileSystemRepository) Assets() ([]string, error)
Assets returns the names of all assets in the repository.
func (*FileSystemRepository) Get ¶
func (r *FileSystemRepository) Get(name string) (<-chan *Snapshot, error)
Get attempts to return a channel of snapshots for the asset with the given name.
type InMemoryRepository ¶
type InMemoryRepository struct {
// contains filtered or unexported fields
}
InMemoryRepository stores and retrieves asset snapshots using an in memory storage.
func NewInMemoryRepository ¶
func NewInMemoryRepository() *InMemoryRepository
NewInMemoryRepository initializes an in memory repository.
func (*InMemoryRepository) Append ¶
func (r *InMemoryRepository) Append(name string, snapshots <-chan *Snapshot) error
Append adds the given snapshows to the asset with the given name.
func (*InMemoryRepository) Assets ¶
func (r *InMemoryRepository) Assets() ([]string, error)
Assets returns the names of all assets in the repository.
func (*InMemoryRepository) Get ¶
func (r *InMemoryRepository) Get(name string) (<-chan *Snapshot, error)
Get attempts to return a channel of snapshots for the asset with the given name.
type Repository ¶
type Repository interface {
// Assets returns the names of all assets in the repository.
Assets() ([]string, error)
// Get attempts to return a channel of snapshots for
// the asset with the given name.
Get(name string) (<-chan *Snapshot, error)
// GetSince attempts to return a channel of snapshots for
// the asset with the given name since the given date.
GetSince(name string, date time.Time) (<-chan *Snapshot, error)
// LastDate returns the date of the last snapshot for
// the asset with the given name.
LastDate(name string) (time.Time, error)
// Append adds the given snapshows to the asset with the
// given name.
Append(name string, snapshots <-chan *Snapshot) error
}
Repository serves as a centralized storage and retrieval location for asset snapshots.
func NewRepository ¶ added in v2.1.2
func NewRepository(name, config string) (Repository, error)
NewRepository builds a new repository by the given name type and the configuration.
type RepositoryBuilderFunc ¶ added in v2.1.2
type RepositoryBuilderFunc func(config string) (Repository, error)
RepositoryBuilderFunc defines a function to build a new repository using the given configuration parameter.
type SQLRepository ¶ added in v2.1.13
type SQLRepository struct {
// contains filtered or unexported fields
}
SQLRepository provides a SQL backed storage facility for financial market data.
func NewSQLRepository ¶ added in v2.1.13
func NewSQLRepository(dbDriver, dbURL string, dialect SQLRepositoryDialect) (*SQLRepository, error)
NewSQLRepository takes a database driver, URL, and dialect for the asset repository and connects to it.
func (*SQLRepository) Append ¶ added in v2.1.13
func (s *SQLRepository) Append(name string, snapshots <-chan *Snapshot) error
Append adds the given snapshots to the asset with the given name.
func (*SQLRepository) Assets ¶ added in v2.1.13
func (s *SQLRepository) Assets() ([]string, error)
Assets returns the names of all assets in the respository.
func (*SQLRepository) Close ¶ added in v2.1.13
func (s *SQLRepository) Close() error
Close closes the database connection.
func (*SQLRepository) Drop ¶ added in v2.1.13
func (s *SQLRepository) Drop() error
Drop drops the snapshots table.
func (*SQLRepository) Get ¶ added in v2.1.13
func (s *SQLRepository) Get(name string) (<-chan *Snapshot, error)
Get attempts to return a channel of snapshots for the asset with the given name.
type SQLRepositoryDialect ¶ added in v2.1.13
type SQLRepositoryDialect interface {
// CreateTable returns the SQL statement to create the repository table.
CreateTable() string
// DropTable returns the SQL statement to drop the repository table.
DropTable() string
// Assets returns the SQL statement to get the names of all assets in the respository.
Assets() string
// GetSince returns the SQL statement to query snapshots for the asset with the given name since the given date.
GetSince() string
// LastDate returns the SQL statement to query for the last date for the asset with the given name.
LastDate() string
// Appends returns the SQL statement to add the given snapshots to the asset with the given name.
Append() string
}
SQLRepositoryDialect defines the SQL dialect for the SQL repository.
type Snapshot ¶
type Snapshot struct {
// Date represents the specific timestamp.
Date time.Time
// Open represents the opening price for the
// snapshot period.
Open float64
// High represents the highest price reached
// during the snapshot period.
High float64
// Low represents the lowest price reached
// during the snapshot period.
Low float64
// Close represents the closing price for the
// snapshot period.
Close float64
// Volume represents the total trading activity for
// the asset during the snapshot period.
Volume float64
}
Snapshot captures a single observation of an asset's price at a specific moment.
type Sync ¶
type Sync struct {
// Number of workers to use.
Workers int
// Delay between repository get requests to minimize the load to the remote server.
Delay int
// Assets is the name of the assets to be synced. If it is empty, all assets in the target repository
// will be synced instead.
Assets []string
// Logger is the slog logger instance.
Logger *slog.Logger
}
Sync represents the configuration parameters for synchronizing assets between repositories.
type TiingoEndOfDay ¶
type TiingoEndOfDay struct {
// Date is the date this data pertains to.
Date time.Time `json:"date"`
// Open is the opening price.
Open float64 `json:"open"`
// High is the highest price.
High float64 `json:"high"`
// Low is the lowest price.
Low float64 `json:"low"`
// Close is the closing price.
Close float64 `json:"close"`
// Volume is the total volume.
Volume int64 `json:"volume"`
// AdjOpen is the adjusted opening price.
AdjOpen float64 `json:"adjOpen"`
// AdjHigh is the adjusted highest price.
AdjHigh float64 `json:"adjHigh"`
// AdjLow is the adjusted lowest price.
AdjLow float64 `json:"adjLow"`
// AdjClose is the adjusted closing price.
AdjClose float64 `json:"adjClose"`
// AdjVolume is the adjusted total volume.
AdjVolume int64 `json:"adjVolume"`
// Dividend is the dividend paid out.
Dividend float64 `json:"divCash"`
// Split to adjust values after a split.
Split float64 `json:"splitFactor"`
}
TiingoEndOfDay is the repose from the end-of-day endpoint. https://www.tiingo.com/documentation/end-of-day
func (*TiingoEndOfDay) ToSnapshot ¶
func (e *TiingoEndOfDay) ToSnapshot() *Snapshot
ToSnapshot converts the Tiingo end-of-day to a snapshot.
type TiingoMeta ¶
type TiingoMeta struct {
// Ticker related to the asset.
Ticker string `json:"ticker"`
// Name is the full name of the asset.
Name string `json:"name"`
// ExchangeCode is the exchange where the asset is listed on.
ExchangeCode string `json:"exchangeCode"`
// Description is the description of the asset.
Description string `json:"description"`
// StartDate is the earliest date for the asset data.
StartDate time.Time `json:"startDate"`
// EndDate is the latest date for the asset data.
EndDate time.Time `json:"endDate"`
}
TiingoMeta is the response from the meta endpoint. https://www.tiingo.com/documentation/end-of-day
type TiingoRepository ¶
type TiingoRepository struct {
Repository
// BaseURL is the Tiingo API URL.
BaseURL string
// Logger is the slog logger instance.
Logger *slog.Logger
// contains filtered or unexported fields
}
TiingoRepository provides access to financial market data, retrieving asset snapshots, by interacting with the Tiingo Stock & Financial Markets API. To use this repository, you'll need a valid API key from https://www.tiingo.com.
func NewTiingoRepository ¶
func NewTiingoRepository(apiKey string) *TiingoRepository
NewTiingoRepository initializes a file system repository with the given API key.
func (*TiingoRepository) Append ¶
func (*TiingoRepository) Append(_ string, _ <-chan *Snapshot) error
Append adds the given snapshows to the asset with the given name.
func (*TiingoRepository) Assets ¶
func (*TiingoRepository) Assets() ([]string, error)
Assets returns the names of all assets in the repository.
func (*TiingoRepository) Get ¶
func (r *TiingoRepository) Get(name string) (<-chan *Snapshot, error)
Get attempts to return a channel of snapshots for the asset with the given name.