tracker

package
v0.0.0-...-7d63ed4 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2022 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const GWEI = 1000000000

GWEI constant is the multiplier from Wei

Variables

View Source
var PSRs = map[int]ValueGenerator{
	1: &SingleSymbol{symbol: "ZAP/USD", granularity: 1000000, transform: MedianAt},
	2: &SingleSymbol{symbol: "BTC/USD", granularity: 1000000, transform: MedianAt},
	3: &SingleSymbol{symbol: "ETH/USD", granularity: 1000000, transform: MedianAt},
	4: &SingleSymbol{symbol: "LTC/USD", granularity: 1000000, transform: MedianAt},
	5: &SingleSymbol{symbol: "XRP/USD", granularity: 1000000, transform: MedianAt},
	6: &SingleSymbol{symbol: "BNB/USD", granularity: 1000000, transform: MedianAt},

	7:  &SingleSymbol{symbol: "DOGE/USD", granularity: 1000000, transform: MedianAt},
	8:  &SingleSymbol{symbol: "BCH/USD", granularity: 1000000, transform: MedianAt},
	9:  &SingleSymbol{symbol: "BSV/USD", granularity: 1000000, transform: MedianAt},
	10: &SingleSymbol{symbol: "EOS/USD", granularity: 1000000, transform: MedianAt},
	11: &SingleSymbol{symbol: "ETC/USD", granularity: 1000000, transform: MedianAt},

	12: &SingleSymbol{symbol: "ADA/USD", granularity: 1000000, transform: MedianAt},
	13: &SingleSymbol{symbol: "DOT/USD", granularity: 1000000, transform: MedianAt},
	14: &SingleSymbol{symbol: "UNI/USD", granularity: 1000000, transform: MedianAt},
	15: &SingleSymbol{symbol: "LINK/USD", granularity: 1000000, transform: MedianAt},

	16: &SingleSymbol{symbol: "XCD/USD", granularity: 1000000, transform: MedianAt},
	17: &SingleSymbol{symbol: "TTD/USD", granularity: 1000000, transform: MedianAt},
	18: &SingleSymbol{symbol: "JMD/USD", granularity: 1000000, transform: MedianAt},
	19: &SingleSymbol{symbol: "BBD/USD", granularity: 1000000, transform: MedianAt},
	20: &SingleSymbol{symbol: "KYD/USD", granularity: 1000000, transform: MedianAt},
	21: &SingleSymbol{symbol: "BSD/USD", granularity: 1000000, transform: MedianAt},
	22: &SingleSymbol{symbol: "BZD/USD", granularity: 1000000, transform: MedianAt},
	23: &SingleSymbol{symbol: "HTG/USD", granularity: 1000000, transform: MedianAt},
	24: &SingleSymbol{symbol: "SRD/USD", granularity: 1000000, transform: MedianAt},
	25: &SingleSymbol{symbol: "BMD/USD", granularity: 1000000, transform: MedianAt},
	26: &SingleSymbol{symbol: "AUD/USD", granularity: 1000000, transform: MedianAt},
	27: &SingleSymbol{symbol: "GBP/USD", granularity: 1000000, transform: MedianAt},
	28: &SingleSymbol{symbol: "CAD/USD", granularity: 1000000, transform: MedianAt},
	29: &SingleSymbol{symbol: "DKK/USD", granularity: 1000000, transform: MedianAt},
	30: &SingleSymbol{symbol: "EUR/USD", granularity: 1000000, transform: MedianAt},
	31: &SingleSymbol{symbol: "HKD/USD", granularity: 1000000, transform: MedianAt},
	32: &SingleSymbol{symbol: "JPY/USD", granularity: 1000000, transform: MedianAt},
	33: &SingleSymbol{symbol: "NZD/USD", granularity: 1000000, transform: MedianAt},
	34: &SingleSymbol{symbol: "NOK/USD", granularity: 1000000, transform: MedianAt},
	35: &SingleSymbol{symbol: "ZAR/USD", granularity: 1000000, transform: MedianAt},
	36: &SingleSymbol{symbol: "SEK/USD", granularity: 1000000, transform: MedianAt},
	37: &SingleSymbol{symbol: "CHF/USD", granularity: 1000000, transform: MedianAt},
	38: &SingleSymbol{symbol: "TRY/USD", granularity: 1000000, transform: MedianAt},
	39: &SingleSymbol{symbol: "AED/USD", granularity: 1000000, transform: MedianAt},
	40: &SingleSymbol{symbol: "CNY/USD", granularity: 1000000, transform: MedianAt},
	41: &SingleSymbol{symbol: "THB/USD", granularity: 1000000, transform: MedianAt},
	42: &SingleSymbol{symbol: "INR/USD", granularity: 1000000, transform: MedianAt},
	43: &SingleSymbol{symbol: "SGD/USD", granularity: 1000000, transform: MedianAt},
	44: &SingleSymbol{symbol: "RUB/USD", granularity: 1000000, transform: MedianAt},
	45: &SingleSymbol{symbol: "KRW/USD", granularity: 1000000, transform: MedianAt},
}

