Documentation ¶
Index ¶
Constants ¶
const StaticNumberPrecision = 1e18
StaticNumberPrecision is a precision of static numbers. Thw number is multiplied by this value before being marshaled.
const TickPricePrecision = 18
TickPricePrecision specified number of decimal places for tick prices during marshaling.
const TickVolumePrecision = 18
TickVolumePrecision specified number of decimal places for tick volumes during marshaling.
Variables ¶
This section is empty.
Functions ¶
func MarshalBinary ¶
MarshalBinary serializes a Value to binary.
The output includes the type ID followed by the binary representation of the value.
func RegisterType ¶
RegisterType registers a new value type.
The type ID must be unique and not equal to 0.
Types ¶
type MarshalableValue ¶
type MarshalableValue interface { encoding.BinaryMarshaler Value }
MarshalableValue is a data point value which can be serialized to binary.
The interface must be implemented by using non-pointer receivers.
type NumericValue ¶
type NumericValue interface {
Number() *bn.FloatNumber
}
NumericValue is a data point value which is a number.
The interface must be implemented by using non-pointer receivers.
type Pair ¶
Pair represents an asset pair.
func PairFromString ¶
PairFromString returns a new Pair for given string. The string must be formatted as "BASE/QUOTE".
func (Pair) Empty ¶
Empty returns true if the pair is empty. Pair is considered empty if either base or quote is empty.
func (Pair) Invert ¶
Invert returns an inverted pair. For example, if the pair is "BTC/USD", then the inverted pair is "USD/BTC".
func (Pair) MarshalText ¶
MarshalText implements encoding.TextMarshaler interface.
func (*Pair) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler interface.
type StaticValue ¶
type StaticValue struct {
Value *bn.FloatNumber
}
StaticValue is a numeric value obtained from a static origin.
func (StaticValue) MarshalBinary ¶
func (s StaticValue) MarshalBinary() ([]byte, error)
MarshalBinary implements the Value interface.
func (StaticValue) Number ¶
func (s StaticValue) Number() *bn.FloatNumber
Number implements the NumericValue interface.
func (StaticValue) Print ¶
func (s StaticValue) Print() string
Print implements the Value interface.
func (*StaticValue) UnmarshalBinary ¶
func (s *StaticValue) UnmarshalBinary(bytes []byte) error
UnmarshalBinary implements the Value interface.
type Tick ¶
type Tick struct { // Pair is an asset pair for which this price is calculated. Pair Pair // Price is a price for the given asset pair. // Depending on the provider implementation, this price can be // a last trade price, an average of bid and ask prices, etc. // // Price is always non-nil if there is no error. Price *bn.FloatNumber // Volume24h is a 24h volume for the given asset pair presented in the // base currency. // // May be nil if the provider does not provide volume. Volume24h *bn.FloatNumber }
Tick contains a price, volume and other information for a given asset pair at a given time.
Before using this data, you should check if it is valid by calling Tick.Validate() method.
During marshaling, the price and volume are converted to fixed-point numbers with the precision specified by TickPricePrecision and TickVolumePrecision constants.
func (Tick) MarshalBinary ¶
MarshalBinary implements the Value interface.
func (Tick) MarshalJSON ¶
func (Tick) Number ¶
func (t Tick) Number() *bn.FloatNumber
Number implements the NumericValue interface.
func (*Tick) UnmarshalBinary ¶
UnmarshalBinary implements the Value interface.
func (*Tick) UnmarshalJSON ¶
type UnmarshalableValue ¶
type UnmarshalableValue interface { encoding.BinaryUnmarshaler Value }
UnmarshalableValue is a data point value which can be deserialized from binary.
The UnmarshalBinary must be implemented by using pointer receivers.
type ValidatableValue ¶
type ValidatableValue interface {
Validate() error
}
ValidatableValue is a data point value which can be validated.
The interface must be implemented by using non-pointer receivers.
type Value ¶
type Value interface { // Print returns a human-readable representation of the value. Print() string }
Value is a data point value.
A value can be anything, e.g. a number, a string, a struct, etc.
To be able to send values over the network, they must implement the MarshalableValue and UnmarshalableValue interfaces.
The interface must be implemented by using non-pointer receivers.
func UnmarshalBinary ¶
UnmarshalBinary deserializes a Value from binary.
The input is expected to start with the type ID, followed by the binary representation of the value.