oracle

package
v1.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeStandardDeviationsAndMeans

func ComputeStandardDeviationsAndMeans(prices map[provider.Name]map[string]sdk.Dec) (map[string]sdk.Dec, map[string]sdk.Dec, error)

ComputeStandardDeviationsAndMeans returns maps of the standard deviations and means of assets. Will skip calculating for an asset if there are less than 3 prices.

func ComputeTVWAP

func ComputeTVWAP(prices provider.AggregatedProviderCandles) (map[string]sdk.Dec, error)

ComputeTVWAP computes the time volume weighted average price for all points for each exchange pair. Filters out any candles that did not occur within timePeriod. The provided prices argument reflects a mapping of provider => {<base> => <TickerPrice>, ...}.

Ref : https://en.wikipedia.org/wiki/Time-weighted_average_price

func ComputeVWAP

func ComputeVWAP(prices provider.AggregatedProviderPrices) map[string]sdk.Dec

ComputeVWAP computes the volume weighted average price for all price points for each ticker/exchange pair. The provided prices argument reflects a mapping of provider => {<base> => <TickerPrice>, ...}.

Ref: https://en.wikipedia.org/wiki/Volume-weighted_average_price

func ConvertCandlesToUSD

func ConvertCandlesToUSD(
	logger zerolog.Logger,
	candles provider.AggregatedProviderCandles,
	providerPairs map[provider.Name][]types.CurrencyPair,
	deviationThresholds map[string]sdk.Dec,
) (provider.AggregatedProviderCandles, error)

ConvertCandlesToUSD converts any candles which are not quoted in USD to USD by other price feeds. It will also filter out any candles not within the deviation threshold set by the config.

func ConvertTickersToUSD

func ConvertTickersToUSD(
	logger zerolog.Logger,
	tickers provider.AggregatedProviderPrices,
	providerPairs map[provider.Name][]types.CurrencyPair,
	deviationThresholds map[string]sdk.Dec,
) (provider.AggregatedProviderPrices, error)

ConvertTickersToUSD converts any tickers which are not quoted in USD to USD, using the conversion rates of other tickers. It will also filter out any tickers not within the deviation threshold set by the config.

func FilterTickerDeviations

func FilterTickerDeviations(
	logger zerolog.Logger,
	prices provider.AggregatedProviderPrices,
	deviationThresholds map[string]sdk.Dec,
) (provider.AggregatedProviderPrices, error)

FilterTickerDeviations finds the standard deviations of the prices of all assets, and filters out any providers that are not within 2𝜎 of the mean.

func NewProvider

func NewProvider(
	ctx context.Context,
	providerName provider.Name,
	logger zerolog.Logger,
	endpoint provider.Endpoint,
	providerPairs ...types.CurrencyPair,
) (provider.Provider, error)

func SetProviderTickerPricesAndCandles

func SetProviderTickerPricesAndCandles(
	providerName provider.Name,
	providerPrices provider.AggregatedProviderPrices,
	providerCandles provider.AggregatedProviderCandles,
	prices map[string]types.TickerPrice,
	candles map[string][]types.CandlePrice,
	pair types.CurrencyPair,
) (success bool)

SetProviderTickerPricesAndCandles flattens and collects prices for candles and tickers based on the base currency per provider. Returns true if at least one of price or candle exists.

Types

type Oracle

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

Oracle implements the core component responsible for fetching exchange rates for a given set of currency pairs and determining the correct exchange rates to submit to the on-chain price oracle adhering the oracle specification.

func New

func New(
	logger zerolog.Logger,
	oc client.OracleClient,
	currencyPairs []config.CurrencyPair,
	providerTimeout time.Duration,
	deviations map[string]sdk.Dec,
	endpoints map[provider.Name]provider.Endpoint,
) *Oracle

func (*Oracle) GetComputedPrices

func (o *Oracle) GetComputedPrices(
	providerCandles provider.AggregatedProviderCandles,
	providerPrices provider.AggregatedProviderPrices,
	providerPairs map[provider.Name][]types.CurrencyPair,
	deviations map[string]sdk.Dec,
) (prices map[string]sdk.Dec, err error)

GetComputedPrices gets the candle and ticker prices and computes it. It returns candles' TVWAP if possible, if not possible (not available or due to some staleness) it will use the most recent ticker prices and the VWAP formula instead.

func (*Oracle) GetLastPriceSyncTimestamp

func (o *Oracle) GetLastPriceSyncTimestamp() time.Time

GetLastPriceSyncTimestamp returns the latest timestamp at which prices where fetched from the oracle's set of exchange rate providers.

func (*Oracle) GetPrices

func (o *Oracle) GetPrices() map[string]sdk.Dec

GetPrices returns a copy of the current prices fetched from the oracle's set of exchange rate providers.

func (*Oracle) GetTVWAPPrices

func (o *Oracle) GetTVWAPPrices() PricesByProvider

GetTVWAPPrices returns a copy of the tvwapsByProvider map.

func (*Oracle) GetVWAPPrices

func (o *Oracle) GetVWAPPrices() PricesByProvider

GetVWAPPrices returns the vwapsByProvider map using a read lock.

func (*Oracle) Start

func (o *Oracle) Start(ctx context.Context) error

Start starts the oracle process in a blocking fashion.

func (*Oracle) Stop

func (o *Oracle) Stop()

Stop stops the oracle process and waits for it to gracefully exit.

type ParamCache

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

ParamCache is used to cache oracle param data for an amount of blocks, defined by paramsCacheInterval.

func (*ParamCache) IsOutdated

func (paramCache *ParamCache) IsOutdated(currentBlockHeigh int64) bool

IsOutdated checks whether or not the current param data was fetched in the last 200 blocks.

func (*ParamCache) Update

func (paramCache *ParamCache) Update(currentBlockHeigh int64, params oracletypes.Params)

Update retrieves the most recent oracle params and updates the instance.

type PreviousPrevote

type PreviousPrevote struct {
	ExchangeRates     string
	Salt              string
	SubmitBlockHeight int64
}

PreviousPrevote defines a structure for defining the previous prevote submitted on-chain.

type PricesByProvider

type PricesByProvider map[provider.Name]map[string]sdk.Dec

type PricesWithMutex

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

func (*PricesWithMutex) GetPricesClone

func (pwm *PricesWithMutex) GetPricesClone() PricesByProvider

GetPricesClone retrieves a clone of PricesWithMutex.prices surrounded by a read lock.

func (*PricesWithMutex) SetPrices

func (pwm *PricesWithMutex) SetPrices(prices PricesByProvider)

SetPrices sets the PricesWithMutex.prices value surrounded by a write lock.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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