Documentation ¶
Index ¶
- Variables
- func CalculateValue(value, price currency.Amount) currency.Amount
- type Chore
- type Client
- type Config
- type PriceQuote
- type PriceQuoteDB
- type Service
- func (service *Service) LatestPrice(ctx context.Context) (_ time.Time, _ currency.Amount, err error)
- func (service *Service) Ping(ctx context.Context) (statusCode int, err error)
- func (service *Service) PriceAt(ctx context.Context, timestamp time.Time) (_ currency.Amount, err error)
- func (service *Service) SavePrice(ctx context.Context, timestamp time.Time, price currency.Amount) (err error)
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 ¶
Types ¶
type Chore ¶
Chore to save storj ticker price to local DB.
architecture: Chore
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 ¶
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.
Click to show internal directories.
Click to hide internal directories.