Documentation
¶
Overview ¶
Credit: @oleksandrmarkelov https://github.com/NibiruChain/pricefeeder/pull/27
Index ¶
- Constants
- Variables
- func BinancePriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (rawPrices map[types.Symbol]float64, err error)
- func BinanceSymbolCsv(symbols set.Set[types.Symbol]) string
- func BitfinexPriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (rawPrices map[types.Symbol]float64, err error)
- func BitfinexSymbolCsv(symbols set.Set[types.Symbol]) string
- func BybitPriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (rawPrices map[types.Symbol]float64, err error)
- func ChainlinkPriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (map[types.Symbol]float64, error)
- func CoingeckoPriceUpdate(sourceConfig json.RawMessage) types.FetchPricesFunc
- func CoinmarketcapPriceUpdate(coinmarketcapConfig json.RawMessage) types.FetchPricesFunc
- func ErisProtocolPriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (rawPrices map[types.Symbol]float64, err error)
- func GateIoPriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (rawPrices map[types.Symbol]float64, err error)
- func GetRegisteredSource(name string, symbols set.Set[types.Symbol], cfg json.RawMessage, ...) (types.Source, error)
- func OkexPriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (rawPrices map[types.Symbol]float64, err error)
- func Register(ns NamedSource)
- func TestCoingeckoPriceUpdate(t *testing.T)
- func TestCoingeckoWithConfig(t *testing.T)
- func UniswapV3PriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (map[types.Symbol]float64, error)
- type BinanceTicker
- type BybitResponse
- type ChainType
- type ChainlinkConfig
- type CmcQuote
- type CmcQuotePrice
- type CmcResponse
- type CmcTicker
- type CoingeckoConfig
- type CoingeckoTicker
- type CoinmarketcapConfig
- type NamedSource
- type OkexResponse
- type OkexTicker
- type Pool
- type SourceFactory
- type TickSource
- type TokenInfo
- type TokenPair
Constants ¶
const ( SourceNameCoingecko = "coingecko" FreeLink = "https://api.coingecko.com/api/v3/" PaidLink = "https://pro-api.coingecko.com/api/v3/" ApiKeyParam = "x_cg_pro_api_key" )
const ( SourceNameUniswapV3 = "uniswap_v3" Symbol_UniswapV3_USDaUSD types.Symbol = "USDa:USDT" )
const ErrBybitBlockAccess = "configured to block access from your country"
const (
SourceNameBinance = "binance"
)
const (
SourceNameBitfinex = "bitfinex"
)
const (
SourceNameBybit = "bybit"
)
const (
SourceNameChainLink = "chainlink"
)
const (
SourceNameCoinMarketCap = "coinmarketcap"
)
const (
SourceNameErisProtocol = "eris_protocol"
)
const (
SourceNameGateIo = "gateio"
)
const (
SourceNameOkex = "okex"
)
Variables ¶
var UniswapV3factoryAddress = gethcommon.HexToAddress("0x1F98431c8aD98523631AE4a59f267346ea31F984")
var UpdateTick = 8 * time.Second
UpdateTick defines the wait time between price updates.
var UpdateTickTestLock sync.Mutex
UpdateTickTestLock is a mutex that should be acquired before modifying UpdateTick in tests to prevent data races when tests run in parallel.
Functions ¶
func BinancePriceUpdate ¶
func BinancePriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (rawPrices map[types.Symbol]float64, err error)
BinancePriceUpdate returns the prices given the symbols or an error. Uses the Binance API at https://docs.binance.us/#price-data.
func BitfinexPriceUpdate ¶
func BitfinexPriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (rawPrices map[types.Symbol]float64, err error)
BitfinexPriceUpdate returns the prices given the symbols or an error.
func BybitPriceUpdate ¶
func BybitPriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (rawPrices map[types.Symbol]float64, err error)
BybitPriceUpdate returns the prices for given symbols or an error. Uses BYBIT API at https://bybit-exchange.github.io/docs/v5/market/tickers.
func ChainlinkPriceUpdate ¶
func ChainlinkPriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (map[types.Symbol]float64, error)
ChainlinkPriceUpdate retrieves exchange rates from various Chainlink oracles across different chains
func CoingeckoPriceUpdate ¶
func CoingeckoPriceUpdate(sourceConfig json.RawMessage) types.FetchPricesFunc
func CoinmarketcapPriceUpdate ¶
func CoinmarketcapPriceUpdate(coinmarketcapConfig json.RawMessage) types.FetchPricesFunc
func ErisProtocolPriceUpdate ¶
func ErisProtocolPriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (rawPrices map[types.Symbol]float64, err error)
ErisProtocolPriceUpdate retrieves the exchange rate for stNIBI to NIBI (ustnibi:unibi) from the Eris Protocol smart contract. Note: This function ignores the input symbols and always returns the exchange rate for "ustnibi:unibi".
func GateIoPriceUpdate ¶
func GateIoPriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (rawPrices map[types.Symbol]float64, err error)
GateIoPriceUpdate returns the prices given the symbols or an error. Uses the GateIo API at https://www.gate.io/docs/developers/apiv4/en/#get-details-of-a-specifc-currency-pair.
func GetRegisteredSource ¶
func GetRegisteredSource( name string, symbols set.Set[types.Symbol], cfg json.RawMessage, logger zerolog.Logger, ) (types.Source, error)
GetRegisteredSource retrieves a registered source by name from the source registry and instantiates it with the provided symbols, configuration, and logger.
- GetRegisteredSource is safe for concurrent use.
- Returns an error if the source name is not registered or if the registered factory function is nil.
func OkexPriceUpdate ¶
func OkexPriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (rawPrices map[types.Symbol]float64, err error)
OkexPriceUpdate returns the prices for given symbols or an error. Uses OKEX API at https://www.okx.com/docs-v5/en/#rest-api-market-data.
func Register ¶
func Register(ns NamedSource)
Register adds a NamedSource to the price feeder application.
func TestCoingeckoWithConfig ¶
Types ¶
type BinanceTicker ¶
type BybitResponse ¶
type ChainType ¶
type ChainType string
ChainType represents different blockchain networks
const (
ChainB2 ChainType = "b2"
)
type ChainlinkConfig ¶
type ChainlinkConfig struct {
Chain ChainType
ContractAddress common.Address
Description string // Expected description (for sanity check)
MaxDataAge time.Duration // Maximum acceptable data age
}
ChainlinkConfig represents configuration for a specific Chainlink oracle
type CmcQuote ¶
type CmcQuote struct {
USD CmcQuotePrice
}
type CmcQuotePrice ¶
type CmcQuotePrice struct {
Price float64
}
type CmcResponse ¶
type CoingeckoConfig ¶
type CoingeckoConfig struct {
ApiKey string `json:"api_key"`
}
type CoingeckoTicker ¶
type CoingeckoTicker struct {
Price float64 `json:"usd"`
}
type CoinmarketcapConfig ¶
type CoinmarketcapConfig struct {
ApiKey string `json:"api_key"`
}
type NamedSource ¶
type NamedSource struct {
Name string // For example, "binance", "bitfinex"
F SourceFactory // The factory function that creates instances of this source
}
NamedSource pairs a source name with its factory function for registration in the price feeder source registry. Use NamedSource with Register to make a source available to the application.
type OkexResponse ¶
type OkexResponse struct {
Data []OkexTicker `json:"data"`
}
type OkexTicker ¶
type Pool ¶
type Pool struct {
Address gethcommon.Address
Fee uint32
Liquidity *big.Int
}
Pool represents a Uniswap V3 pool with its metadata
type SourceFactory ¶
type SourceFactory func( symbols set.Set[types.Symbol], cfg json.RawMessage, logger zerolog.Logger, ) types.Source
SourceFactory is a function type that creates a types.Source instance for a given set of symbols, configuration, and logger. Use SourceFactory to register new price data sources with the application registry.
type TickSource ¶
type TickSource struct {
// contains filtered or unexported fields
}
TickSource is a Source which updates prices every x time.Duration.
func NewTickSource ¶
func NewTickSource( symbols set.Set[types.Symbol], fetchPricesFunc types.FetchPricesFunc, logger zerolog.Logger, ) *TickSource
NewTickSource instantiates a new TickSource instance, given the symbols and a price updater function which returns the latest prices for the provided symbols.
func (*TickSource) Close ¶
func (s *TickSource) Close()
func (*TickSource) PriceUpdates ¶
func (s *TickSource) PriceUpdates() <-chan map[types.Symbol]types.RawPrice
type TokenPair ¶
type TokenPair struct {
Token0 gethcommon.Address
Token1 gethcommon.Address
Token0Decimals int
Token1Decimals int
IsReversed bool // true if the original order was reversed for sorting
}
TokenPair represents a sorted token pair for Uniswap V3
func NewTokenPair ¶
func NewTokenPair(tokenA, tokenB gethcommon.Address, decimalsA, decimalsB int) TokenPair
NewTokenPair creates a properly sorted token pair for Uniswap V3