Functions

func ExpDecay

func ExpDecay(x float64) (float64, float64)

these weight functions map values of x between 0 (brand new) and 1 (old) to weights between 0 and 1 also returns the integral of the weight over the range [0,1] weights the oldest data (1) as being 1/3 as important (1/e)

func InitPSRs

func InitPSRs() error

func LinearDecay

func LinearDecay(x float64) (float64, float64)

weights the oldest data at 0

func ManualEntry

func ManualEntry(apis []*IndexTracker, at time.Time) (apiOracle.PriceInfo, float64)

func Mean

func MeanAt

func MeanAt(apis []*IndexTracker, at time.Time) (apiOracle.PriceInfo, float64)

func Median

func Median(values []apiOracle.PriceInfo) apiOracle.PriceInfo

func MedianAt

func MedianAt(apis []*IndexTracker, at time.Time) (apiOracle.PriceInfo, float64)

func MedianAtEOD

func MedianAtEOD(apis []*IndexTracker, at time.Time) (apiOracle.PriceInfo, float64)

func NoDecay

func NoDecay(x float64) (float64, float64)

weights all data in the time interval evenly

func PSRValueForTime

func PSRValueForTime(requestID int, at time.Time) (float64, float64)

func PrepareEthTransaction

func PrepareEthTransaction(ctx context.Context) (*bind.TransactOpts, error)

func UpdatePSRs

func UpdatePSRs(ctx context.Context, updatedSymbols []string) error

func VolumeWeightedAvg

func VolumeWeightedAvg(vals []apiOracle.PriceInfo) apiOracle.PriceInfo

Types

type Ampl

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

func (Ampl) Require

func (a Ampl) Require(at time.Time) map[string]IndexProcessor

func (Ampl) ValueAt

func (a Ampl) ValueAt(vals map[string]apiOracle.PriceInfo, at time.Time) float64

type BalanceTracker

type BalanceTracker struct {
}

BalanceTracker concrete tracker type

func (*BalanceTracker) Exec

func (b *BalanceTracker) Exec(ctx context.Context) error

Exec implementation for tracker

func (*BalanceTracker) String

func (b *BalanceTracker) String() string

Returns the BalanceTracker name

type ChainedPrice

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

ChainedPrice computes a pair that doesn't exist by using multiple symbols

type CurrentVariablesTracker

type CurrentVariablesTracker struct {
}

CurrentVariablesTracker concrete tracker type

func (*CurrentVariablesTracker) Exec

Exec implementation for tracker

func (*CurrentVariablesTracker) String

func (b *CurrentVariablesTracker) String() string

Returns the CurrentVariablesTracker name

type DataSource

type DataSource interface {
	Get() ([]byte, error)
}

type DisputeTracker

type DisputeTracker struct {
}

DisputeTracker struct

func (*DisputeTracker) Exec

func (b *DisputeTracker) Exec(ctx context.Context) error

Exec - Places the Dispute Status in the database

func (*DisputeTracker) String

func (b *DisputeTracker) String() string

type FetchRequest

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

FetchRequest holds info for a request TODO: add mock fetch

type GasPriceModel

type GasPriceModel struct {
	Fast    float32 `json:"fast"`
	Fastest float32 `json:"fastest"`
	Average float32 `json:"average"`
}

GasPriceModel is what ETHGasStation returns from queries. Not all fields are filled in

type GasTracker

type GasTracker struct {
}

GasTracker is the struct that maintains the latest gasprices. note the prices are actually stored in the DB

func (*GasTracker) Exec

func (b *GasTracker) Exec(ctx context.Context) error

Exec queries EthGasStation for the current Gas Prices

func (*GasTracker) String

func (b *GasTracker) String() string

type IndexProcessor

