Documentation ¶
Index ¶
- func ComputeTVWAP(prices provider.AggregatedProviderCandles) (map[string]sdk.Dec, error)
- func ComputeTvwapsByProvider(prices provider.AggregatedProviderCandles) (map[provider.Name]map[string]sdk.Dec, error)
- func ComputeVWAP(prices provider.AggregatedProviderPrices) map[string]sdk.Dec
- func ComputeVwapsByProvider(prices provider.AggregatedProviderPrices) map[provider.Name]map[string]sdk.Dec
- func Connect(protoAddr string) (net.Conn, error)
- func ConvertCandlesToUSD(logger zerolog.Logger, candles provider.AggregatedProviderCandles, ...) (provider.AggregatedProviderCandles, error)
- func ConvertTickersToUSD(logger zerolog.Logger, tickers provider.AggregatedProviderPrices, ...) (provider.AggregatedProviderPrices, error)
- func FilterCandleDeviations(logger zerolog.Logger, candles provider.AggregatedProviderCandles, ...) (provider.AggregatedProviderCandles, error)
- func FilterTickerDeviations(logger zerolog.Logger, prices provider.AggregatedProviderPrices, ...) (provider.AggregatedProviderPrices, error)
- func GenerateExchangeRatesString(prices map[string]sdk.Dec) string
- func GenerateSalt(length int) (string, error)
- func NewProvider(ctx context.Context, providerName provider.Name, logger zerolog.Logger, ...) (provider.Provider, error)
- func ProtocolAndAddress(listenAddr string) (string, string)
- func SetProviderTickerPricesAndCandles(providerName provider.Name, providerPrices provider.AggregatedProviderPrices, ...) (success bool)
- func StandardDeviation(prices map[provider.Name]map[string]sdk.Dec) (map[string]sdk.Dec, map[string]sdk.Dec, error)
- type Oracle
- func (o *Oracle) GetComputedPrices(providerCandles provider.AggregatedProviderCandles, ...) (prices map[string]sdk.Dec, err error)
- func (o *Oracle) GetLastPriceSyncTimestamp() time.Time
- func (o *Oracle) GetParamCache(ctx context.Context, currentBlockHeigh int64) (oracletypes.Params, error)
- func (o *Oracle) GetParams(ctx context.Context) (oracletypes.Params, error)
- func (o *Oracle) GetPrices() map[string]sdk.Dec
- func (o *Oracle) GetTvwapPrices() PricesByProvider
- func (o *Oracle) GetVwapPrices() PricesByProvider
- func (o *Oracle) SetPrices(ctx context.Context) error
- func (o *Oracle) Start(ctx context.Context) error
- func (o *Oracle) Stop()
- type ParamCache
- type PreviousPrevote
- type PricesByProvider
- type PricesWithMutex
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeTVWAP ¶
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 ComputeTvwapsByProvider ¶
func ComputeTvwapsByProvider(prices provider.AggregatedProviderCandles) (map[provider.Name]map[string]sdk.Dec, error)
ComputeTvwapsByProvider computes the tvwap prices from candles for each provider separately and returns them in a map separated by provider name
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 ComputeVwapsByProvider ¶
func ComputeVwapsByProvider(prices provider.AggregatedProviderPrices) map[provider.Name]map[string]sdk.Dec
ComputeVwapsByProvider computes the vwap prices from tickers for each provider separately and returns them in a map separated by provider name
func Connect ¶
Connect dials the given address and returns a net.Conn. The protoAddr argument should be prefixed with the protocol, eg. "tcp://127.0.0.1:8080" or "unix:///tmp/test.sock".
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 FilterCandleDeviations ¶
func FilterCandleDeviations( logger zerolog.Logger, candles provider.AggregatedProviderCandles, deviationThresholds map[string]sdk.Dec, ) (provider.AggregatedProviderCandles, error)
FilterCandleDeviations finds the standard deviations of the tvwaps of all assets, and filters out any providers that are not within 2𝜎 of the mean.
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 GenerateExchangeRatesString ¶
GenerateExchangeRatesString generates a canonical string representation of the aggregated exchange rates.
func GenerateSalt ¶
GenerateSalt generates a random salt, size length/2, as a HEX encoded string.
func NewProvider ¶
func ProtocolAndAddress ¶
ProtocolAndAddress splits an address into the protocol and address components. For instance, "tcp://127.0.0.1:8080" will be split into "tcp" and "127.0.0.1:8080". If the address has no protocol prefix, the default is "tcp".
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 (*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 ¶
GetLastPriceSyncTimestamp returns the latest timestamp at which prices where fetched from the oracle's set of exchange rate providers.
func (*Oracle) GetParamCache ¶
func (o *Oracle) GetParamCache(ctx context.Context, currentBlockHeigh int64) (oracletypes.Params, error)
GetParamCache returns the last updated parameters of the x/oracle module if the current ParamCache is outdated, we will query it again.
func (*Oracle) GetParams ¶
GetParams returns the current on-chain parameters of the x/oracle module.
func (*Oracle) GetPrices ¶
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) SetPrices ¶
SetPrices retrieves all the prices and candles from our set of providers as determined in the config. If candles are available, uses TVWAP in order to determine prices. If candles are not available, uses the most recent prices with VWAP. Warns the the user of any missing prices, and filters out any faulty providers which do not report prices or candles within 2𝜎 of the others.
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 ¶
PreviousPrevote defines a structure for defining the previous prevote submitted on-chain.
func NewPreviousPrevote ¶
func NewPreviousPrevote() *PreviousPrevote
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