ratios

package
v0.0.0-...-8a10f5f Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// The amount of seconds price data can be in the Redis cache
	// before it is considered stale
	GetRelativeTTL = 900
)

Variables

View Source
var (
	// ErrCoingeckoCoinEmpty - empty coin
	ErrCoingeckoCoinEmpty = errors.New("coin cannot be empty")
	// ErrCoingeckoCoinInvalid - indicates there is a validation issue with the coin
	ErrCoingeckoCoinInvalid = errors.New("invalid coin")
)
View Source
var (
	// ErrCoingeckoVsCurrencyEmpty - empty coin
	ErrCoingeckoVsCurrencyEmpty = errors.New("vs currency cannot be empty")
	// ErrCoingeckoVsCurrencyInvalid - indicates there is a validation issue with the coin
	ErrCoingeckoVsCurrencyInvalid = errors.New("invalid vs currency")
)
View Source
var (

	// ErrCoingeckoDurationInvalid - indicates there is a validation issue with the duration
	ErrCoingeckoDurationInvalid = errors.New("invalid duration")

	// ErrCoingeckoLimitInvalid - indicates there is a validation issue with the Limit
	ErrCoingeckoLimitInvalid = errors.New("invalid limit")
)
View Source
var (
	// ErrCoingeckoCoinListLimit - coin list limit
	ErrCoingeckoCoinListLimit = errors.New("too many coins passed")
)
View Source
var (
	// ErrCoingeckoVsCurrencyLimit - vs currency list limit
	ErrCoingeckoVsCurrencyLimit = errors.New("too many vs currencies passed")
)

Functions

func CreateStripeOnrampSessionsHandler

func CreateStripeOnrampSessionsHandler(service *Service) handlers.AppHandler

func GetCoinMarketsHandler

func GetCoinMarketsHandler(service *Service) handlers.AppHandler

GetCoinMarketsHandler - handler to get top currency data

func GetHistoryHandler

func GetHistoryHandler(service *Service) handlers.AppHandler

GetHistoryHandler - handler to get historical exchange rates

func GetMappingHandler

func GetMappingHandler(service *Service) handlers.AppHandler

GetMappingHandler - handler to get current coin / currency mappings

func GetRelativeHandler

func GetRelativeHandler(service *Service) handlers.AppHandler

GetRelativeHandler - handler to get current relative exchange rates

func XBraveHeaderInstrumentHandler

func XBraveHeaderInstrumentHandler(name string, next http.Handler) http.Handler

XBraveHeaderInstrumentHandler instruments an http.Handler to capture data relevant to the ratios service

Types

type CoingeckoCoin

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

CoingeckoCoin - type for coingecko coin input

func (*CoingeckoCoin) Decode

func (cc *CoingeckoCoin) Decode(ctx context.Context, v []byte) error

Decode - implement decodable

func (*CoingeckoCoin) String

func (cc *CoingeckoCoin) String() string

String - stringer implmentation

func (*CoingeckoCoin) Validate

func (cc *CoingeckoCoin) Validate(ctx context.Context) error

Validate - implement validatable

type CoingeckoCoinList

type CoingeckoCoinList []CoingeckoCoin

CoingeckoCoinList - type for coingecko coin list input

func (*CoingeckoCoinList) Decode

func (ccl *CoingeckoCoinList) Decode(ctx context.Context, v []byte) error

Decode - implement decodable

func (*CoingeckoCoinList) String

func (ccl *CoingeckoCoinList) String() string

String - stringer implmentation

func (*CoingeckoCoinList) Validate

func (ccl *CoingeckoCoinList) Validate(ctx context.Context) error

Validate - implement validatable

type CoingeckoDuration

type CoingeckoDuration string

CoingeckoDuration - type for coingecko duration input

func (*CoingeckoDuration) Decode

func (cd *CoingeckoDuration) Decode(ctx context.Context, v []byte) error

Decode - implement decodable

func (*CoingeckoDuration) String

func (cd *CoingeckoDuration) String() string

String - stringer implmentation

func (*CoingeckoDuration) ToDays

func (cd *CoingeckoDuration) ToDays() float32

ToDays - get duration in days

func (*CoingeckoDuration) ToGetHistoryCacheDurationSeconds

func (cd *CoingeckoDuration) ToGetHistoryCacheDurationSeconds() int

ToGetHistoryCacheDurationSeconds returns the length of time a GetHistory cache entry is considered valid based on it's duration

func (*CoingeckoDuration) Validate

func (cd *CoingeckoDuration) Validate(ctx context.Context) error

Validate - implement validatable

type CoingeckoLimit

type CoingeckoLimit int

CoingeckoLimit - type for number of results per page Note: we only will request the first page

func (*CoingeckoLimit) Decode

func (cl *CoingeckoLimit) Decode(ctx context.Context, v []byte) error

Decode - implement decodable

func (*CoingeckoLimit) Int

func (cl *CoingeckoLimit) Int() int

Int - int conversion implmentation

func (*CoingeckoLimit) String

func (cl *CoingeckoLimit) String() string

String - stringer implmentation

func (*CoingeckoLimit) Validate

func (cl *CoingeckoLimit) Validate(ctx context.Context) error

Validate - implement validatable

type CoingeckoVsCurrency

type CoingeckoVsCurrency string

CoingeckoVsCurrency - type for coingecko vs currency input

func (*CoingeckoVsCurrency) Decode

func (cvc *CoingeckoVsCurrency) Decode(ctx context.Context, v []byte) error

Decode - implement decodable

func (*CoingeckoVsCurrency) String

func (cvc *CoingeckoVsCurrency) String() string

String - stringer implmentation

