tracker

package
v0.1.1-0...-94ed833 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2020 License: MIT Imports: 30 Imported by: 1

Documentation

Index

Constants

View Source
const GWEI = 1000000000

GWEI constant is the multiplier from Wei

Variables

View Source
var PSRs = map[int]ValueGenerator{
	1: &TimedSwitch{
		before: &SingleSymbol{symbol: "ETH/USD", granularity: 1000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "ETH/USD", granularity: 1000000, transform: MedianAt},
		at:     switchTime,
	},
	2: &TimedSwitch{
		before: &SingleSymbol{symbol: "BTC/USD", granularity: 1000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "BTC/USD", granularity: 1000000, transform: MedianAt},
		at:     switchTime,
	},
	3: &TimedSwitch{
		before: &SingleSymbol{symbol: "BNB/USD", granularity: 1000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "BNB/USD", granularity: 1000000, transform: MedianAt},
		at:     switchTime,
	},
	4: &TimedSwitch{
		before: &SingleSymbol{symbol: "BTC/USD", granularity: 100000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "BTC/USD", granularity: 1000000, transform: TimeWeightedAvg(24*time.Hour, ExpDecay)},
		at:     switchTime,
	},
	5: &SingleSymbol{symbol: "ETH/BTC", granularity: 1000000, transform: MedianAt},
	6: &SingleSymbol{symbol: "BNB/BTC", granularity: 1000000, transform: MedianAt},
	7: &SingleSymbol{symbol: "BNB/ETH", granularity: 1000000, transform: MedianAt},
	8: &TimedSwitch{
		before: &SingleSymbol{symbol: "ETH/USD", granularity: 1000000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "ETH/USD", granularity: 1000000, transform: TimeWeightedAvg(24*time.Hour, ExpDecay)},
		at:     switchTime,
	},
	9: &TimedSwitch{
		before: &SingleSymbol{symbol: "LINK/BTC", granularity: 1000000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "ETH/USD", granularity: 1000000, transform: MedianAtEOD},
		at:     switchTime,
	},
	10: &TimedSwitch{
		before: &SingleSymbol{symbol: "ETC/ETH", granularity: 1000000, transform: MedianAt},
		after:  &Ampl{granularity: 1000000},
		at:     switchTime,
	},
	11: &SingleSymbol{symbol: "ZEC/ETH", granularity: 1000000, transform: MedianAt},
	12: &SingleSymbol{symbol: "TRX/ETH", granularity: 1000000, transform: MedianAt},
	13: &TimedSwitch{
		before: &SingleSymbol{symbol: "XRP/BTC", granularity: 1000000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "XRP/USD", granularity: 1000000, transform: MedianAt},
		at:     switchTime,
	},
	14: &SingleSymbol{symbol: "XMR/ETH", granularity: 1000000, transform: MedianAt},
	15: &TimedSwitch{
		before: &SingleSymbol{symbol: "XLM/BTC", granularity: 1000000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "ATOM/USD", granularity: 1000000, transform: MedianAt},
		at:     switchTime,
	},
	16: &SingleSymbol{symbol: "LTC/USD", granularity: 1000000, transform: MedianAt},
	17: &SingleSymbol{symbol: "WAVES/BTC", granularity: 1000000, transform: MedianAt},
	18: &SingleSymbol{symbol: "REP/BTC", granularity: 1000000, transform: MedianAt},
	19: &SingleSymbol{symbol: "TUSD/ETH", granularity: 1000000, transform: MedianAt},
	20: &SingleSymbol{symbol: "EOS/USD", granularity: 1000000, transform: MedianAt},
	21: &SingleSymbol{symbol: "IOTA/USD", granularity: 1000000, transform: MedianAt},
	22: &SingleSymbol{symbol: "ETC/USD", granularity: 1000000, transform: MedianAt},
	23: &SingleSymbol{symbol: "ETH/PAX", granularity: 1000000, transform: MedianAt},
	24: &TimedSwitch{
		before: &SingleSymbol{symbol: "ETH/USD", granularity: 1000000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "ETH/BTC", granularity: 1000000, transform: TimeWeightedAvg(1*time.Hour, NoDecay)},
		at:     switchTime,
	},
	25: &SingleSymbol{symbol: "USDC/USDT", granularity: 1000000, transform: MedianAt},
	26: &TimedSwitch{
		before: &SingleSymbol{symbol: "RCN/BTC", granularity: 1000000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "XTZ/USD", granularity: 1000000, transform: MedianAt},
		at:     switchTime,
	},
	27: &SingleSymbol{symbol: "LINK/USD", granularity: 1000000, transform: MedianAt},
	28: &SingleSymbol{symbol: "ZRX/BNB", granularity: 1000000, transform: MedianAt},
	29: &SingleSymbol{symbol: "ZEC/USD", granularity: 1000000, transform: MedianAt},
	30: &TimedSwitch{
		before: &SingleSymbol{symbol: "DASH/BNB", granularity: 1000000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "XAU/USD", granularity: 1000000, transform: MedianAt},
		at:     switchTime,
	},
	31: &SingleSymbol{symbol: "MATIC/USD", granularity: 1000000, transform: MedianAt},
	32: &SingleSymbol{symbol: "BAT/USD", granularity: 1000000, transform: MedianAt},
	33: &SingleSymbol{symbol: "ALGO/USD", granularity: 1000000, transform: MedianAt},
	34: &SingleSymbol{symbol: "ZRX/USD", granularity: 1000000, transform: MedianAt},
	35: &SingleSymbol{symbol: "COS/USD", granularity: 1000000, transform: MedianAt},
	36: &SingleSymbol{symbol: "BCH/USD", granularity: 1000000, transform: MedianAt},
	37: &SingleSymbol{symbol: "REP/USD", granularity: 1000000, transform: MedianAt},
	38: &SingleSymbol{symbol: "GNO/USD", granularity: 1000000, transform: MedianAt},
	39: &SingleSymbol{symbol: "DAI/USD", granularity: 1000000, transform: MedianAt},
	40: &SingleSymbol{symbol: "STEEM/BTC", granularity: 1000000, transform: MedianAt},
	41: &TimedSwitch{
		before: &SingleSymbol{symbol: "LINK/USD", granularity: 1000000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "USPCE", granularity: 1000, transform: ManualEntry},
		at:     switchTime,
	},
	42: &TimedSwitch{
		before: &SingleSymbol{symbol: "WAN/BTC", granularity: 1000000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "BTC/USD", granularity: 1000000, transform: MedianAtEOD},
		at:     switchTime,
	},
	43: &TimedSwitch{
		before: &SingleSymbol{symbol: "GNT/ETH", granularity: 1000000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "TRB/ETH", granularity: 1000000, transform: MedianAt},
		at:     switchTime,
	},
	44: &TimedSwitch{
		before: &SingleSymbol{symbol: "BTC/USD", granularity: 1000000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "BTC/USD", granularity: 1000000, transform: TimeWeightedAvg(1*time.Hour, NoDecay)},
		at:     switchTime,
	},
	45: &TimedSwitch{
		before: &SingleSymbol{symbol: "BTC/USD", granularity: 1000000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "TRB/USD", granularity: 1000000, transform: MedianAtEOD},
		at:     switchTime,
	},
	46: &TimedSwitch{
		before: &SingleSymbol{symbol: "ETH/USD", granularity: 1000000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "ETH/USD", granularity: 1000000, transform: TimeWeightedAvg(1*time.Hour, NoDecay)},
		at:     switchTime,
	},
	47: &TimedSwitch{
		before: &SingleSymbol{symbol: "LTC/USD", granularity: 1000000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "BSV/USD", granularity: 1000000, transform: MedianAt},
		at:     switchTime,
	},
	48: &SingleSymbol{symbol: "MAKER/USD", granularity: 1000000, transform: MedianAt},
	49: &TimedSwitch{
		before: &SingleSymbol{symbol: "EOS/USD", granularity: 1000000, transform: MedianAt},
		after:  &SingleSymbol{symbol: "BCH/USD", granularity: 1000000, transform: TimeWeightedAvg(24*time.Hour, NoDecay)},
		at:     switchTime,
	},
	50: &SingleSymbol{symbol: "TRB/USD", granularity: 1000000, transform: MedianAt},
	51: &SingleSymbol{symbol: "XMR/USD", granularity: 1000000, transform: MedianAt},
	52: &SingleSymbol{symbol: "XFT/USD", granularity: 1000000, transform: MedianAt},
	53: &SingleSymbol{symbol: "BTCDOMINANCE", 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 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

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

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 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 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 TributeTracker

type TributeTracker struct {
}

func (*TributeTracker) Exec

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

func (*TributeTracker) String

func (b *TributeTracker) String() string

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