coinmarketcap

package
v0.0.0-beta.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

README

CoinMarketCap Provider

Overview

NOTE: This specific provider should not be used in any production setting as it is not sufficiently tested.

The CoinMarketCap provider is used to fetch the spot price for cryptocurrencies from the CoinMarketCap API.

Configuration

The configuration structure for this provider looks like the following:

// CoinMarketCapConfig is the config struct for the coinmarketcap provider.
type CoinMarketCapConfig struct {
	// APIKey is the API key used to make requests to the coinmarketcap API.
	APIKey string `mapstructure:"api_key" toml:"api_key"`
	// TokenNameToMetadata is a map of token names to their metadata.
	TokenNameToSymbol map[string]string `mapstructure:"token_name_to_symbol" toml:"token_name_to_symbol"`
}

Where a properly formatted CoinMarketCapConfig json object looks like the following:

Sample coinmarketcap.toml:

###############################################################################
###                           CoinMarketCap                                 ###
###############################################################################
# This section contains the configuration for the CoinMarketCap API. This meant to be
# used in a testing environment as this API is not production ready.

# APIKey is the API key used to make requests to the CoinMarketCap API.
api_key = "my-api-key"

# TokenNameToMetadata is a map of token names to their metadata.
[token_name_to_symbol]
  "BITCOIN" = "BTC"
  "USD" = "USD"
  # Add more token name-to-symbol mappings as needed

Documentation

Index

Constants

View Source
const (
	// Name is the name of this provider
	Name = "coinmarketcap"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// APIKey is the API key used to make requests to the coinmarketcap API.
	APIKey string `mapstructure:"api_key" toml:"api_key"`
	// TokenNameToMetadata is a map of token names to their metadata.
	TokenNameToSymbol map[string]string `mapstructure:"token_name_to_symbol" toml:"token_name_to_symbol"`
}

Config is the config struct for the coinmarketcap provider.

func ReadCoinMarketCapConfigFromFile

func ReadCoinMarketCapConfigFromFile(path string) (Config, error)

ReadCoinMarketCapConfigFromFile reads a config from a file and returns the config.

type Provider

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

Provider is the implementation of the oracle's Provider interface for coinmarketcap.

func NewProvider

func NewProvider(logger log.Logger, pairs []oracletypes.CurrencyPair, providerConfig config.ProviderConfig) (*Provider, error)

NewProvider returns a new coinmarketcap provider. It uses the provided API-key in the header of outgoing requests to coinmarketcap's API.

func (*Provider) GetPairs

func (p *Provider) GetPairs() []oracletypes.CurrencyPair

GetPairs returns the currency pairs that the provider is fetching prices for.

func (*Provider) GetPrices

GetPrices returns the current set of prices for each of the currency pairs. This method starts all price requests concurrently, and waits for them all to finish, or for the context to be cancelled, at which point it aggregates the responses and returns.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the name of the provider.

func (*Provider) SetPairs

func (p *Provider) SetPairs(pairs ...oracletypes.CurrencyPair)

SetPairs sets the currency pairs that the provider will fetch prices for.

Jump to

Keyboard shortcuts

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