Documentation ¶
Index ¶
- Constants
- Variables
- func CreateStripeOnrampSessionsHandler(service *Service) handlers.AppHandler
- func GetCoinMarketsHandler(service *Service) handlers.AppHandler
- func GetHistoryHandler(service *Service) handlers.AppHandler
- func GetMappingHandler(service *Service) handlers.AppHandler
- func GetRelativeHandler(service *Service) handlers.AppHandler
- func XBraveHeaderInstrumentHandler(name string, next http.Handler) http.Handler
- type CoingeckoCoin
- type CoingeckoCoinList
- type CoingeckoDuration
- type CoingeckoLimit
- type CoingeckoVsCurrency
- type CoingeckoVsCurrencyList
- type CreateStripeOnrampSessionResponse
- type GetCoinMarketsResponse
- type HistoryResponse
- type MappingResponse
- type Service
- func (s *Service) CacheRelative(ctx context.Context, resp coingecko.SimplePriceResponse) error
- func (s *Service) CreateStripeOnrampSessionsHandler(ctx context.Context, walletAddress string, sourceCurrency string, ...) (string, error)
- func (s *Service) GetCoinMarkets(ctx context.Context, vsCurrency CoingeckoVsCurrency, limit CoingeckoLimit) (*GetCoinMarketsResponse, error)
- func (s *Service) GetHistory(ctx context.Context, coinID CoingeckoCoin, vsCurrency CoingeckoVsCurrency, ...) (*HistoryResponse, error)
- func (s *Service) GetRelative(ctx context.Context, coinIDs CoingeckoCoinList, ...) (*ratiosclient.RelativeResponse, error)
- func (s *Service) GetRelativeFromCache(ctx context.Context, vsCurrencies CoingeckoVsCurrencyList, ...) (*coingecko.SimplePriceResponse, time.Time, error)
- func (s *Service) GetTopCoins(ctx context.Context, limit int) (CoingeckoCoinList, error)
- func (s *Service) GetTopCurrencies(ctx context.Context, limit int) (CoingeckoVsCurrencyList, error)
- func (s *Service) Jobs() []srv.Job
- func (s *Service) RecordCoinsAndCurrencies(ctx context.Context, coinIds []CoingeckoCoin, ...) error
- func (s *Service) RunNextRelativeCachePrepopulationJob(ctx context.Context) (bool, error)
- type StripeOnrampSessionRequest
Constants ¶
const ( // The amount of seconds price data can be in the Redis cache // before it is considered stale GetRelativeTTL = 900 )
Variables ¶
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") )
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") )
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") )
var ( // ErrCoingeckoCoinListLimit - coin list limit ErrCoingeckoCoinListLimit = errors.New("too many coins passed") )
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
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
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
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
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) String ¶
func (cl *CoingeckoLimit) String() string
String - stringer implmentation
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
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
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 ¶
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 ¶
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 ¶
GetTopCoins - get the top coins
func (*Service) GetTopCurrencies ¶
GetTopCurrencies - get the top currencies
func (*Service) RecordCoinsAndCurrencies ¶
func (s *Service) RecordCoinsAndCurrencies(ctx context.Context, coinIds []CoingeckoCoin, vsCurrencies []CoingeckoVsCurrency) error
RecordCoinsAndCurrencies - record the coins and currencies in the cache
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