db

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 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"),
		Asset("ORCL5"),
		Asset("DEGEN10"),
	}
	// 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) LastTotalSupply added in v0.0.17

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

LastTotalSupply returns the last recorded total supply for an asset

func (*Database) LastValueLocked added in v0.0.15

func (d *Database) LastValueLocked(pool string) (float64, error)

LastValueLocked returns the latest record total value locked entry

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

func (*Database) RecordTotalSupply added in v0.0.17

func (d *Database) RecordTotalSupply(asset string, supply float64) error

RecordTotalSupply is used to record the supply for an asset

func (*Database) RecordValueLocked added in v0.0.15

func (d *Database) RecordValueLocked(pool string, locked float64) error

RecordValueLocked records the USD value locked into a pool

type Model added in v0.0.17

type Model struct {
	ID        uint      `gorm:"primarykey"`
	CreatedAt time.Time // `gorm:"index"` // this is changed to include the index
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

Model is a copy of the gorm model type but using slightly different configurations

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 {
	Model
	Type     Asset `gorm:"varchar(255)"`
	USDPrice float64
}

Price is a given price entry for an asset

type TotalSupply added in v0.0.17

type TotalSupply struct {
	Model
	Type   string
	Supply float64
}

TotalSupply is used to track the total supply of a given asset

type TotalValueLocked added in v0.0.15

type TotalValueLocked struct {
	Model
	PoolName    string
	ValueLocked float64
}

TotalValueLocked records the USD value of funds locked within index pool

Jump to

Keyboard shortcuts

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