cryptodatapy.extract.exchanges

Submodules

Classes

Exchange

Abstract base class for crypto exchanges (CEX or DEX).

Dydx

Retrieves data from dydx exchange.

Package Contents

class cryptodatapy.extract.exchanges.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: 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.

property name

Returns the type of exchange.

property exch_type

Returns the type of exchange.

property is_active

Returns whether the exchange is active.

property categories

Returns a list of available categories for the data vendor.

property assets

Returns a list of available assets for the data vendor.

property markets

Returns a list of available markets for the data vendor.

property market_types

Returns a list of available market types for the data vendor.

property fields

Returns a list of available fields for the data vendor.

property frequencies

Returns a list of available data frequencies for the data vendor.

property fees

Returns a list of fees for the data vendor.

property base_url

Returns the base url for the data vendor.

property api_key

Returns the api key for the data vendor.

property max_obs_per_call

Returns the maximum observations per API call for the data vendor.

property rate_limit

Returns the number of API calls made and remaining.

abstractmethod get_assets_info()

Gets info for available assets from the data vendor.

abstractmethod get_markets_info()

Gets info for available markets from the data vendor.

abstractmethod get_fields_info(data_type: str | None)

Gets info for available fields from the data vendor.

abstractmethod get_frequencies_info(data_type: str | None)

Gets info for available frequencies from the exchange.

abstractmethod get_rate_limit_info()

Gets the number of API calls made and remaining.

abstractmethod get_metadata() None

Get exchange metadata.

abstractmethod get_data(data_req) pandas.DataFrame

Submits get data request to API.

static _wrangle_data_resp(data_req: cryptodatapy.extract.datarequest.DataRequest, data_resp: Dict[str, Any] | pandas.DataFrame) pandas.DataFrame
Abstractmethod:

Wrangles data response from data vendor API into tidy format.

class cryptodatapy.extract.exchanges.Dydx(name: str = 'dydx', exch_type: str = 'dex', is_active: bool = True, categories: str | List[str] = 'crypto', assets: Dict[str, List[str]] | None = None, markets: Dict[str, List[str]] | None = None, market_types: List[str] = ['perpetual_future'], fields: List[str] | None = ['open', 'high', 'low', 'close', 'volume', 'funding_rate'], frequencies: Dict[str, str | int] | None = {'1m': '1MIN', '5m': '5MINS', '15m': '15MINS', '1h': '1HOUR', '4h': '4HOURS', '1d': '1DAY'}, fees: Dict[str, float] | None = {'perpetual_future': {'maker': 0.0, 'taker': 0.0}}, base_url: str | None = 'https://indexer.dydx.trade/v4', api_key: str | None = None, max_obs_per_call: int | None = 1000, rate_limit: Any | None = None)

Bases: cryptodatapy.extract.exchanges.exchange.Exchange

Retrieves data from dydx exchange.

data_req = None
data
get_assets_info() pandas.DataFrame

Gets info for available assets from dYdX.

Returns:

DataFrame with asset information.

Return type:

pd.DataFrame

get_markets_info(quote_ccy: str | None = None, mkt_type: str | None = None, as_list: bool = False) pandas.DataFrame | List[str]

Gets info for available markets from dYdX.

Parameters:
  • quote_ccy (str, optional) – Quote currency to filter by (e.g., ‘USD’, ‘USDC’). For dYdX, this is typically ‘USD’.

  • mkt_type (str, optional) – Market type to filter by. For dYdX, this is typically ‘perpetual_future’.

  • as_list (bool, default False) – If True, returns a list of ticker symbols instead of a DataFrame.

Returns:

DataFrame with market information or list of ticker symbols.

Return type:

pd.DataFrame or List[str]

get_fields_info(data_type: str | None = None) pandas.DataFrame

Gets info for available fields from dYdX.

Parameters:

data_type (str, optional) – Type of data for which to return field information.

Returns:

DataFrame with field information.

Return type:

pd.DataFrame

get_frequencies_info() pandas.DataFrame

Gets info for available frequencies from dYdX.

Returns:

DataFrame with frequency information.

Return type:

pd.DataFrame

get_rate_limit_info() Dict[str, Any]

Gets rate limit information from dYdX.

Returns:

Dictionary with rate limit information.

Return type:

Dict[str, Any]

get_metadata() Dict[str, Any]

Gets metadata about the exchange.

Returns:

Dictionary with exchange metadata.

Return type:

Dict[str, Any]

_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.

Return type:

pd.DataFrame

_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.

Return type:

pd.DataFrame

_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.

Return type:

pd.DataFrame

_convert_params() None

Converts parameters for the data request using ConvertParams class.

static _wrangle_data_resp(data_req: cryptodatapy.extract.datarequest.DataRequest, data_resp: Dict[str, Any] | pandas.DataFrame) pandas.DataFrame

Wrangles data response from dYdX using WrangleData class.

Parameters:
  • data_req (DataRequest) – Parameters of data request.

  • data_resp (Union[Dict[str, Any], pd.DataFrame]) – Data response from dYdX.

Returns:

Wrangled DataFrame.

Return type:

pd.DataFrame

_fetch_tidy_ohlcv() pandas.DataFrame

Fetches and tidies OHLCV data.

Returns:

Tidy DataFrame with OHLCV data.

Return type:

pd.DataFrame

_fetch_tidy_funding_rates() pandas.DataFrame

Fetches and tidies funding rates.

Returns:

Tidy DataFrame with funding rates.

Return type:

pd.DataFrame

_fetch_tidy_open_interest() pandas.DataFrame

Fetches and tidies open interest.

Returns:

Tidy DataFrame with open interest.

Return type:

pd.DataFrame

get_data(data_req: cryptodatapy.extract.datarequest.DataRequest) pandas.DataFrame

Gets market data from dYdX.

Parameters:

data_req (DataRequest) – Parameters of data request.

Returns:

DataFrame with market data.

Return type:

pd.DataFrame