fiatrates

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: BlueOak-1.0.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FiatRateDataExpiry : Any data older than FiatRateDataExpiry will be
	// discarded.
	FiatRateDataExpiry = 60 * time.Minute
)

Variables

This section is empty.

Functions

func CoinpapSlug

func CoinpapSlug(name, symbol string) string

func FetchCoinpaprikaRates

func FetchCoinpaprikaRates(ctx context.Context, assets []*CoinpaprikaAsset, log dex.Logger) map[uint32]float64

FetchCoinpaprikaRates retrieves and parses fiat rate data from the Coinpaprika API. See https://api.coinpaprika.com/#operation/getTickersById for sample request and response information.

Types

type CoinpaprikaAsset

type CoinpaprikaAsset struct {
	AssetID uint32
	Name    string
	Symbol  string
}

type Config

type Config struct {
	CryptoCompareAPIKey string `long:"ccdataapikey" description:"This is your free API Key from cryptocompare.com."`
	EnableBinanceUS     bool   `long:"enablebinanceus" description:"Set to true, if running the tatanka mesh from a US based server."`
	DisabledFiatSources string `long:"disabledfiatsources" description:"A list of disabled sources separated by comma. See fiatrate/sources.go."`
}

func (Config) AllFiatSourceDisabled

func (cfg Config) AllFiatSourceDisabled() bool

AllFiatSourceDisabled checks if all currently supported fiat rate sources are disabled.

type FiatRateInfo

type FiatRateInfo struct {
	Value      float64
	LastUpdate time.Time
}

FiatRateInfo holds the fiat rate and the last update time for an asset.

type Oracle

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

Oracle manages and retrieves fiat rate information from all enabled rate sources.

func NewFiatOracle

func NewFiatOracle(cfg Config, tickerSymbols string, log dex.Logger) (*Oracle, error)

func (*Oracle) AddFiatRateListener

func (o *Oracle) AddFiatRateListener(uniqueID string, ratesChan chan<- map[string]*FiatRateInfo)

AddFiatRateListener adds a new fiat rate listener for the provided uniqueID. Overrides existing rateChan if uniqueID already exists.

func (*Oracle) Rates

func (o *Oracle) Rates() map[string]*FiatRateInfo

Rates returns the current fiat rates. Returns an empty map if there are no valid rates.

func (*Oracle) RemoveFiatRateListener

func (o *Oracle) RemoveFiatRateListener(uniqueID string)

RemoveFiatRateListener removes a fiat rate listener. no-op if there's no listener for the provided uniqueID. The fiat rate chan will be closed to signal to readers that we are done sending.

func (*Oracle) Run

func (o *Oracle) Run(ctx context.Context)

Run starts goroutines that refresh fiat rates every source.refreshInterval. This should be called in a goroutine as it's blocking.

Jump to

Keyboard shortcuts

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