constants

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Log keys are used to provide a consistent key-value interface for logging across the daemon.
	SubmoduleLogKey = "submodule"

	ErrorLogKey      = "error"
	ExchangeIdLogKey = "exchangeId"
	MarketIdLogKey   = "marketId"
	PriceLogKey      = "Price"
	ReasonLogKey     = "reason"

	// Module and Submodule names are used to provide consistent key-value pairs for logging across the daemon.
	PricefeedDaemonModuleName       = "pricefeed-daemon"
	PriceFetcherSubmoduleName       = "price-fetcher"
	PriceEncoderSubmoduleName       = "price-encoder"
	PriceUpdaterSubmoduleName       = "price-updater"
	MarketParamUpdaterSubmoduleName = "market-param-updater"

	// PriceDaemonStartupErrorGracePeriod defines the amount of time the daemon waits before logging issues that are
	// intermittent on daemon startup as true errors. Examples of this includes price conversion failures due to
	// an uninitialized prices cache, and failures to fetch market param updates due to a delay on the protocol side
	// in starting the prices query service.
	// If the protocol is not started within this grace period, the daemon will report these errors as true errors.
	PriceDaemonStartupErrorGracePeriod = 120 * time.Second

	// Error messages
	UnexpectedResponseStatusMessage = "Unexpected response status code of:"
)
View Source
const (
	// 5K is chosen to be >> than the number of messages an exchange could send in any period before the
	// price encoder is able to read the messages from the buffer, even if we add O(10-100) markets dynamically,
	// but not large enough to allow more than at most a few minutes of price messages to accumulate.
	FixedBufferSize = 1024 * 5
	// https://stackoverflow.com/questions/37774624/go-http-get-concurrency-and-connection-reset-by-peer.
	// This is a good number to start with based on the above link. Adjustments can/will be made accordingly.
	MaxConnectionsPerExchange = 50
)
View Source
const (
	// DefaultPrice is the default value for `Price` field in `UpdateMarketPricesRequest`.
	DefaultPrice = 0

	// PricefeedExchangeConfigFileName names the config file containing the exchange startup config.
	PricefeedExchangeConfigFileName = "pricefeed_exchange_config.toml"

	// MarketParamsConfigFileName names the config file containing the market params.
	MarketParamsConfigFileName = "market_params.toml"
)
View Source
const (
	// MaxPriceAge defines the duration in which a price update is valid for.
	MaxPriceAge = time.Duration(30_000_000_000) // 30 sec, duration uses nanoseconds.
)
View Source
const (
	// MinimumRequiredExchangesPerMarket is the minimum number of markets required for a market to be reliably priced
	// by the pricefeed daemon. This number was chosen to supply the minimum number of prices required to
	// compute an index price for a market, given exchange unavailability due to exchange geo-fencing,
	// downtime, etc.
	// Ok to drop this to 5 for some markets if needed, but 6 is better.
	MinimumRequiredExchangesPerMarket = 6
)
View Source
const (
	// UnixProtocol is the network for gRPC protocol used by the price daemon and server.
	UnixProtocol = "unix"
)

Variables

View Source
var ErrRateLimiting = fmt.Errorf("status 429 - rate limit exceeded")

StaticExchangeDetails is the static mapping of `ExchangeId` to its `ExchangeQueryDetails`.

