coingecko

package
v0.0.0-...-f003305 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MPL-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// CoinMarketsCacheTTLSeconds is how long FetchCoinMarkets responses cached
	// in Redis are considered valid
	CoinMarketsCacheTTLSeconds = 60 * 60
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	FetchSimplePrice(ctx context.Context, ids string, vsCurrencies string, include24hrChange bool) (*SimplePriceResponse, error)
	FetchCoinList(ctx context.Context, includePlatform bool) (*CoinListResponse, error)
	FetchSupportedVsCurrencies(ctx context.Context) (*SupportedVsCurrenciesResponse, error)
	FetchMarketChart(ctx context.Context, id string, vsCurrency string, days float32, cacheDurationSeconds int) (*MarketChartResponse, time.Time, error)
	FetchCoinMarkets(ctx context.Context, vsCurrency string, limit int) (*CoinMarketResponse, time.Time, error)
}

Client abstracts over the underlying client

func NewWithContext

func NewWithContext(ctx context.Context, redis *redis.Pool) (Client, error)

NewWithContext returns a new HTTPClient, retrieving the base URL from the context

type ClientWithPrometheus

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

ClientWithPrometheus implements Client interface with all methods wrapped with Prometheus metrics

func NewClientWithPrometheus

func NewClientWithPrometheus(base Client, instanceName string) ClientWithPrometheus

NewClientWithPrometheus returns an instance of the Client decorated with prometheus summary metric

func (ClientWithPrometheus) FetchCoinList

func (_d ClientWithPrometheus) FetchCoinList(ctx context.Context, includePlatform bool) (cp1 *CoinListResponse, err error)

FetchCoinList implements Client

func (ClientWithPrometheus) FetchCoinMarkets

func (_d ClientWithPrometheus) FetchCoinMarkets(ctx context.Context, vsCurrency string, limit int) (cp1 *CoinMarketResponse, t1 time.Time, err error)

FetchCoinMarkets implements Client

func (ClientWithPrometheus) FetchMarketChart

func (_d ClientWithPrometheus) FetchMarketChart(ctx context.Context, id string, vsCurrency string, days float32, cacheDurationSeconds int) (mp1 *MarketChartResponse, t1 time.Time, err error)

FetchMarketChart implements Client

func (ClientWithPrometheus) FetchSimplePrice

func (_d ClientWithPrometheus) FetchSimplePrice(ctx context.Context, ids string, vsCurrencies string, include24hrChange bool) (sp1 *SimplePriceResponse, err error)

FetchSimplePrice implements Client

func (ClientWithPrometheus) FetchSupportedVsCurrencies

func (_d ClientWithPrometheus) FetchSupportedVsCurrencies(ctx context.Context) (sp1 *SupportedVsCurrenciesResponse, err error)

FetchSupportedVsCurrencies implements Client

type CoinInfo

type CoinInfo struct {
	ID        string           `json:"id"`
	Symbol    string           `json:"symbol"`
	Name      string           `json:"name"`
	Platforms CoinInfoPlatform `json:"platforms,omitempty"`
}

CoinInfo - info about coin

type CoinInfoPlatform

type CoinInfoPlatform struct {
	Ethereum string `json:"ethereum,omitempty"`
}

CoinInfoPlatform - platform coin info

type CoinListResponse

type CoinListResponse []CoinInfo

CoinListResponse is the response received from coingecko

type CoinMarket

type CoinMarket struct {
	ID                       string  `json:"id"`
	Symbol                   string  `json:"symbol"`
	Name                     string  `json:"name"`
	Image                    string  `json:"image"`
	MarketCap                int     `json:"market_cap"`
	MarketCapRank            int     `json:"market_cap_rank"`
	CurrentPrice             float64 `json:"current_price"`
	PriceChange24h           float64 `json:"price_change_24h"`
	PriceChangePercentage24h float64 `json:"price_change_percentage_24h"`
	TotalVolume              float64 `json:"total_volume"`
}

CoinMarket represents the market data for a single coin returned in FetchCoinMarkets call to coingecko

type CoinMarketResponse

type CoinMarketResponse []*CoinMarket

CoinMarketResponse is the coingecko response for FetchCoinMarkets

type HTTPClient

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

HTTPClient wraps http.Client for interacting with the coingecko server

func (*HTTPClient) FetchCoinList

func (c *HTTPClient) FetchCoinList(ctx context.Context, includePlatform bool) (*CoinListResponse, error)

FetchCoinList fetches the list of supported coins

func (*HTTPClient) FetchCoinMarkets

func (c *HTTPClient) FetchCoinMarkets(
	ctx context.Context,
	vsCurrency string,
	limit int,
) (*CoinMarketResponse, time.Time, error)

FetchCoinMarkets fetches the market data for the top coins

func (*HTTPClient) FetchMarketChart

func (c *HTTPClient) FetchMarketChart(
	ctx context.Context,
	id string, vsCurrency string,
	days float32,
	cacheDurationSeconds int,
) (*MarketChartResponse, time.Time, error)

FetchMarketChart fetches the history rate of a currency

func (*HTTPClient) FetchSimplePrice

func (c *HTTPClient) FetchSimplePrice(ctx context.Context, ids string, vsCurrencies string, include24hrChange bool) (*SimplePriceResponse, error)

FetchSimplePrice fetches the rate of a currency to BAT

func (*HTTPClient) FetchSupportedVsCurrencies

func (c *HTTPClient) FetchSupportedVsCurrencies(ctx context.Context) (*SupportedVsCurrenciesResponse, error)

FetchSupportedVsCurrencies fetches the list of supported vs currencies

type MarketChartResponse

type MarketChartResponse struct {
	Prices       [][]decimal.Decimal `json:"prices"`
	MarketCaps   [][]decimal.Decimal `json:"market_caps"`
	TotalVolumes [][]decimal.Decimal `json:"total_volumes"`
}

MarketChartResponse is the response received from coingecko

type SimplePriceResponse

type SimplePriceResponse map[string]map[string]decimal.Decimal

SimplePriceResponse is the response received from coingecko

type SupportedVsCurrenciesResponse

type SupportedVsCurrenciesResponse []string

SupportedVsCurrenciesResponse is the response received from coingecko

Directories

Path Synopsis
Package mock_coingecko is a generated GoMock package.
Package mock_coingecko is a generated GoMock package.

Jump to

Keyboard shortcuts

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