db

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Assets are all currently supported assets for which we track prices
	Assets = []Asset{
		Asset("NDX"),
		Asset("DEFI5"),
		Asset("CC10"),
		Asset("ETH"),
	}
	// ErrInvalidAsset is an error returned when the given asset specified is invalid
	ErrInvalidAsset = errors.New("invalid asset")
)

Functions

func IsValidAsset

func IsValidAsset(asset string) bool

IsValidAsset determines whether or not the given asset is one we are tracking

Types

type Asset

type Asset string

Asset is a given crypto asset tracked by it's Ticker symbol

func ToAsset

func ToAsset(asset string) Asset

ToAsset is a helper function to type convert string -> Asset

func (Asset) String

func (a Asset) String() string

String returns the Asset value in string type

type Database

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

func New

func New(opts *Opts) (*Database, error)

New returns a new database client

func (*Database) AutoMigrate

func (d *Database) AutoMigrate() error

AutoMigrate is used to automatically migrate datbase tables

func (*Database) Close

func (d *Database) Close() error

Close shuts down the database

func (*Database) GetAllPrices

func (d *Database) GetAllPrices(asset string) ([]*Price, error)

GetAllPrices returns all price entries for a given asset

func (*Database) LastPrice

func (d *Database) LastPrice(asset string) (float64, error)

LastPrice returns the last recorded price

func (*Database) PriceAvgInRange

func (d *Database) PriceAvgInRange(asset string, windowInDays int) (float64, error)

PriceAvgInRange returns the average price of the given asset during the last N days

func (*Database) PriceChangeInRange

func (d *Database) PriceChangeInRange(asset string, windowInDays int) (float64, error)

PriceChangeInRange returns the price change percentage in the last N days

func (*Database) PricesInRange added in v0.0.14

func (d *Database) PricesInRange(asset string, windowInDays int) ([]*Price, error)

PricesInRange returns all prices items in the given range

func (*Database) RecordPrice

func (d *Database) RecordPrice(asset string, price float64) error

RecordPrice records the given asset price in the database

type Opts

type Opts struct {
	Type           string
	Host           string
	Port           string
	User           string
	Password       string
	DBName         string
	DBPath         string
	SSLModeDisable bool
}

Opts is used to configure database connections

func (*Opts) DSN

func (db *Opts) DSN() string

DSN returns the config string used with gorm

func (*Opts) Open

func (db *Opts) Open() (gorm.Dialector, error)

Open returns the gorm dialector for the corresponding db type

type Price

type Price struct {
	gorm.Model
	Type     Asset `gorm:"varchar(255)"`
	USDPrice float64
}

Price is a given price entry for an asset

Jump to

Keyboard shortcuts

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