base

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider[K providertypes.ResponseKey, V providertypes.ResponseValue] struct {
	// contains filtered or unexported fields
}

Provider implements a base provider that can be used to build other providers.

func NewProvider

func NewProvider[K providertypes.ResponseKey, V providertypes.ResponseValue](opts ...ProviderOption[K, V]) (*Provider[K, V], error)

NewProvider returns a new Base provider.

func (*Provider[K, V]) GetAPIConfig

func (p *Provider[K, V]) GetAPIConfig() config.APIConfig

GetAPIConfig returns the API configuration for the provider.

func (*Provider[K, V]) GetAPIHandler

func (p *Provider[K, V]) GetAPIHandler() apihandler.APIQueryHandler[K, V]

GetAPIHandler returns the API handler that the provider will use to fetch data.

func (*Provider[K, V]) GetData

func (p *Provider[K, V]) GetData() map[K]providertypes.ResolvedResult[V]

GetData returns the latest data recorded by the provider. The data is constantly updated by the provider's main loop and provides access to the latest data - prices in constant time.

func (*Provider[K, V]) GetIDs

func (p *Provider[K, V]) GetIDs() []K

GetIDs returns the set of IDs that the provider is responsible for fetching data for.

func (*Provider[K, V]) GetWebSocketHandler

func (p *Provider[K, V]) GetWebSocketHandler() wshandlers.WebSocketQueryHandler[K, V]

GetWebSocketHandler returns the WebSocket handler that the provider will use to fetch data.

func (*Provider[K, V]) IsRunning

func (p *Provider[K, V]) IsRunning() bool

IsRunning returns true if the provider is running.

func (*Provider[K, V]) Name

func (p *Provider[K, V]) Name() string

Name returns the name of the provider.

func (*Provider[K, V]) Start

func (p *Provider[K, V]) Start(ctx context.Context) error

Start starts the provider's main loop. The provider will fetch the data from the handler and continuously update the data. This blocks until the provider is stopped.

func (*Provider[K, V]) Stop

func (p *Provider[K, V]) Stop()

Stop stops the provider's main loop.

func (*Provider[K, V]) Type

func (p *Provider[K, V]) Type() providertypes.ProviderType

Type returns the type of data handler the provider uses.

func (*Provider[K, V]) Update

func (p *Provider[K, V]) Update(opts ...UpdateOption[K, V])

Update updates the provider with the given options.

type ProviderOption

type ProviderOption[K providertypes.ResponseKey, V providertypes.ResponseValue] func(*Provider[K, V])

ProviderOption is a function that can be used to modify a provider.

func WithAPIConfig

WithAPIConfig sets the APIConfig for the provider.

func WithAPIQueryHandler

WithAPIQueryHandler sets the APIQueryHandler for the provider. If your provider utilizes a API (HTTP) based provider, you should use this option to set the APIQueryHandler.

func WithIDs

WithIDs sets the IDs that the provider is responsible for fetching data for.

func WithLogger

WithLogger sets the logger for the provider.

func WithMetrics

WithMetrics sets the metrics implementation for the provider.

func WithName

WithName sets the name of the provider.

func WithWebSocketConfig

WithWebSocketConfig sets the WebSocketConfig for the provider.

func WithWebSocketQueryHandler

WithWebSocketQueryHandler sets the WebSocketQueryHandler for the provider. If your provider utilizes a websocket based provider, you should use this option to set the WebSocketQueryHandler.

type UpdateOption

type UpdateOption[K providertypes.ResponseKey, V providertypes.ResponseValue] func(*Provider[K, V])

UpdateOption are the options that can be used to update the provider.

func WithNewAPIHandler

func WithNewAPIHandler[K providertypes.ResponseKey, V providertypes.ResponseValue](
	apiHandler apihandler.APIQueryHandler[K, V],
) UpdateOption[K, V]

WithNewAPIHandler returns an option that sets the new API handler that the provider will use to fetch data.

func WithNewIDs

func WithNewIDs[K providertypes.ResponseKey, V providertypes.ResponseValue](ids []K) UpdateOption[K, V]

WithNewIDs returns an option that sets the new set of IDs that the provider is responsible for fetching data for.

func WithNewWebSocketHandler

func WithNewWebSocketHandler[K providertypes.ResponseKey, V providertypes.ResponseValue](
	wsHandler wshandlers.WebSocketQueryHandler[K, V],
) UpdateOption[K, V]

WithNewWebSocketHandler returns an option that sets the new WebSocket handler that the provider will use to fetch data.

Directories

Path Synopsis
api
websocket

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