coinmarketcap

package
v1.0.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClient = errs.Class("Client")

ErrClient is an error class for coinmarketcap API client error.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is used to query the coinmarketcap API for the STORJ token price. implements tokenprice.Client interface.

func NewClient

func NewClient(config Config) *Client

NewClient returns a new token price client.

func (*Client) GetLatestPrice

func (c *Client) GetLatestPrice(ctx context.Context) (time.Time, currency.Amount, error)

GetLatestPrice gets the latest available ticker price. todo - verify fields in status, and add alerts.

func (*Client) GetPriceAt

func (c *Client) GetPriceAt(ctx context.Context, requestedTimestamp time.Time) (time.Time, currency.Amount, error)

GetPriceAt gets the ticker price at the specified time. todo - verify fields in status, and add alerts.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) (statusCode int, err error)

Ping checks that the coinmarketcap third-party api is available for use.

type Config

type Config struct {
	BaseURL string        `help:"base URL for ticker price API" default:"https://pro-api.coinmarketcap.com" testDefault:"$TESTBASEURL"`
	APIKey  string        `help:"API Key used to access coinmarketcap" default:"" testDefault:"$TESTAPIKEY"`
	Timeout time.Duration `help:"coinmarketcap API response timeout" default:"10s" testDefault:"$TESTTIMEOUT"`
}

Config holds coinmarketcap configuration.

type TestClient

type TestClient struct{}

TestClient implements the Client interface for test purposes (bypassing coinmarketcap 3rd party api calls).

func NewTestClient

func NewTestClient() *TestClient

NewTestClient returns a new test token price client.

func (*TestClient) GetLatestPrice

func (tc *TestClient) GetLatestPrice(ctx context.Context) (time.Time, currency.Amount, error)

GetLatestPrice gets the latest available ticker price.

func (*TestClient) GetPriceAt

func (tc *TestClient) GetPriceAt(ctx context.Context, requestedTimestamp time.Time) (time.Time, currency.Amount, error)

GetPriceAt gets the ticker price at the specified time.

func (*TestClient) Ping

func (tc *TestClient) Ping(ctx context.Context) (statusCode int, err error)

Ping checks that the api is available for use.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL