volatile

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Name is the name of the provider.
	Name = "volatile-exchange-provider"
	// Offset is the average of the returned value from GetVolatilePrice.
	Offset = float64(100)
	// Amplitude is the magnitude of price variation of the cosine function used in GetVolatilePrice.
	Amplitude = float64(0.95)
	// Frequency sizes the repetition of the price curve in GetVolatilePrice.
	Frequency = float64(1)
)

Variables

View Source
var DefaultAPIConfig = config.APIConfig{
	Name:             Name,
	Enabled:          true,
	MaxQueries:       1,
	Timeout:          500 * time.Millisecond,
	Interval:         500 * time.Millisecond,
	ReconnectTimeout: 500 * time.Millisecond,
	Endpoints:        []config.Endpoint{{URL: Name}},
}

DefaultAPIConfig is required by the oracle to run. Most fields are ignored.

Functions

func GetVolatilePrice

func GetVolatilePrice(tp TimeProvider, amplitude float64, offset float64, frequency float64) *big.Float

GetVolatilePrice generates a time-based price value. The value follows a cosine wave function, but that includes jumps from the lowest value to the highest value (and vice versa) once per period. The general formula is written below. - price = offset * (1 + amplitude * cosVal) - cosVal = math.Cos(radians) - radians = (cosinePhase <= 0.5 ? cosinePhase * 4 : cosinePhase * 4 - 1) * π - cosinePhase = (frequency * unix_time(in seconds) / dailySeconds) % 1.

func NewAPIHandler

func NewAPIHandler() types.PriceAPIDataHandler

NewAPIHandler is invoked by the API factory to create the volatile api handler.

Types

type APIHandler

type APIHandler struct{}

APIHandler implements the APIHandler interface.

func (*APIHandler) CreateURL

func (v *APIHandler) CreateURL(_ []types.ProviderTicker) (string, error)

CreateURL is a no-op in volatile api handler.

func (*APIHandler) ParseResponse

func (v *APIHandler) ParseResponse(tickers []types.ProviderTicker, _ *http.Response) types.PriceResponse

ParseResponse returns the same volatile price for each ticker.

type TimeProvider

type TimeProvider func() time.Time

Jump to

Keyboard shortcuts

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