type IndexProcessor func([]*IndexTracker, time.Time) (apiOracle.PriceInfo, float64)

a function to consolidate the recorded API values to a single value

func AmpleChained

func AmpleChained(chainedPair string) IndexProcessor

compute the average ampl price over a 24 hour period using a chained price feed

func TimeWeightedAvg

func TimeWeightedAvg(interval time.Duration, weightFn func(float64) (float64, float64)) IndexProcessor

func VolumeWeightedAPIs

func VolumeWeightedAPIs(processor IndexProcessor) IndexProcessor

type IndexTracker

type IndexTracker struct {
	Name       string
	Identifier string
	Symbols    []string
	Source     DataSource
	Args       [][]string
}

func (*IndexTracker) Exec

func (i *IndexTracker) Exec(ctx context.Context) error

func (*IndexTracker) String

func (i *IndexTracker) String() string

type JSONapi

type JSONapi struct {
	Request *FetchRequest
}

func (*JSONapi) Get

func (j *JSONapi) Get() ([]byte, error)

type JSONfile

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

func (*JSONfile) Get

func (j *JSONfile) Get() ([]byte, error)

type NewCurrentVariablesTracker

type NewCurrentVariablesTracker struct {
}

CurrentVariablesTracker concrete tracker type

func (*NewCurrentVariablesTracker) Exec

Exec implementation for tracker

func (*NewCurrentVariablesTracker) String

func (b *NewCurrentVariablesTracker) String() string

type Runner

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

Runner will execute all configured trackers

func NewRunner

func NewRunner(client rpc.ETHClient, db db.DB) (*Runner, error)

NewRunner will create a new runner instance

func (*Runner) Ready

func (r *Runner) Ready() chan bool

Ready provides notification channel to know that the tracker data output is ready for use

func (*Runner) Start

func (r *Runner) Start(ctx context.Context, exitCh chan int) error

Start will kick off the runner until the given exit channel selects.

type SingleSymbol

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

func (SingleSymbol) Require

func (s SingleSymbol) Require(at time.Time) map[string]IndexProcessor

func (SingleSymbol) ValueAt

func (s SingleSymbol) ValueAt(vals map[string]apiOracle.PriceInfo, at time.Time) float64

type TallyVotesTracker

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

func (*TallyVotesTracker) Exec

func (b *TallyVotesTracker) Exec(ctx context.Context) error

func (*TallyVotesTracker) String

func (b *TallyVotesTracker) String() string

type TimeOutTracker

type TimeOutTracker struct {
}

TimeOutTracker struct

func (*TimeOutTracker) Exec

func (b *TimeOutTracker) Exec(ctx context.Context) error

Exec - Places the Dispute Status in the database

func (*TimeOutTracker) String

func (b *TimeOutTracker) String() string

type TimedSwitch

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

func (*TimedSwitch) Require

func (t *TimedSwitch) Require(at time.Time) map[string]IndexProcessor

func (*TimedSwitch) ValueAt

func (t *TimedSwitch) ValueAt(vals map[string]apiOracle.PriceInfo, at time.Time) float64

type TokenTracker

type TokenTracker struct {
}

func (*TokenTracker) Exec

func (b *TokenTracker) Exec(ctx context.Context) error

func (*TokenTracker) String

func (b *TokenTracker) String() string

type Tracker

type Tracker interface {
	//Exec will be run as a go function. The given context will be a KeyValue context containing
	//the client to use for tracking ops.
	Exec(ctx context.Context) error
	String() string
}

Tracker is the primary interface for the various tracking options

func BuildIndexTrackers

func BuildIndexTrackers() ([]Tracker, error)

BuildIndexTrackers creates and initializes a new tracker instance

type ValueCheckResult

type ValueCheckResult struct {
	High, Low   float64
	WithinRange bool
	Datapoints  []float64
	Times       []time.Time
}

ValueCheckResult holds the details regarding the disputed value

func CheckValueAtTime

func CheckValueAtTime(reqID uint64, val *big.Int, at time.Time) *ValueCheckResult

CheckValueAtTime queries for the details regarding the disputed value

type ValueGenerator

type ValueGenerator interface {
	//PSRs report what they require to produce a value with this
	Require(time.Time) map[string]IndexProcessor

	//return the best estimate of a value at a given time, and the confidence
	// if confidence == 0, the value has no meaning
	ValueAt(map[string]apiOracle.PriceInfo, time.Time) float64
}

Jump to

Keyboard shortcuts

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