nodes

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2022 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Walk

func Walk(fn func(Node), nodes ...Node)

Types

type Aggregator

type Aggregator interface {
	Node
	Pair() gofer.Pair
	Price() AggregatorPrice
}

Aggregator represents a node which can aggregate prices from its children.

type AggregatorPrice

type AggregatorPrice struct {
	PairPrice
	// OriginPrices is a list of all OriginPrices used to calculate Price.
	OriginPrices []OriginPrice
	// AggregatorPrices is a list of all OriginPrices used to calculate Price.
	AggregatorPrices []AggregatorPrice
	// Parameters is a custom list of optional parameters returned by an aggregator.
	Parameters map[string]string
	// Errors is a list of optional error messages which may occur during
	// fetching Price. If this list is not empty, then the price value
	// is not reliable.
	Error error
}

AggregatorPrice represent a price which was calculated by using other prices.

type ErrDivByZero

type ErrDivByZero struct {
	PairA gofer.Pair
	PairB gofer.Pair
}

func (ErrDivByZero) Error

func (e ErrDivByZero) Error() string

type ErrIncompatiblePair

type ErrIncompatiblePair struct {
	Given    gofer.Pair
	Expected gofer.Pair
}

func (ErrIncompatiblePair) Error

func (e ErrIncompatiblePair) Error() string

type ErrIncompatiblePairs

type ErrIncompatiblePairs struct {
	Given    gofer.Pair
	Expected gofer.Pair
}

func (ErrIncompatiblePairs) Error

func (e ErrIncompatiblePairs) Error() string

type ErrInvalidPrice

type ErrInvalidPrice struct {
	Pair gofer.Pair
}

func (ErrInvalidPrice) Error

func (e ErrInvalidPrice) Error() string

type ErrNoCommonPart

type ErrNoCommonPart struct {
	PairA gofer.Pair
	PairB gofer.Pair
}

func (ErrNoCommonPart) Error

func (e ErrNoCommonPart) Error() string

type ErrNotEnoughSources

type ErrNotEnoughSources struct {
	Given int
	Min   int
}

func (ErrNotEnoughSources) Error

func (e ErrNotEnoughSources) Error() string

type ErrPrice

type ErrPrice struct {
	Pair gofer.Pair
	Err  error
}

func (ErrPrice) Error

func (e ErrPrice) Error() string

type ErrPriceTTLExpired

type ErrPriceTTLExpired struct {
	Price OriginPrice
	TTL   time.Duration
}

func (ErrPriceTTLExpired) Error

func (e ErrPriceTTLExpired) Error() string

type ErrResolve

type ErrResolve struct {
	ExpectedPair gofer.Pair
	ResolvedPair gofer.Pair
}

func (ErrResolve) Error

func (e ErrResolve) Error() string

type IncompatibleOriginErr

type IncompatibleOriginErr struct {
	Given    string
	Expected string
}

func (IncompatibleOriginErr) Error

func (e IncompatibleOriginErr) Error() string

type IndirectAggregatorNode

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

IndirectAggregatorNode calculates a price which is a cross rate between all child prices.

                           -- [Origin A/B]
                          /
[IndirectAggregatorNode] ---- [Origin B/C]       -- ...
                          \                     /
                           -- [Aggregator C/D] ---- ...
                                                \
                                                 -- ...

For above node, cross rate for the A/D pair will be calculated. It is important to add child nodes in the correct order, because prices will be calculated from first to last.

func NewIndirectAggregatorNode

func NewIndirectAggregatorNode(pair gofer.Pair) *IndirectAggregatorNode

func (*IndirectAggregatorNode) AddChild

func (n *IndirectAggregatorNode) AddChild(node Node)

AddChild implements the Parent interface.

func (*IndirectAggregatorNode) Children

func (n *IndirectAggregatorNode) Children() []Node

Children implements the Node interface.

func (*IndirectAggregatorNode) Pair

func (n *IndirectAggregatorNode) Pair() gofer.Pair

func (*IndirectAggregatorNode) Price

type MedianAggregatorNode

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

MedianAggregatorNode gets Prices from all of its children and calculates median price.

                         -- [Origin A/B]
                        /
[MedianAggregatorNode] ---- [Origin A/B]       -- ...
                        \                     /
                         -- [AggregatorNode A/B] ---- ...
                                              \
                                               -- ...

All children of this node must return a Price for the same pair.

func NewMedianAggregatorNode

func NewMedianAggregatorNode(pair gofer.Pair, minSources int) *MedianAggregatorNode

func (*MedianAggregatorNode) AddChild

func (n *MedianAggregatorNode) AddChild(node Node)

AddChild implements the Parent interface.

func (*MedianAggregatorNode) Children

func (n *MedianAggregatorNode) Children() []Node

Children implements the Node interface.

func (*MedianAggregatorNode) Pair

func (n *MedianAggregatorNode) Pair() gofer.Pair

func (*MedianAggregatorNode) Price

type Node

type Node interface {
	Children() []Node
}

Node represents generics node in a graph.

func DetectCycle

func DetectCycle(node Node) []Node

DetectCycle detects cycle in given graph. If cycle is detected then path is returned, otherwise empty slice.

type Origin

type Origin interface {
	Node
	OriginPair() OriginPair
	Price() OriginPrice
}

Origin represents a node which provides price directly from an origin.

type OriginNode

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

OriginNode contains a Price fetched directly from an origin.

func NewOriginNode

func NewOriginNode(originPair OriginPair, minTTL time.Duration, maxTTL time.Duration) *OriginNode

func (*OriginNode) Children

func (n *OriginNode) Children() []Node

Children implements the Node interface.

func (*OriginNode) Expired

func (n *OriginNode) Expired() bool

Expired implements the Feedable interface.

func (*OriginNode) Ingest

func (n *OriginNode) Ingest(price OriginPrice) error

Ingest implements Feedable interface.

func (*OriginNode) MaxTTL

func (n *OriginNode) MaxTTL() time.Duration

MaxTTL implements the Feedable interface.

func (*OriginNode) MinTTL

func (n *OriginNode) MinTTL() time.Duration

MinTTL implements the Feedable interface.

func (*OriginNode) OriginPair

func (n *OriginNode) OriginPair() OriginPair

OriginPair implements the Feedable interface.

func (*OriginNode) Price

func (n *OriginNode) Price() OriginPrice

Price implements the Feedable interface.

type OriginPair

type OriginPair struct {
	Origin string
	Pair   gofer.Pair
}

func (OriginPair) String

func (o OriginPair) String() string

type OriginPrice

type OriginPrice struct {
	PairPrice
	// Origin is a name of Price source.
	Origin string
	// Error is a list of optional error messages which may occur during
	// calculating the price. If this string is not empty, then the price
	// value is not reliable.
	Error error
}

OriginPrice represent a price which was sourced directly from an origin.

type PairPrice

type PairPrice struct {
	Pair      gofer.Pair
	Price     float64
	Bid       float64
	Ask       float64
	Volume24h float64
	Time      time.Time
}

type Parent

type Parent interface {
	Node
	AddChild(node Node)
}

Parent represents a node to which you can add a child node.

Jump to

Keyboard shortcuts

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