tokenprice

package
v1.0.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrChore = errs.Class("Chore")

ErrChore is an error class for coinmarketcap API client error.

View Source
var (
	// ErrNoQuotes is error when no quotes were found in DB.
	ErrNoQuotes = errs.New("no quotes in db")
)
View Source
var ErrService = errs.Class("tokenprice service")

ErrService is token price service error class.

Functions

func CalculateValue

func CalculateValue(value, price currency.Amount) currency.Amount

CalculateValue calculates value from given token value and price.

Types

type Chore

type Chore struct {
	Loop *sync2.Cycle
	// contains filtered or unexported fields
}

Chore to save storj ticker price to local DB.

architecture: Chore

func NewChore

func NewChore(log *zap.Logger, service *Service, interval time.Duration) *Chore

NewChore creates new chore for saving storj ticker price to local DB.

func (*Chore) Close

func (chore *Chore) Close() error

Close stops the chore.

func (*Chore) Run

func (chore *Chore) Run(ctx context.Context) (err error)

Run starts the chore.

func (*Chore) RunOnce

func (chore *Chore) RunOnce(ctx context.Context) (err error)

RunOnce gets the latest storj ticker price and saves it to the DB.

type Client

type Client interface {
	// GetLatestPrice gets the latest available ticker price.
	GetLatestPrice(context.Context) (time.Time, currency.Amount, error)
	// GetPriceAt gets the ticker price at the specified time.
	GetPriceAt(context.Context, time.Time) (time.Time, currency.Amount, error)
	// Ping checks that the third-party api is available for use.
	Ping(ctx context.Context) (int, error)
}

Client is the interface used to query for STORJ token price.

type Config

type Config struct {
	Interval            time.Duration `help:"how often to run the chore" default:"1m" testDefault:"$TESTINTERVAL"`
	PriceWindow         time.Duration `` /* 133-byte string literal not displayed */
	CoinmarketcapConfig coinmarketcap.Config
	UseTestPrices       bool `help:"use test prices instead of coninmaketcap" default:"false"`
}

Config is a configuration struct for the token price service.

type PriceQuote

type PriceQuote struct {
	Timestamp time.Time
	Price     currency.Amount
}

PriceQuote represents an entry in the token_price table.

type PriceQuoteDB

type PriceQuoteDB interface {
	// Update updates the stored token price for the given time window, or creates a new entry if it does not exist.
	Update(ctx context.Context, window time.Time, price int64) error

	// Before gets the first token price with timestamp before provided timestamp.
	Before(ctx context.Context, before time.Time) (PriceQuote, error)

	// DeleteBefore deletes token prices before the given time.
	DeleteBefore(ctx context.Context, before time.Time) (err error)
}

PriceQuoteDB is STORJ token price database.

architecture: Database

type Service

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

Service retrieves token price.

func NewService

func NewService(log *zap.Logger, db PriceQuoteDB, client Client, priceWindow time.Duration) *Service

NewService creates new service.

func (*Service) LatestPrice

func (service *Service) LatestPrice(ctx context.Context) (_ time.Time, _ currency.Amount, err error)

LatestPrice gets the latest available ticker price.

func (*Service) Ping

func (service *Service) Ping(ctx context.Context) (statusCode int, err error)

Ping checks that the third-party api is available for use.

func (*Service) PriceAt

func (service *Service) PriceAt(ctx context.Context, timestamp time.Time) (_ currency.Amount, err error)

PriceAt retrieves token price at a particular timestamp.

func (*Service) SavePrice

func (service *Service) SavePrice(ctx context.Context, timestamp time.Time, price currency.Amount) (err error)

SavePrice stores the token price for the given time window.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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