Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorCode ¶
type ErrorCode int
ErrorCode is a type alias for an int error code.
const ( OK ErrorCode = 0 ErrorRateLimitExceeded ErrorCode = 1 ErrorUnknown ErrorCode = 2 ErrorUnknownPair ErrorCode = 3 ErrorUnableToCreateURL ErrorCode = 4 ErrorWebsocketStartFail ErrorCode = 5 ErrorInvalidAPIChains ErrorCode = 6 ErrorNoResponse ErrorCode = 7 ErrorInvalidResponse ErrorCode = 8 ErrorInvalidChainID ErrorCode = 9 ErrorFailedToParsePrice ErrorCode = 10 ErrorInvalidWebSocketTopic ErrorCode = 11 ErrorFailedToDecode ErrorCode = 12 ErrorAPIGeneral ErrorCode = 13 ErrorWebSocketGeneral ErrorCode = 14 ErrorGRPCGeneral ErrorCode = 15 ErrorNoExistingPrice ErrorCode = 16 ErrorTickerMetadataNotFound ErrorCode = 17 )
type ErrorWithCode ¶
type ErrorWithCode struct {
// contains filtered or unexported fields
}
func NewErrorWithCode ¶
func NewErrorWithCode(err error, ec ErrorCode) ErrorWithCode
func (ErrorWithCode) Code ¶
func (ec ErrorWithCode) Code() ErrorCode
Code returns the internal ErrorCode.
func (ErrorWithCode) Error ¶
func (ec ErrorWithCode) Error() string
Error returns an error string wrapping the internalErr and the error code.
type GetResponse ¶
type GetResponse[K ResponseKey, V ResponseValue] struct { Resolved map[K]ResolvedResult[V] UnResolved map[K]UnresolvedResult }
GetResponse is the GET response from the API data handler.
func NewGetResponse ¶
func NewGetResponse[K ResponseKey, V ResponseValue](resolved map[K]ResolvedResult[V], unresolved map[K]UnresolvedResult) GetResponse[K, V]
NewGetResponse creates a new GetResponse.
func NewGetResponseWithErr ¶
func NewGetResponseWithErr[K ResponseKey, V ResponseValue](ids []K, err ErrorWithCode) GetResponse[K, V]
NewGetResponseWithErr creates a new GetResponse with the given error. This populates the unresolved map with the given IDs and error.
func (GetResponse[K, V]) String ¶
func (r GetResponse[K, V]) String() string
String returns a string representation of the GetResponse. This is mostly used for logging and testing purposes.
type Provider ¶
type Provider[K ResponseKey, V ResponseValue] interface { // Name returns the name of the provider. Name() string // GetData returns the aggregated data for the given (key, value) pairs. // For example, if the provider is fetching prices for a set of currency // pairs, the data returned by this function would be the latest prices // for those currency pairs. GetData() map[K]ResolvedResult[V] // Start starts the provider. Start(context.Context) error // Type returns the type of the provider data handler. Type() ProviderType // IsRunning returns whether the provider is running. IsRunning() bool }
Provider defines an interface a data provider must implement.
type ProviderType ¶
type ProviderType string
const ( WebSockets ProviderType = "websockets" API ProviderType = "api" )
type ResolvedResult ¶
type ResolvedResult[V ResponseValue] struct { // Value is the value of the requested ID. Value V // Timestamp is the timestamp of the value. Timestamp time.Time // ResponseCode is an optional code that can be attached to responses to provide // additional context. ResponseCode ResponseCode }
ResolvedResult is the result of a single requested ID.
func NewResult ¶
func NewResult[V ResponseValue](value V, timestamp time.Time) ResolvedResult[V]
NewResult creates a new ResolvedResult.
func NewResultWithCode ¶
func NewResultWithCode[V ResponseValue](value V, timestamp time.Time, code ResponseCode) ResolvedResult[V]
NewResultWithCode creates a new ResolvedResult with the given error code.
func (ResolvedResult[V]) String ¶
func (r ResolvedResult[V]) String() string
String returns a string representation of the ResolvedResult. This is mostly used for logging and testing purposes.
type ResponseCode ¶
type ResponseCode int
ResponseCode is an optional code that can be attached to responses to provide additional context.
const ( // ResponseCodeOK is a code that notifies the base provider that the response // is OK. ResponseCodeOK ResponseCode = 0 // ResponseCodeUnchange is a code that notifies the base provider that the response // is unchanged for the given ID. This is useful when the provider has a cache // and the value has not changed. ResponseCodeUnchanged ResponseCode = 1 )
func (ResponseCode) String ¶
func (r ResponseCode) String() string
type ResponseKey ¶
type ResponseKey interface {
comparable
fmt.Stringer
}
ResponseKey is a type restriction interface for the key of a GetResponse.
type ResponseValue ¶
ResponseValue is a type restriction interface for the value of a GetResponse.
type UnresolvedResult ¶
type UnresolvedResult struct {
ErrorWithCode
}
UnresolvedResult is an unresolved (failed) result of a single requested ID.