Documentation ¶
Overview ¶
Package datapoint and its subpackages offer utilities for retrieving and manipulating data points.
In this package, a data point represents a value from a specific source, or 'origin'. This value could represent anything, such as the price of an asset at a specific time.
Different data point types are represented as unique types that implement the Value interface from the value package. All of these types must support binary marshalling, which is essential for transmission across the transport layer.
A provider is a service that produces data points. All providers must implement the Provider interface. Currently, the only implementation of the Provider interface comes from the graph package.
The graph package uses a graph structure to calculate data points. Instead of directly fetching data points from origins, it allows for manipulation, aggregation, filtering of data points before delivering them. For instance, a graph can calculate the median value from multiple origins, compute indirect prices if direct prices are unavailable. For instance, if the direct ETH/BTC price is not available, it can be calculated using ETH/USD and USD/BTC prices.
A specific graph within this system is often referred to as a 'model'. However, within this package, the Model is a simple structure that is designed to help users understand how data points are calculated and retrieved.
The signer package is responsible for data point signing. A data point may be signed by a feed prior to being sent to the transport layer.
The store package facilitates storing of data points received from the transport layer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Model ¶
type Model struct { // Meta contains metadata for the model. It should contain information // about the model and its parameters. // // The "type" metadata field is used to determine the type of the model. // // Meta values must be marshalable to JSON. Meta map[string]any // Models is a list of sub models used to calculate price. Models []Model }
Model is a simplified representation of a model which is used to obtain a data point. The main purpose of this structure is to help the end user to understand how data points values are calculated and obtained.
This structure is purely informational. The way it is used depends on a specific implementation.
func (Model) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Model) MarshalTrace ¶
MarshalTrace returns a human-readable representation of the model.
type Point ¶
type Point struct { // Value is the value of the data point. Value value.Value // Time is the time when the data point was obtained. Time time.Time // SubPoints is a list of sub data points that are used to obtain this // data point. SubPoints []Point // Meta contains metadata for the data point. It may contain additional // information about the data point, such as the origin it was obtained // from, etc. // // Meta values must be marshalable to JSON. Meta map[string]any // Error is an optional error which occurred during obtaining the price. // If error is not nil, then the price is invalid and should not be used. // // Point may be invalid for other reasons, hence you should always check // the data point for validity by calling Point.Validate() method. Error error }
Point represents a data point. It can represent any value obtained from an origin. It can be a price, a volume, a market cap, etc. The value itself is represented by the Value interface and can be anything, a number, a string, or even a complex structure.
Before using this data, you should check if it is valid by calling Point.Validate() method.
func (Point) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (Point) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Point) MarshalTrace ¶
MarshalTrace returns a human-readable representation of the tick.
func (*Point) UnmarshalBinary ¶
type Provider ¶
type Provider interface { // ModelNames returns a list of supported data models. ModelNames(ctx context.Context) []string // DataPoint returns a data point for the given model. DataPoint(ctx context.Context, model string) (Point, error) // DataPoints returns a map of data points for the given models. DataPoints(ctx context.Context, models ...string) (map[string]Point, error) // Model returns a price model for the given asset pair. Model(ctx context.Context, model string) (Model, error) // Models describes price models which are used to calculate prices. // If no pairs are specified, models for all pairs are returned. Models(ctx context.Context, models ...string) (map[string]Model, error) }
Provider provides data points.
A data point is a value obtained from a source. For example, a data point can be a price of an asset at a specific time obtained from an exchange.
A model describes how a data point is calculated and obtained. For example, a model can describe from which sources data points are obtained and how they are combined to calculate a final value. Details of how models work depend on a specific implementation.
type Recoverer ¶
type Recoverer interface { // Supports returns true if the recoverer supports the given data point. Supports(ctx context.Context, data Point) bool // Recover recovers the address from the given signature. Recover(ctx context.Context, model string, data Point, signature types.Signature) (*types.Address, error) }
Recoverer is responsible for recovering addresses from signatures.
type Signer ¶
type Signer interface { // Supports returns true if the signer supports the given data point. Supports(ctx context.Context, data Point) bool // Sign signs a data point using the given key. Sign(ctx context.Context, model string, data Point) (*types.Signature, error) }
Signer is responsible for signing data points.