Documentation ¶
Index ¶
- func Walk(fn func(Node), nodes ...Node)
- type Aggregator
- type AggregatorPrice
- type ErrDivByZero
- type ErrIncompatiblePair
- type ErrIncompatiblePairs
- type ErrInvalidPrice
- type ErrNoCommonPart
- type ErrNotEnoughSources
- type ErrPrice
- type ErrPriceTTLExpired
- type ErrResolve
- type IncompatibleOriginErr
- type IndirectAggregatorNode
- type MedianAggregatorNode
- type Node
- type Origin
- type OriginNode
- func (n *OriginNode) Children() []Node
- func (n *OriginNode) Expired() bool
- func (n *OriginNode) Ingest(price OriginPrice) error
- func (n *OriginNode) MaxTTL() time.Duration
- func (n *OriginNode) MinTTL() time.Duration
- func (n *OriginNode) OriginPair() OriginPair
- func (n *OriginNode) Price() OriginPrice
- type OriginPair
- type OriginPrice
- type PairPrice
- type Parent
- type ReferenceNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Aggregator ¶
type Aggregator interface { Node Pair() provider.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 ¶
func (ErrDivByZero) Error ¶
func (e ErrDivByZero) Error() string
type ErrIncompatiblePair ¶
func (ErrIncompatiblePair) Error ¶
func (e ErrIncompatiblePair) Error() string
type ErrIncompatiblePairs ¶
func (ErrIncompatiblePairs) Error ¶
func (e ErrIncompatiblePairs) Error() string
type ErrInvalidPrice ¶
func (ErrInvalidPrice) Error ¶
func (e ErrInvalidPrice) Error() string
type ErrNoCommonPart ¶
func (ErrNoCommonPart) Error ¶
func (e ErrNoCommonPart) Error() string
type ErrNotEnoughSources ¶
func (ErrNotEnoughSources) Error ¶
func (e ErrNotEnoughSources) Error() string
type ErrPriceTTLExpired ¶
type ErrPriceTTLExpired struct { Price OriginPrice TTL time.Duration }
func (ErrPriceTTLExpired) Error ¶
func (e ErrPriceTTLExpired) Error() string
type ErrResolve ¶
func (ErrResolve) Error ¶
func (e ErrResolve) Error() string
type IncompatibleOriginErr ¶
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 provider.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() provider.Pair
func (*IndirectAggregatorNode) Price ¶
func (n *IndirectAggregatorNode) Price() AggregatorPrice
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 provider.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() provider.Pair
func (*MedianAggregatorNode) Price ¶
func (n *MedianAggregatorNode) Price() AggregatorPrice
type Node ¶
type Node interface {
Children() []Node
}
Node represents generics node in a graph.
func DetectCycle ¶
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 ¶
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 ReferenceNode ¶ added in v0.10.0
type ReferenceNode struct {
// contains filtered or unexported fields
}
ReferenceNode is a node that points to another node.
func NewReferenceNode ¶ added in v0.10.0
func NewReferenceNode() *ReferenceNode
func (*ReferenceNode) Children ¶ added in v0.10.0
func (n *ReferenceNode) Children() []Node
Children implements the Node interface.
func (*ReferenceNode) Pair ¶ added in v0.10.0
func (n *ReferenceNode) Pair() provider.Pair
func (*ReferenceNode) Price ¶ added in v0.10.0
func (n *ReferenceNode) Price() AggregatorPrice
func (*ReferenceNode) SetReference ¶ added in v0.10.0
func (n *ReferenceNode) SetReference(reference Node)