sources

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Credit: @oleksandrmarkelov https://github.com/NibiruChain/pricefeeder/pull/27

Index

Constants

View Source
const (
	SourceNameCoingecko = "coingecko"
	FreeLink            = "https://api.coingecko.com/api/v3/"
	PaidLink            = "https://pro-api.coingecko.com/api/v3/"
	ApiKeyParam         = "x_cg_pro_api_key"
)
View Source
const (
	SourceNameUniswapV3 = "uniswap_v3"

	Symbol_UniswapV3_USDaUSD types.Symbol = "USDa:USDT"
)
View Source
const ErrBybitBlockAccess = "configured to block access from your country"
View Source
const (
	SourceNameBinance = "binance"
)
View Source
const (
	SourceNameBitfinex = "bitfinex"
)
View Source
const (
	SourceNameBybit = "bybit"
)
View Source
const (
	SourceNameChainLink = "chainlink"
)
View Source
const (
	SourceNameCoinMarketCap = "coinmarketcap"
)
View Source
const (
	SourceNameErisProtocol = "eris_protocol"
)
View Source
const (
	SourceNameGateIo = "gateio"
)
View Source
const (
	SourceNameOkex = "okex"
)

Variables

View Source
var UniswapV3factoryAddress = gethcommon.HexToAddress("0x1F98431c8aD98523631AE4a59f267346ea31F984")
View Source
var UpdateTick = 8 * time.Second

UpdateTick defines the wait time between price updates.

View Source
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 BinanceSymbolCsv

func BinanceSymbolCsv(symbols set.Set[types.Symbol]) string

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 BitfinexSymbolCsv

func BitfinexSymbolCsv(symbols set.Set[types.Symbol]) string

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 TestCoingeckoPriceUpdate

func TestCoingeckoPriceUpdate(t *testing.T)

func TestCoingeckoWithConfig

func TestCoingeckoWithConfig(t *testing.T)

func UniswapV3PriceUpdate

func UniswapV3PriceUpdate(symbols set.Set[types.Symbol], logger zerolog.Logger) (map[types.Symbol]float64, error)

UniswapV3PriceUpdate retrieves the exchange rates for the given symbols from the Uniswap V3 protocol.

Types

type BinanceTicker

type BinanceTicker struct {
	Symbol string  `json:"symbol"`
	Price  float64 `json:"price,string"`
}

type BybitResponse

type BybitResponse struct {
	Data struct {
		List []struct {
			Symbol string `json:"symbol"`
			Price  string `json:"lastPrice"`
		} `json:"list"`
	} `json:"result"`
}

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 CmcResponse struct {
	Data map[string]CmcTicker
}

type CmcTicker

type CmcTicker struct {
	Slug  string
	Quote CmcQuote
}

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 OkexTicker struct {
	Symbol string `json:"instId"`
	Price  string `json:"last"`
}

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 TokenInfo

type TokenInfo struct {
	Address  string
	Decimals int
}

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

Jump to

Keyboard shortcuts

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