Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertDenomByProvider(denom string, exchange string) (string, error)
- func ConvertExchangeConfigJSON(config dydxtypes.ExchangeConfigJson) ([]mmtypes.ProviderConfig, error)
- func ConvertMarketParamsToMarketMap(params dydxtypes.QueryAllMarketParamsResponse) (mmtypes.MarketMapResponse, error)
- func CreateCurrencyPairFromPair(pair string) (connecttypes.CurrencyPair, error)
- func CreateTickerFromMarket(market dydxtypes.MarketParam) (mmtypes.Ticker, error)
- func ExtractMetadata(providerName string, cfg dydxtypes.ExchangeMarketConfigJson) (string, error)
- func NewDefaultSwitchOverMarketMapFetcher(logger *zap.Logger, api config.APIConfig, rh apihandlers.RequestHandler, ...) (mmclient.MarketMapFetcher, error)
- func NewSwitchOverFetcher(logger *zap.Logger, pricesFetcher mmclient.MarketMapFetcher, ...) (mmclient.MarketMapFetcher, error)
- func RaydiumMetadataFromTicker(ticker string) (string, error)
- func UniswapV3MetadataFromTicker(ticker string, invert bool) (string, error)
- type APIHandler
- type MultiMarketMapRestAPIFetcher
- type ResearchAPIHandler
- type SwitchOverFetcher
Constants ¶
const ( // Name is the name of the MarketMap provider. Name = "dydx_api" // SwitchOverAPIHandlerName is the name of the dYdX switch over API. SwitchOverAPIHandlerName = "dydx_migration_api" // ResearchAPIHandlerName is the name of the dYdX research json API. ResearchAPIHandlerName = "dydx_research_json_api" // ResearchCMCAPIHandlerName is the name of the dYdX research json API that only returns CoinMarketCap markets. ResearchCMCAPIHandlerName = "dydx_research_coinmarketcap_api" // ChainID is the chain ID for the dYdX market map provider. ChainID = "dydx-node" // Endpoint is the endpoint for the dYdX market map API. Endpoint = "%s/dydxprotocol/prices/params/market?pagination.limit=10000" // Delimiter is the delimiter used to separate the base and quote assets in a pair. Delimiter = "-" // UniswapV3TickerFields is the number of fields to expect to parse from a UniswapV3 ticker. UniswapV3TickerFields = 3 // UniswapV3TickerSeparator is the separator for fields contained within a ticker for a uniswapv3_api provider. UniswapV3TickerSeparator = Delimiter // RaydiumTickerFields is the minimum number of fields to expect the raydium exchange ticker to have. RaydiumTickerFields = 8 // RaydiumTickerSeparator is the separator for fields contained within a ticker for the raydium provider. RaydiumTickerSeparator = Delimiter )
Variables ¶
var ( DYDXChain = mmclient.Chain{ ChainID: ChainID, } )
var DefaultAPIConfig = config.APIConfig{ Name: Name, Atomic: true, Enabled: true, Timeout: 20 * time.Second, Interval: 10 * time.Second, ReconnectTimeout: 2000 * time.Millisecond, MaxQueries: 1, Endpoints: []config.Endpoint{{URL: "http://localhost:1317"}}, }
DefaultAPIConfig returns the default configuration for the dYdX market map API.
var DefaultResearchAPIConfig = config.APIConfig{ Name: ResearchAPIHandlerName, Atomic: true, Enabled: true, Timeout: 20 * time.Second, Interval: 10 * time.Second, ReconnectTimeout: 2000 * time.Millisecond, MaxQueries: 1, Endpoints: []config.Endpoint{ { URL: "https://dydx-api.lavenderfive.com", }, { URL: "https://raw.githubusercontent.com/dydxprotocol/v4-web/main/public/configs/otherMarketData.json", }, }, }
DefaultResearchAPIConfig returns the default configuration for the dYdX market map API.
var DefaultResearchCMCAPIConfig = config.APIConfig{ Name: ResearchCMCAPIHandlerName, Atomic: true, Enabled: true, Timeout: 20 * time.Second, Interval: 10 * time.Second, ReconnectTimeout: 2000 * time.Millisecond, MaxQueries: 1, Endpoints: []config.Endpoint{ { URL: "https://dydx-api.lavenderfive.com", }, { URL: "https://raw.githubusercontent.com/dydxprotocol/v4-web/main/public/configs/otherMarketData.json", }, }, }
DefaultResearchCMCAPIConfig returns the default configuration for the dYdX market map API that only returns CoinMarketCap markets.
var DefaultSwitchOverAPIConfig = config.APIConfig{ Name: SwitchOverAPIHandlerName, Atomic: true, Enabled: true, Timeout: 20 * time.Second, Interval: 10 * time.Second, ReconnectTimeout: 2000 * time.Millisecond, MaxQueries: 1, Endpoints: []config.Endpoint{ { URL: "http://localhost:1317", }, { URL: "localhost:9090", }, }, }
DefaultSwitchOverAPIConfig returns the default configuration for the dYdX switch over API provider.
var ProviderMapping = map[string]string{ "Binance": binance.Name, "BinanceUS": binance.Name, "Bitfinex": bitfinex.Name, "Kraken": kraken.Name, "Gate": gate.Name, "Bitstamp": bitstamp.Name, "Bybit": bybit.Name, "CryptoCom": cryptodotcom.Name, "Huobi": huobi.Name, "Kucoin": kucoin.Name, "Okx": okx.Name, "Mexc": mexc.Name, "CoinbasePro": coinbase.Name, "TestVolatileExchange": volatile.Name, "Raydium": raydium.Name, "UniswapV3-Ethereum": uniswapv3.ProviderNames[constants.ETHEREUM], "UniswapV3-Base": uniswapv3.ProviderNames[constants.BASE], coinmarketcap.Name: coinmarketcap.Name, }
ProviderMapping is referencing the different providers that are supported by the dYdX market params.
Functions ¶
func ConvertDenomByProvider ¶
ConvertDenomByProvider converts a given denom to a format that is compatible with a given provider. Specifically, this is used to convert API to WebSocket representations of denoms where necessary.
func ConvertExchangeConfigJSON ¶
func ConvertExchangeConfigJSON( config dydxtypes.ExchangeConfigJson, ) ([]mmtypes.ProviderConfig, error)
ConvertExchangeConfigJSON creates a set of paths and providers for a given ticker from a dYdX market. These paths represent the different ways to convert a currency pair using the dYdX market.
func ConvertMarketParamsToMarketMap ¶
func ConvertMarketParamsToMarketMap( params dydxtypes.QueryAllMarketParamsResponse, ) (mmtypes.MarketMapResponse, error)
ConvertMarketParamsToMarketMap converts a dYdX market params response to a connect market map response.
func CreateCurrencyPairFromPair ¶
func CreateCurrencyPairFromPair(pair string) (connecttypes.CurrencyPair, error)
CreateCurrencyPairFromPair creates a currency pair from a dYdX market.
func CreateTickerFromMarket ¶
func CreateTickerFromMarket(market dydxtypes.MarketParam) (mmtypes.Ticker, error)
CreateTickerFromMarket creates a ticker from a dYdX market.
func ExtractMetadata ¶
func ExtractMetadata(providerName string, cfg dydxtypes.ExchangeMarketConfigJson) (string, error)
ExtractMetadata extracts Metadata_JSON from ExchangeMarketConfigJson, based on the converted provider name.
func NewDefaultSwitchOverMarketMapFetcher ¶
func NewDefaultSwitchOverMarketMapFetcher( logger *zap.Logger, api config.APIConfig, rh apihandlers.RequestHandler, metrics metrics.APIMetrics, ) (mmclient.MarketMapFetcher, error)
NewDefaultSwitchOverMarketMapFetcher returns a new SwitchOverProvider with the default dYdX x/prices and x/marketmap fetchers.
func NewSwitchOverFetcher ¶
func NewSwitchOverFetcher( logger *zap.Logger, pricesFetcher mmclient.MarketMapFetcher, marketmapFetcher mmclient.MarketMapFetcher, metrics metrics.APIMetrics, ) (mmclient.MarketMapFetcher, error)
NewSwitchOverFetcher returns a new SwitchOverFetcher with the provided fetchers.
func RaydiumMetadataFromTicker ¶
RaydiumMetadataFromTicker extracts json-metadata from a ticker for Raydium. All raydium tickers on dydx will be formatted as follows (BASE-QUOTE-BASE_VAULT-BASE_DECIMALS-QUOTE_VAULT-QUOTE_DECIMALS-OPEN_ORDERS_ADDRESS-AMM_INFO_ADDRESS).
Types ¶
type APIHandler ¶
type APIHandler struct {
// contains filtered or unexported fields
}
APIHandler implements the MarketMapAPIDataHandler interface for the dYdX prices module, which can be used by a base provider. This is specifically for fetching market data from the dYdX prices module, which is then translated to a market map.
func NewAPIHandler ¶
NewAPIHandler returns a new MarketMap MarketMapAPIDataHandler.
func (*APIHandler) CreateURL ¶
func (h *APIHandler) CreateURL(chains []types.Chain) (string, error)
CreateURL returns the URL that is used to fetch the latest market map data from the dYdX prices module.
func (*APIHandler) ParseResponse ¶
func (h *APIHandler) ParseResponse( chains []types.Chain, resp *http.Response, ) types.MarketMapResponse
ParseResponse parses the response from the x/prices API and returns the resolved and unresolved market map data. The response from the MarketMap API is expected to be a a single market map object that was converted from the dYdX market params response.
type MultiMarketMapRestAPIFetcher ¶
type MultiMarketMapRestAPIFetcher struct {
// contains filtered or unexported fields
}
MultiMarketMapRestAPIFetcher is an implementation of a RestAPIFetcher that wraps two underlying Fetchers for fetching the market-map according to dydx mainnet and the additional markets that can be added according to the dydx research json.
func DefaultDYDXResearchMarketMapFetcher ¶
func DefaultDYDXResearchMarketMapFetcher( rh apihandlers.RequestHandler, metrics metrics.APIMetrics, api config.APIConfig, logger *zap.Logger, ) (*MultiMarketMapRestAPIFetcher, error)
DefaultDYDXResearchMarketMapFetcher returns a MultiMarketMapFetcher composed of dydx mainnet + research apiDataHandlers.
func NewDYDXResearchMarketMapFetcher ¶
func NewDYDXResearchMarketMapFetcher( mainnetFetcher, researchFetcher mmclient.MarketMapFetcher, logger *zap.Logger, isCMCOnly bool, ) *MultiMarketMapRestAPIFetcher
NewDYDXResearchMarketMapFetcher returns an aggregated market-map among the dydx mainnet and the dydx research json.
func (*MultiMarketMapRestAPIFetcher) Fetch ¶
func (f *MultiMarketMapRestAPIFetcher) Fetch(ctx context.Context, chains []mmclient.Chain) mmclient.MarketMapResponse
Fetch fetches the market map from the underlying fetchers and combines the results. If any of the underlying fetchers fetch for a chain that is different from the chain that the fetcher is initialized with, those responses will be ignored.
type ResearchAPIHandler ¶
type ResearchAPIHandler struct { APIHandler // contains filtered or unexported fields }
ResearchAPIHandler is a subclass of the dydx_chain.ResearchAPIHandler. It interprets the dydx ResearchJSON as a market-map.
func NewResearchAPIHandler ¶
func NewResearchAPIHandler( logger *zap.Logger, api config.APIConfig, ) (*ResearchAPIHandler, error)
NewResearchAPIHandler returns a new MarketMap MarketMapAPIDataHandler.
func (*ResearchAPIHandler) CreateURL ¶
func (h *ResearchAPIHandler) CreateURL(chains []types.Chain) (string, error)
CreateURL returns a static url (the url of the first configured endpoint). If the dydx chain is not configured in the request, an error is returned.
func (*ResearchAPIHandler) ParseResponse ¶
func (h *ResearchAPIHandler) ParseResponse( chains []types.Chain, resp *http.Response, ) types.MarketMapResponse
ParseResponse parses the response from the dydx ResearchJSON API into a MarketMap, and unmarshals the market-map in accordance with the underlying dydx ResearchAPIHandler.
type SwitchOverFetcher ¶
type SwitchOverFetcher struct {
// contains filtered or unexported fields
}
SwitchOverFetcher is an implementation of a RestAPIFetcher that wraps a dydx x/prices market map fetcher and a x/marketmap fetcher. The fetcher operates by first fetching the market map from the x/prices API and then fetching the market map from the x/marketmap API. The fetcher will switch over to the x/marketmap API the first time it receives a non-nil market map from the x/marketmap API.
func (*SwitchOverFetcher) Fetch ¶
func (f *SwitchOverFetcher) Fetch( ctx context.Context, chains []mmclient.Chain, ) mmclient.MarketMapResponse
Fetch fetches the market map from the x/prices API and then the x/marketmap API. The fetcher will switch over to the x/marketmap API the first time it receives a non-nil market map from the x/marketmap API.