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-2024 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 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 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 ( // 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 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 afterwards.
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 afterwards.
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 afterwards.
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 afterwards.
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 afterwards.
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 afterwards.
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) *FileSystemRepository
NewFileSystemRepository initializes a file system repository with the given base directory.
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.
type Snapshot ¶
type Snapshot struct {
// Date represents the specific timestamp.
Date time.Time `format:"2006-01-02"`
// 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
}
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
// 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.