func (*CoingeckoVsCurrency) Validate

func (cvc *CoingeckoVsCurrency) Validate(ctx context.Context) error

Validate - implement validatable

type CoingeckoVsCurrencyList

type CoingeckoVsCurrencyList []CoingeckoVsCurrency

CoingeckoVsCurrencyList - type for coingecko vs currency list input

func (*CoingeckoVsCurrencyList) Decode

func (cvcl *CoingeckoVsCurrencyList) Decode(ctx context.Context, v []byte) error

Decode - implement decodable

func (*CoingeckoVsCurrencyList) String

func (cvcl *CoingeckoVsCurrencyList) String() string

String - stringer implmentation

func (*CoingeckoVsCurrencyList) Validate

func (cvcl *CoingeckoVsCurrencyList) Validate(ctx context.Context) error

Validate - implement validatable

type CreateStripeOnrampSessionResponse

type CreateStripeOnrampSessionResponse struct {
	URL string `json:"url"`
}

CreateStripeOnrampSessionResponse is an HTTP response that includes the Stripe onramp redirect URL

type GetCoinMarketsResponse

type GetCoinMarketsResponse struct {
	Payload     coingecko.CoinMarketResponse `json:"payload"`
	LastUpdated time.Time                    `json:"lastUpdated"`
}

GetCoinMarketsResponse - the response structure for top currency calls

type HistoryResponse

type HistoryResponse struct {
	Payload     coingecko.MarketChartResponse `json:"payload"`
	LastUpdated time.Time                     `json:"lastUpdated"`
}

HistoryResponse - the response structure for history calls

type MappingResponse

type MappingResponse struct {
	IDToSymbol            map[string]string `json:"idToSymbol"`
	SymbolToID            map[string]string `json:"symbolToId"`
	ContractToID          map[string]string `json:"contractToId"`
	SupportedVsCurrencies map[string]bool   `json:"supportedVsCurrencies"`
}

MappingResponse - the response structure for the current mappings

type Service

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

Service contains datastore

func InitService

func InitService(ctx context.Context) (context.Context, *Service, error)

InitService creates a service using the passed context

func NewService

func NewService(
	ctx context.Context,
	coingecko coingecko.Client,
	stripe stripe.Client,
	redis *redis.Pool,
) *Service

NewService - create a new ratios service structure

func (*Service) CacheRelative

func (s *Service) CacheRelative(ctx context.Context, resp coingecko.SimplePriceResponse) error

CacheRelative - cache the relative values

func (*Service) CreateStripeOnrampSessionsHandler

func (s *Service) CreateStripeOnrampSessionsHandler(
	ctx context.Context,
	walletAddress string,
	sourceCurrency string,
	sourceExchangeAmount string,
	destinationNetwork string,
	destinationCurrency string,
	supportedDestinationNetworks []string,
) (string, error)

CreateStripeOnrampSessionsHandler - respond to caller with an onramp URL

func (*Service) GetCoinMarkets

func (s *Service) GetCoinMarkets(
	ctx context.Context,
	vsCurrency CoingeckoVsCurrency,
	limit CoingeckoLimit,
) (*GetCoinMarketsResponse, error)

GetCoinMarkets - respond to caller with top currencies

func (*Service) GetHistory

func (s *Service) GetHistory(ctx context.Context, coinID CoingeckoCoin, vsCurrency CoingeckoVsCurrency, duration CoingeckoDuration) (*HistoryResponse, error)

GetHistory - respond to caller with historical exchange rates

func (*Service) GetRelative

func (s *Service) GetRelative(
	ctx context.Context,
	coinIDs CoingeckoCoinList,
	vsCurrencies CoingeckoVsCurrencyList,
	duration CoingeckoDuration,
) (*ratiosclient.RelativeResponse, error)

GetRelative - respond to caller with the relative exchange rates

func (*Service) GetRelativeFromCache

func (s *Service) GetRelativeFromCache(ctx context.Context, vsCurrencies CoingeckoVsCurrencyList, coinIds ...CoingeckoCoin) (*coingecko.SimplePriceResponse, time.Time, error)

GetRelativeFromCache - get the relative response from the cache

func (*Service) GetTopCoins

func (s *Service) GetTopCoins(ctx context.Context, limit int) (CoingeckoCoinList, error)

GetTopCoins - get the top coins

func (*Service) GetTopCurrencies

func (s *Service) GetTopCurrencies(ctx context.Context, limit int) (CoingeckoVsCurrencyList, error)

GetTopCurrencies - get the top currencies

func (*Service) Jobs

func (s *Service) Jobs() []srv.Job

Jobs - Implement srv.JobService interface

func (*Service) RecordCoinsAndCurrencies

func (s *Service) RecordCoinsAndCurrencies(ctx context.Context, coinIds []CoingeckoCoin, vsCurrencies []CoingeckoVsCurrency) error

RecordCoinsAndCurrencies - record the coins and currencies in the cache

func (*Service) RunNextRelativeCachePrepopulationJob

func (s *Service) RunNextRelativeCachePrepopulationJob(ctx context.Context) (bool, error)

RunNextRelativeCachePrepopulationJob takes the next job to prepopulate the relative cache and completes it

type StripeOnrampSessionRequest

type StripeOnrampSessionRequest struct {
	WalletAddress                string   `json:"wallet_address"`
	SourceCurrency               string   `json:"source_currency"`
	SourceExchangeAmount         string   `json:"source_exchange_amount"`
	DestinationNetwork           string   `json:"destination_network"`
	DestinationCurrency          string   `json:"destination_currency"`
	SupportedDestinationNetworks []string `json:"supported_destination_networks"`
}

StripeOnrampSessionRequest

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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