Documentation
¶
Index ¶
- type AggregateFn
- type AggregatedProviderPrices
- type PriceAggregator
- func (p *PriceAggregator) GetPrices() map[types.CurrencyPair]*uint256.Int
- func (p *PriceAggregator) GetPricesByProvider(provider string) map[types.CurrencyPair]QuotePrice
- func (p *PriceAggregator) GetProviderPrices() AggregatedProviderPrices
- func (p *PriceAggregator) ResetProviderPrices()
- func (p *PriceAggregator) SetPrices(prices map[types.CurrencyPair]*uint256.Int)
- func (p *PriceAggregator) SetProviderPrices(provider string, prices map[types.CurrencyPair]QuotePrice)
- func (p *PriceAggregator) UpdatePrices()
- type Provider
- type ProviderConfig
- type QuotePrice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AggregateFn ¶
type AggregateFn func(providers AggregatedProviderPrices) map[types.CurrencyPair]*uint256.Int
AggregateFn is the function used to aggregate prices from each provider. Providers should be responsible for aggregating prices using TWAPs, TVWAPs, etc. The oracle will then compute the canonical price for a given currency pair by computing the median price across all providers.
func ComputeMedian ¶
func ComputeMedian() AggregateFn
ComputeMedian inputs the aggregated prices from all providers and computes the median price for each asset.
type AggregatedProviderPrices ¶
type AggregatedProviderPrices map[string]map[types.CurrencyPair]QuotePrice
AggregatedProviderPrices defines a type alias for a map of provider -> asset -> QuotePrice
type PriceAggregator ¶
type PriceAggregator struct {
// contains filtered or unexported fields
}
PriceAggregator is a simple aggregator for provider prices. It is thread-safe since it is assumed to be called concurrently in price fetching goroutines.
func NewPriceAggregator ¶
func NewPriceAggregator(aggregateFn AggregateFn) *PriceAggregator
NewPriceAggregator returns a PriceAggregator. The PriceAggregator is responsible for aggregating prices from each provider and computing the final oracle price for each asset. The PriceAggregator also tracks the current set of prices from each provider. The PricesAggregator is thread-safe since it is assumed to be called concurrently in price fetching goroutines.
func (*PriceAggregator) GetPrices ¶
func (p *PriceAggregator) GetPrices() map[types.CurrencyPair]*uint256.Int
GetPrices returns the aggregated prices based on the provided currency pairs.
func (*PriceAggregator) GetPricesByProvider ¶
func (p *PriceAggregator) GetPricesByProvider(provider string) map[types.CurrencyPair]QuotePrice
GetPricesByProvider returns the prices for a given provider.
func (*PriceAggregator) GetProviderPrices ¶
func (p *PriceAggregator) GetProviderPrices() AggregatedProviderPrices
GetProviderPrices returns a copy of the aggregated provider prices.
func (*PriceAggregator) ResetProviderPrices ¶
func (p *PriceAggregator) ResetProviderPrices()
ResetProviderPrices resets the price aggregator for all providers.
func (*PriceAggregator) SetPrices ¶
func (p *PriceAggregator) SetPrices(prices map[types.CurrencyPair]*uint256.Int)
SetPrices sets the current set of prices.
func (*PriceAggregator) SetProviderPrices ¶
func (p *PriceAggregator) SetProviderPrices(provider string, prices map[types.CurrencyPair]QuotePrice)
SetQuotePrices updates the price aggregator with the latest ticker prices from the given provider.
func (*PriceAggregator) UpdatePrices ¶
func (p *PriceAggregator) UpdatePrices()
UpdatePrices updates the current set of prices by using the aggregate function.
type Provider ¶
type Provider interface {
// Name returns the name of the provider.
Name() string
// GetPrices returns the aggregated prices based on the provided currency pairs.
GetPrices(context.Context) (map[types.CurrencyPair]QuotePrice, error)
// SetPairs sets the pairs that the provider should fetch prices for.
SetPairs(...types.CurrencyPair)
// GetPairs returns the pairs that the provider is fetching prices for.
GetPairs() []types.CurrencyPair
}
Provider defines an interface an exchange price provider must implement.
type ProviderConfig ¶
type ProviderConfig struct {
// Name identifies which provider this config is for
Name string `mapstructure:"name" toml:"name"`
// Apikey is the api-key accompanying requests to the provider's API.
Apikey string `mapstructure:"apikey" toml:"apikey"`
// TokenNameToSymbol is a map of token names to their symbols, i.e how each token in the CurrencyPair should
// map to the token references in the queried provider's API.
TokenNameToSymbol map[string]string `mapstructure:"token_name_to_symbol"`
// ProviderTimeout is the maximum amount of time to wait for a response from the provider.
ProviderTimeout time.Duration `mapstructure:"provider_timeout"`
}
type QuotePrice ¶
type QuotePrice struct {
// Price tracks the quote price for a given CurrencyPair.
Price *uint256.Int
// Timestamp tracks the time at which the price was fetched.
Timestamp time.Time
}
QuotePrice defines price information for a given CurrencyPair provided by a price provider.
func NewQuotePrice ¶
NewQuotePrice returns a new QuotePrice.