db

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package db handles all data exchange to the db.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLimit = errors.New("daily limit reached")
	ErrCode  = errors.New("invalid code requested")
)
View Source
var ErrNoRecord = errors.New("models: no matching record found")

ErrNoRecord is returned if the query is empty.

Functions

func NewApp

func NewApp(ctx context.Context, c Config) (*app, func(), error)

Types

type AlphaVantage

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

func NewAlphaVantage

func NewAlphaVantage(alphaFunction,
	alphaKey string) AlphaVantage

func (AlphaVantage) Pull

func (s AlphaVantage) Pull(ctx context.Context, ShareCode string) ([]byte, error)

type Asset

type Asset struct {
	ID     AssetID `json:"shareid"`
	Name   string  `json:"description"`
	Symbol string  `json:"symbol"`
}

Asset is the base struct for assets.

type AssetExtractor

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

AssetExtractor describes financial data relation

func NewAssetExtractor

func NewAssetExtractor(db PgxIface) *AssetExtractor

func (*AssetExtractor) Assets

func (a *AssetExtractor) Assets(ctx context.Context, MinAge time.Time, Active bool) ([]PricedAsset, error)

Assets provides basic info for searched assets. It sorts (highest first) by traded volume of the last days past.

func (*AssetExtractor) AssetsByID

func (a *AssetExtractor) AssetsByID(ctx context.Context, ids ...AssetID) ([]PricedAsset, error)

func (*AssetExtractor) AssetsBySearch

func (a *AssetExtractor) AssetsBySearch(ctx context.Context, search string, MinAge time.Time, Active bool) ([]PricedAsset, error)

AssetsBySearch provides basic info for searched assets. It sorts (highest first) by traded volume of the last daysPast. func (a *AssetExtractor) GetShareInfo(ctx context.Context, shareIDs []int, daysPast int, queryString string) ([]PricedAsset, error) {

func (*AssetExtractor) HealthCheck

func (a *AssetExtractor) HealthCheck(ctx context.Context) <-chan error

HealthCheck currently only pings the db to see if it is available

func (*AssetExtractor) TimeSeriesAssetsByID

func (a *AssetExtractor) TimeSeriesAssetsByID(ctx context.Context, from time.Time, ids ...AssetID) ([]TimeSeriesAsset, error)

TimeSeriesAssetsByID any return asset comes with a timeSeries starting at `from`

type AssetID

type AssetID = int

type Config

type Config struct {
	PGUser        string `envconfig:"POSTGRES_USER"`
	PGPW          string `envconfig:"POSTGRES_PASSWORD"`
	PGDB          string `envconfig:"POSTGRES_DB"`
	AlphaKey      string `envconfig:"ALPHA_KEY"`
	AlphaFunction string `envconfig:"ALPHA_FUNCTION"`
}

type PgxIface

type PgxIface interface {
	Ping(ctx context.Context) error
	QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
	Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
}

type PricedAsset

type PricedAsset struct {
	Asset
	Price float64 `json:"price"`
}

PricedAsset extends Asset by the latest price for value orientation.

type TemporaryError

type TemporaryError struct {
	RetryValid bool
	Err        error
}

TemporaryError says that a instant rerun is sensible.

func (*TemporaryError) Error

func (e *TemporaryError) Error() string

type TimeSeries

type TimeSeries map[time.Time]float64

TimeSeries maps SharePrice per day (=unique key)

type TimeSeriesAsset

type TimeSeriesAsset struct {
	Asset
	TimeSeries TimeSeries `json:"time_series"`
}

TimeSeriesAsset extends Asset by a TimeSeries to do computation.

Jump to

Keyboard shortcuts

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