View Source
var StaticExchangeQueryConfig = map[types.ExchangeId]*types.ExchangeQueryConfig{

	exchange_common.EXCHANGE_ID_BINANCE: {
		ExchangeId: exchange_common.EXCHANGE_ID_BINANCE,
		IntervalMs: binanceIntervalMs,
		TimeoutMs:  defaultTimeoutMs,
		MaxQueries: defaultMultiMarketMaxQueries,
	},

	exchange_common.EXCHANGE_ID_BINANCE_US: {
		ExchangeId: exchange_common.EXCHANGE_ID_BINANCE_US,
		IntervalMs: binanceIntervalMs,
		TimeoutMs:  defaultTimeoutMs,
		MaxQueries: defaultMultiMarketMaxQueries,
	},

	exchange_common.EXCHANGE_ID_BITFINEX: {
		ExchangeId: exchange_common.EXCHANGE_ID_BITFINEX,
		IntervalMs: bitfinexIntervalMs,
		TimeoutMs:  defaultTimeoutMs,
		MaxQueries: defaultMultiMarketMaxQueries,
	},
	exchange_common.EXCHANGE_ID_KRAKEN: {
		ExchangeId: exchange_common.EXCHANGE_ID_KRAKEN,
		IntervalMs: defaultIntervalMs,
		TimeoutMs:  defaultTimeoutMs,
		MaxQueries: defaultMultiMarketMaxQueries,
	},

	exchange_common.EXCHANGE_ID_GATE: {
		ExchangeId: exchange_common.EXCHANGE_ID_GATE,
		IntervalMs: defaultIntervalMs,
		TimeoutMs:  defaultTimeoutMs,
		MaxQueries: defaultMultiMarketMaxQueries,
	},

	exchange_common.EXCHANGE_ID_BITSTAMP: {
		ExchangeId: exchange_common.EXCHANGE_ID_BITSTAMP,
		IntervalMs: defaultIntervalMs,
		TimeoutMs:  defaultTimeoutMs,
		MaxQueries: defaultMultiMarketMaxQueries,
	},

	exchange_common.EXCHANGE_ID_CRYPTO_COM: {
		ExchangeId: exchange_common.EXCHANGE_ID_CRYPTO_COM,
		IntervalMs: defaultIntervalMs,
		TimeoutMs:  defaultTimeoutMs,
		MaxQueries: defaultMultiMarketMaxQueries,
	},

	exchange_common.EXCHANGE_ID_HUOBI: {
		ExchangeId: exchange_common.EXCHANGE_ID_HUOBI,
		IntervalMs: defaultIntervalMs,
		TimeoutMs:  defaultTimeoutMs,
		MaxQueries: defaultMultiMarketMaxQueries,
	},

	exchange_common.EXCHANGE_ID_KUCOIN: {
		ExchangeId: exchange_common.EXCHANGE_ID_KUCOIN,
		IntervalMs: defaultIntervalMs,
		TimeoutMs:  defaultTimeoutMs,
		MaxQueries: defaultMultiMarketMaxQueries,
	},

	exchange_common.EXCHANGE_ID_OKX: {
		ExchangeId: exchange_common.EXCHANGE_ID_OKX,
		IntervalMs: defaultIntervalMs,
		TimeoutMs:  defaultTimeoutMs,
		MaxQueries: defaultMultiMarketMaxQueries,
	},

	exchange_common.EXCHANGE_ID_MEXC: {
		ExchangeId: exchange_common.EXCHANGE_ID_MEXC,
		IntervalMs: defaultIntervalMs,
		TimeoutMs:  defaultTimeoutMs,
		MaxQueries: defaultMultiMarketMaxQueries,
	},

	exchange_common.EXCHANGE_ID_TEST_VOLATILE_EXCHANGE: {
		ExchangeId: exchange_common.EXCHANGE_ID_TEST_VOLATILE_EXCHANGE,
		IntervalMs: defaultIntervalMs,
		TimeoutMs:  defaultTimeoutMs,
		MaxQueries: defaultMaxQueries,
	},
	exchange_common.EXCHANGE_ID_TEST_FIXED_PRICE_EXCHANGE: {
		ExchangeId: exchange_common.EXCHANGE_ID_TEST_FIXED_PRICE_EXCHANGE,
		IntervalMs: defaultIntervalMs,
		TimeoutMs:  defaultTimeoutMs,
		MaxQueries: defaultMaxQueries,
	},
}
View Source
var StaticMarketParamsConfig = map[uint32]*types.MarketParam{
	exchange_common.BTCUSD_ID: {
		Id:                 exchange_common.BTCUSD_ID,
		Pair:               `"BTC-USD"`,
		Exponent:           -5,
		MinExchanges:       1,
		MinPriceChangePpm:  1000,
		ExchangeConfigJson: `{\"exchanges\":[{\"exchangeName\":\"Binance\",\"ticker\":\"\\\"BTCUSDT\\\"\"},{\"exchangeName\":\"BinanceUS\",\"ticker\":\"\\\"BTCUSD\\\"\"},{\"exchangeName\":\"Bitfinex\",\"ticker\":\"tBTCUSD\"},{\"exchangeName\":\"Bitstamp\",\"ticker\":\"BTC/USD\"},{\"exchangeName\":\"CryptoCom\",\"ticker\":\"BTC_USD\"},{\"exchangeName\":\"Kraken\",\"ticker\":\"XXBTZUSD\"},{\"exchangeName\":\"Okx\",\"ticker\":\"BTC-USDT\"}]}`,
		QueryData:          `"00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000953706F745072696365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003627463000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037573640000000000000000000000000000000000000000000000000000000000"`,
	},
	exchange_common.ETHUSD_ID: {
		Id:                 exchange_common.ETHUSD_ID,
		Pair:               `"ETH-USD"`,
		Exponent:           -6,
		MinExchanges:       1,
		MinPriceChangePpm:  1000,
		ExchangeConfigJson: `{\"exchanges\":[{\"exchangeName\":\"Binance\",\"ticker\":\"\\\"ETHUSDT\\\"\"},{\"exchangeName\":\"BinanceUS\",\"ticker\":\"\\\"ETHUSD\\\"\"},{\"exchangeName\":\"Bitfinex\",\"ticker\":\"tETHUSD\"},{\"exchangeName\":\"Bitstamp\",\"ticker\":\"ETH/USD\"},{\"exchangeName\":\"CryptoCom\",\"ticker\":\"ETH_USD\"},{\"exchangeName\":\"Kraken\",\"ticker\":\"XETHZUSD\"},{\"exchangeName\":\"Okx\",\"ticker\":\"ETH-USDT\"}]}`,
		QueryData:          `"00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000953706F745072696365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003657468000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037573640000000000000000000000000000000000000000000000000000000000"`,
	},
	exchange_common.TRBUSD_ID: {
		Id:                 exchange_common.TRBUSD_ID,
		Pair:               `"TRB-USD"`,
		Exponent:           -6,
		MinExchanges:       1,
		MinPriceChangePpm:  1000,
		ExchangeConfigJson: `{\"exchanges\":[{\"exchangeName\":\"Binance\",\"ticker\":\"\\\"TRBUSDT\\\"\"},{\"exchangeName\":\"CryptoCom\",\"ticker\":\"TRB_USD\"},{\"exchangeName\":\"Okx\",\"ticker\":\"TRB-USDT\"}]}`,
		QueryData:          `"00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000953706F745072696365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003747262000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037573640000000000000000000000000000000000000000000000000000000000"`,
	},
}

Functions

func GenerateExchangeConfigJson

func GenerateExchangeConfigJson(
	exchangeToExchangeConfig map[types.ExchangeId]*types.MutableExchangeMarketConfig,
) (
	marketToExchangeConfigJson map[types.MarketId]string,
)

GenerateExchangeConfigJson generates human-readable exchange config json for each market based on the contents of an exchangeToExchangeConfig map. For the default exchange configs, pass in the `StaticExchangeMarketConfig` map above as the argument.

Types

This section is empty.

Jump to

Keyboard shortcuts

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