types

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxPriceAge defines the duration in which a price update is valid for.
	MaxPriceAge = time.Duration(30_000_000_000) // 30 sec, duration uses nanoseconds.
)

Variables

This section is empty.

Functions

This section is empty.

Types

type PriceTimestamp

type PriceTimestamp struct {
	LastUpdateTime time.Time
	Price          uint64
}

PriceTimestamp maintains a price and its last update timestamp.

func NewPriceTimestamp

func NewPriceTimestamp() *PriceTimestamp

NewPriceTimestamp creates a new PriceTimestamp.

func (*PriceTimestamp) GetValidPrice

func (pt *PriceTimestamp) GetValidPrice(cutoffTime time.Time) (uint64, bool)

GetValidPrice returns (price, true) if the last update time is greater than or equal to the given cutoff time. Otherwise returns (0, false).

func (*PriceTimestamp) UpdatePrice

func (pt *PriceTimestamp) UpdatePrice(price uint64, newUpdateTime *time.Time) bool

UpdatePrice updates the price if the given update has a greater timestamp. Returns true if updating succeeds. Otherwise, returns false.

type Resolver added in v0.3.0

type Resolver func([]uint64) (uint64, error)

Resolver is a function type that "resolves" a slice of values to a single value. The function also returns an error if there was an error in resolving the value.

Jump to

Keyboard shortcuts

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