sources

package
v1.0.3-rc3 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	Coingecko   = "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 (
	Binance = "binance"
)
View Source
const (
	Bitfinex = "bitfinex"
)
View Source
const (
	Bybit = "bybit"
)
View Source
const (
	CoinMarketCap = "coinmarketcap"
)
View Source
const (
	GateIo = "gateio"
)
View Source
const (
	Okex = "okex"
)

Variables

View Source
var UpdateTick = 8 * time.Second

UpdateTick defines the wait time between price updates.

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 added in v1.0.1

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 CoingeckoPriceUpdate

func CoingeckoPriceUpdate(sourceConfig json.RawMessage) types.FetchPricesFunc

func CoinmarketcapPriceUpdate added in v1.0.0

func CoinmarketcapPriceUpdate(coinmarketcapConfig json.RawMessage) types.FetchPricesFunc

func GateIoPriceUpdate added in v1.0.1

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 OkexPriceUpdate added in v1.0.1

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.

Types

type BinanceTicker

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

type BybitResponse added in v1.0.1

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

type CmcQuote added in v1.0.0

type CmcQuote struct {
	USD CmcQuotePrice
}

type CmcQuotePrice added in v1.0.0

type CmcQuotePrice struct {
	Price float64
}

type CmcResponse added in v1.0.0

type CmcResponse struct {
	Data map[string]CmcTicker
}

type CmcTicker added in v1.0.0

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 added in v1.0.0

type CoinmarketcapConfig struct {
	ApiKey string `json:"api_key"`
}

type OkexResponse added in v1.0.1

type OkexResponse struct {
	Data []OkexTicker `json:"data"`
}

type OkexTicker added in v1.0.1

type OkexTicker struct {
	Symbol string `json:"instId"`
	Price  string `json:"last"`
}

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

Jump to

Keyboard shortcuts

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