cryptodatapy.extract.exchanges ============================== .. py:module:: cryptodatapy.extract.exchanges Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/cryptodatapy/extract/exchanges/dydx/index /autoapi/cryptodatapy/extract/exchanges/exchange/index Classes ------- .. autoapisummary:: cryptodatapy.extract.exchanges.Exchange cryptodatapy.extract.exchanges.Dydx Package Contents ---------------- .. py:class:: Exchange(name, exch_type, is_active, categories, assets, markets, market_types, fields, frequencies, fees, base_url, api_key, max_obs_per_call, rate_limit) Bases: :py:obj:`abc.ABC` Abstract base class for crypto exchanges (CEX or DEX). This class provides a blueprint for interacting with crypto exchanges, including authentication, data retrieval, and trading functionality. .. py:property:: name Returns the type of exchange. .. py:property:: exch_type Returns the type of exchange. .. py:property:: is_active Returns whether the exchange is active. .. py:property:: categories Returns a list of available categories for the data vendor. .. py:property:: assets Returns a list of available assets for the data vendor. .. py:property:: markets Returns a list of available markets for the data vendor. .. py:property:: market_types Returns a list of available market types for the data vendor. .. py:property:: fields Returns a list of available fields for the data vendor. .. py:property:: frequencies Returns a list of available data frequencies for the data vendor. .. py:property:: fees Returns a list of fees for the data vendor. .. py:property:: base_url Returns the base url for the data vendor. .. py:property:: api_key Returns the api key for the data vendor. .. py:property:: max_obs_per_call Returns the maximum observations per API call for the data vendor. .. py:property:: rate_limit Returns the number of API calls made and remaining. .. py:method:: get_assets_info() :abstractmethod: Gets info for available assets from the data vendor. .. py:method:: get_markets_info() :abstractmethod: Gets info for available markets from the data vendor. .. py:method:: get_fields_info(data_type: Optional[str]) :abstractmethod: Gets info for available fields from the data vendor. .. py:method:: get_frequencies_info(data_type: Optional[str]) :abstractmethod: Gets info for available frequencies from the exchange. .. py:method:: get_rate_limit_info() :abstractmethod: Gets the number of API calls made and remaining. .. py:method:: get_metadata() -> None :abstractmethod: Get exchange metadata. .. py:method:: get_data(data_req) -> pandas.DataFrame :abstractmethod: Submits get data request to API. .. py:method:: _wrangle_data_resp(data_req: cryptodatapy.extract.datarequest.DataRequest, data_resp: Union[Dict[str, Any], pandas.DataFrame]) -> pandas.DataFrame :staticmethod: :abstractmethod: Wrangles data response from data vendor API into tidy format. .. py:class:: Dydx(name: str = 'dydx', exch_type: str = 'dex', is_active: bool = True, categories: Union[str, List[str]] = 'crypto', assets: Optional[Dict[str, List[str]]] = None, markets: Optional[Dict[str, List[str]]] = None, market_types: List[str] = ['perpetual_future'], fields: Optional[List[str]] = ['open', 'high', 'low', 'close', 'volume', 'funding_rate'], frequencies: Optional[Dict[str, Union[str, int]]] = {'1m': '1MIN', '5m': '5MINS', '15m': '15MINS', '1h': '1HOUR', '4h': '4HOURS', '1d': '1DAY'}, fees: Optional[Dict[str, float]] = {'perpetual_future': {'maker': 0.0, 'taker': 0.0}}, base_url: Optional[str] = 'https://indexer.dydx.trade/v4', api_key: Optional[str] = None, max_obs_per_call: Optional[int] = 1000, rate_limit: Optional[Any] = None) Bases: :py:obj:`cryptodatapy.extract.exchanges.exchange.Exchange` Retrieves data from dydx exchange. .. py:attribute:: data_req :value: None .. py:attribute:: data .. py:method:: get_assets_info() -> pandas.DataFrame Gets info for available assets from dYdX. :returns: DataFrame with asset information. :rtype: pd.DataFrame .. py:method:: get_markets_info(quote_ccy: Optional[str] = None, mkt_type: Optional[str] = None, as_list: bool = False) -> Union[pandas.DataFrame, List[str]] Gets info for available markets from dYdX. :param quote_ccy: Quote currency to filter by (e.g., 'USD', 'USDC'). For dYdX, this is typically 'USD'. :type quote_ccy: str, optional :param mkt_type: Market type to filter by. For dYdX, this is typically 'perpetual_future'. :type mkt_type: str, optional :param as_list: If True, returns a list of ticker symbols instead of a DataFrame. :type as_list: bool, default False :returns: DataFrame with market information or list of ticker symbols. :rtype: pd.DataFrame or List[str] .. py:method:: get_fields_info(data_type: Optional[str] = None) -> pandas.DataFrame Gets info for available fields from dYdX. :param data_type: Type of data for which to return field information. :type data_type: str, optional :returns: DataFrame with field information. :rtype: pd.DataFrame .. py:method:: get_frequencies_info() -> pandas.DataFrame Gets info for available frequencies from dYdX. :returns: DataFrame with frequency information. :rtype: pd.DataFrame .. py:method:: get_rate_limit_info() -> Dict[str, Any] Gets rate limit information from dYdX. :returns: Dictionary with rate limit information. :rtype: Dict[str, Any] .. py:method:: get_metadata() -> Dict[str, Any] Gets metadata about the exchange. :returns: Dictionary with exchange metadata. :rtype: Dict[str, Any] .. py:method:: _fetch_ohlcv() -> pandas.DataFrame Fetches OHLCV data from dYdX for multiple markets with pagination support. The dYdX candles API has a limit (typically 1000 records) and returns data in reverse chronological order (newest first). For large date ranges, we need to implement pagination to retrieve all historical data. :returns: DataFrame with OHLCV data for all requested markets. :rtype: pd.DataFrame .. py:method:: _fetch_funding_rates() -> pandas.DataFrame Fetches funding rate data from dYdX for multiple markets with pagination support. Note: dYdX charges funding every hour, unlike other exchanges that typically use 8-hour funding cycles. This method retrieves the complete historical funding rate data for any requested date range, making multiple API calls as needed. :returns: DataFrame with hourly funding rate data for all requested markets. :rtype: pd.DataFrame .. py:method:: _fetch_open_interest() -> pandas.DataFrame Fetches current open interest from dYdX. Note: This implementation only provides current open interest values, not historical data. Historical open interest data is not available through the dYdX API. :returns: DataFrame with current open interest values. The DataFrame has a MultiIndex with 'date' and 'ticker' levels. The 'date' index will be the current timestamp for all entries. :rtype: pd.DataFrame .. py:method:: _convert_params() -> None Converts parameters for the data request using ConvertParams class. .. py:method:: _wrangle_data_resp(data_req: cryptodatapy.extract.datarequest.DataRequest, data_resp: Union[Dict[str, Any], pandas.DataFrame]) -> pandas.DataFrame :staticmethod: Wrangles data response from dYdX using WrangleData class. :param data_req: Parameters of data request. :type data_req: DataRequest :param data_resp: Data response from dYdX. :type data_resp: Union[Dict[str, Any], pd.DataFrame] :returns: Wrangled DataFrame. :rtype: pd.DataFrame .. py:method:: _fetch_tidy_ohlcv() -> pandas.DataFrame Fetches and tidies OHLCV data. :returns: Tidy DataFrame with OHLCV data. :rtype: pd.DataFrame .. py:method:: _fetch_tidy_funding_rates() -> pandas.DataFrame Fetches and tidies funding rates. :returns: Tidy DataFrame with funding rates. :rtype: pd.DataFrame .. py:method:: _fetch_tidy_open_interest() -> pandas.DataFrame Fetches and tidies open interest. :returns: Tidy DataFrame with open interest. :rtype: pd.DataFrame .. py:method:: get_data(data_req: cryptodatapy.extract.datarequest.DataRequest) -> pandas.DataFrame Gets market data from dYdX. :param data_req: Parameters of data request. :type data_req: DataRequest :returns: DataFrame with market data. :rtype: pd.DataFrame