types

package
v0.3.0-dev1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExchangeToPrice

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

ExchangeToPrice maintains multiple prices from different exchanges for the same market, along with the last time the each exchange price was updated.

func NewExchangeToPrice

func NewExchangeToPrice(marketId uint32) *ExchangeToPrice

NewExchangeToPrice creates a new ExchangeToPrice. It takes a market ID, which is used in logging and metrics to identify the market these exchange prices are for. The market ID does not otherwise affect the behavior of the ExchangeToPrice.

func (*ExchangeToPrice) GetValidPrices

func (etp *ExchangeToPrice) GetValidPrices(
	cutoffTime time.Time,
) []uint64

GetValidPrices returns a list of "valid" prices. Prices are considered "valid" iff the last update time is greater than or equal to the given cutoff time.

func (*ExchangeToPrice) UpdatePrices

func (etp *ExchangeToPrice) UpdatePrices(updates []*api.ExchangePrice)

UpdatePrices updates prices given a list of prices from different exchanges. Prices are only updated if the timestamp on the updates are greater than the timestamp on existing prices.

type MarketToExchangePrices

type MarketToExchangePrices struct {
	sync.RWMutex // reader-writer lock
	// contains filtered or unexported fields
}

MarketToExchangePrices maintains price info for multiple markets. Each market can support prices from multiple exchange sources. Specifically, MarketToExchangePrices supports methods to update prices and to retrieve median prices. Methods are goroutine safe.

func NewMarketToExchangePrices

func NewMarketToExchangePrices(maxPriceAge time.Duration) *MarketToExchangePrices

NewMarketToExchangePrices creates a new MarketToExchangePrices.

func (*MarketToExchangePrices) GetValidMedianPrices

func (mte *MarketToExchangePrices) GetValidMedianPrices(
	marketParams []types.MarketParam,
	readTime time.Time,
) map[uint32]uint64

GetValidMedianPrices returns median prices for multiple markets. Specifically, it returns a map where the key is the market ID and the value is the median price for the market. It only returns "valid" prices where a price is valid iff 1) the last update time is within a predefined threshold away from the given read time. 2) the number of prices that meet 1) are greater than the minimum number of exchanges specified in the given input.

func (*MarketToExchangePrices) UpdatePrices

func (mte *MarketToExchangePrices) UpdatePrices(
	updates []*api.MarketPriceUpdate)

UpdatePrices updates market prices given a list of price updates. Prices are only updated if the timestamp on the updates are greater than the timestamp on existing prices.

Jump to

Keyboard shortcuts

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