cryptodatapy.extract.libraries.ccxt_api ======================================= .. py:module:: cryptodatapy.extract.libraries.ccxt_api Attributes ---------- .. autoapisummary:: cryptodatapy.extract.libraries.ccxt_api.data_cred Classes ------- .. autoapisummary:: cryptodatapy.extract.libraries.ccxt_api.CCXT Module Contents --------------- .. py:data:: data_cred .. py:class:: CCXT(categories: Union[str, List[str]] = 'crypto', exchanges: Optional[List[str]] = None, indexes: Optional[List[str]] = None, assets: Optional[Dict[str, List[str]]] = None, markets: Optional[Dict[str, List[str]]] = None, market_types: List[str] = ['spot', 'future', 'perpetual_future', 'option'], fields: Optional[List[str]] = ['open', 'high', 'low', 'close', 'volume', 'funding_rate', 'oi'], frequencies: Optional[Dict[str, Union[str, int]]] = None, base_url: Optional[str] = None, api_key: Optional[str] = None, max_obs_per_call: Optional[int] = 1000, rate_limit: Optional[Any] = None, ip_ban_wait_time_s: float = 320.0, recovery_base_delay_s: float = 2.0, max_recovery_delay_s: float = 60.0) Bases: :py:obj:`cryptodatapy.extract.libraries.library.Library` Retrieves data from CCXT API. .. py:attribute:: exchange :value: None .. py:attribute:: exchange_async :value: None .. py:attribute:: data_req :value: None .. py:attribute:: ip_ban_wait_time_s :value: 320.0 .. py:attribute:: recovery_base_delay_s :value: 2.0 .. py:attribute:: max_recovery_delay_s :value: 60.0 .. py:attribute:: data_resp :value: [] .. py:attribute:: data .. py:method:: get_exchanges_info() -> List[str] Get exchanges info. :returns: **exch** -- List or dataframe with info on supported exchanges. :rtype: list or pd.DataFrame .. py:method:: get_indexes_info() -> None Get indexes info. .. py:method:: get_assets_info(exch: str, as_list: bool = False) -> Union[pandas.DataFrame, List[str]] Get assets info. :param exch: Name of exchange. :type exch: str :param as_list: Returns assets info for selected exchanges as list. :type as_list: bool, default False :returns: **assets** -- Dataframe with info on available assets or list of assets. :rtype: list or pd.DataFrame .. py:method:: get_markets_info(exch: str, quote_ccy: Optional[str] = None, mkt_type: Optional[str] = None, as_list: bool = False) -> Union[pandas.DataFrame, List[str]] Get markets info. :param exch: Name of exchange. :type exch: str :param quote_ccy: Quote currency. :type quote_ccy: str, optional, default None :param mkt_type: Market type. :type mkt_type: str, {'spot', 'future', 'perpetual_future', 'option'}, optional, default None :param as_list: Returns markets info as list for selected exchange. :type as_list: bool, default False :returns: **markets** -- List or dataframe with info on available markets, by exchange. :rtype: list or pd.DataFrame .. py:method:: get_fields_info() -> List[str] Get fields info. :returns: **fields** -- List of available fields. :rtype: list .. py:method:: get_frequencies_info(exch: str) -> Dict[str, Union[str, int]] Get frequencies info. :param exch: Name of exchange for which to get available assets. :type exch: str :returns: **freq** -- Dictionary with info on available frequencies. :rtype: dictionary .. py:method:: get_rate_limit_info(exch: str) -> Dict[str, Union[str, int]] Get rate limit info. :param exch: Name of exchange. :type exch: str :returns: **rate_limit** -- Dictionary with exchange and required minimal delay between HTTP requests that exchange in milliseconds. :rtype: dictionary .. py:method:: get_metadata(exch: str) -> None Get CCXT metadata. :param exch: Name of exchange. :type exch: str .. py:method:: exponential_backoff_with_jitter(attempts: int, status_code: Optional[int] = None) -> float Calculates and applies exponential backoff with full jitter, honoring specific error codes (403/429) using configurable instance properties. :param attempts: The current retry number (starting at 1 after the first failure). :param status_code: The HTTP status code received (e.g., 403, 429). :returns: The actual time slept in seconds. .. py:method:: exponential_backoff_with_jitter_async(attempts: int, status_code: Optional[int] = None) -> float :async: Async version of exponential_backoff_with_jitter, using configurable instance properties. .. py:method:: _handle_exception_and_backoff(e: Exception, attempts: int) -> bool Analyzes a synchronous exception, applies backoff if recoverable, and logs the result. :returns: True if the error was recoverable (retries should continue). False if the error is terminal (retries should stop). .. py:method:: _handle_exception_and_backoff_async(e: Exception, attempts: int) -> bool :async: Analyzes an asynchronous exception, applies backoff if recoverable, and logs the result. :returns: True if the error was recoverable (retries should continue). False if the error is terminal (retries should stop). .. py:method:: _fetch_ohlcv_async(ticker: str, freq: str, start_date: int, end_date: int, exch: str, trials: int = 3) -> Union[List, None] :async: Fetches OHLCV data for a specific ticker. :param ticker: Ticker symbol. :type ticker: str :param freq: Frequency of data, e.g. '1m', '5m', '1h', '1d'. :type freq: str :param start_date: Start date in integers in milliseconds since Unix epoch. :type start_date: str :param end_date: End date in integers in milliseconds since Unix epoch. :type end_date: str :param exch: Name of exchange. :type exch: str :param trials: Number of attempts to fetch data. :type trials: int, default 3 :returns: **data_resp** -- List of timestamps with OHLCV data. :rtype: list .. py:method:: _fetch_ohlcv(ticker: str, freq: str, start_date: str, end_date: str, exch: str, trials: int = 3) -> Union[List, None] Fetches OHLCV data for a specific ticker. :param ticker: Ticker symbol. :type ticker: str :param freq: Frequency of data, e.g. '1m', '5m', '1h', '1d'. :type freq: str :param start_date: Start date in integers in milliseconds since Unix epoch. :type start_date: str :param end_date: End date in integers in milliseconds since Unix epoch. :type end_date: str :param exch: Name of exchange. :type exch: str :param trials: Number of attempts to fetch data. :type trials: int, default 3 :returns: **data_resp** -- List of timestamps with OHLCV data. :rtype: list .. py:method:: _fetch_all_ohlcv_async(tickers, freq: str, start_date: int, end_date: int, exch: str, trials: int = 3, pause: int = 1) -> Union[List, None] :async: Fetches OHLCV data for a list of tickers. :param tickers: List of ticker symbols. :type tickers: list :param freq: Frequency of data, e.g. '1m', '5m', '1h', '1d'. :type freq: str :param start_date: Start date in integers in milliseconds since Unix epoch. :type start_date: int :param end_date: End date in integers in milliseconds since Unix epoch. :type end_date: int :param exch: Name of exchange. :type exch: str :param trials: Number of attempts to fetch data. :type trials: int, default 3 :param pause: Pause in seconds to respect the rate limit. :type pause: int, default 0.5 :returns: **data_resp** -- List of lists of timestamps and OHLCV data for each ticker. :rtype: list .. py:method:: _fetch_all_ohlcv(tickers, freq: str, start_date: int, end_date: int, exch: str, trials: int = 3, pause: int = 1) -> Union[List, None] Fetches OHLCV data for a list of tickers. :param tickers: List of ticker symbols. :type tickers: list :param freq: Frequency of data, e.g. '1m', '5m', '1h', '1d'. :type freq: str :param start_date: Start date in integers in milliseconds since Unix epoch. :type start_date: int :param end_date: End date in integers in milliseconds since Unix epoch. :type end_date: int :param exch: Name of exchange. :type exch: str :param trials: Number of attempts to fetch data. :type trials: int, default 3 :param pause: Pause in seconds to respect the rate limit. :type pause: int, default 0.5 :returns: **data_resp** -- List of lists of timestamps and OHLCV data for each ticker. :rtype: list .. py:method:: _fetch_funding_rates_async(ticker: str, start_date: int, end_date: int, exch: str, trials: int = 3) -> Union[List, None] :async: Fetches funding rates data for a specific ticker. :param ticker: Ticker symbol. :type ticker: str :param start_date: Start date in integers in milliseconds since Unix epoch. :type start_date: int :param end_date: End date in integers in milliseconds since Unix epoch. :type end_date: int :param trials: Number of attempts to fetch data. :type trials: int, default 3 :returns: **data_resp** -- List of dictionaries with timestamps and funding rates data. :rtype: list .. py:method:: _fetch_funding_rates(ticker: str, start_date: int, end_date: int, exch: str, trials: int = 3) -> Union[List, None] Fetches funding rates data for a specific ticker. :param ticker: Ticker symbol. :type ticker: str :param start_date: Start date in integers in milliseconds since Unix epoch. :type start_date: int :param end_date: End date in integers in milliseconds since Unix epoch. :type end_date: int :param trials: Number of attempts to fetch data. :type trials: int, default 3 :returns: **data_resp** -- List of dictionaries with timestamps and funding rates data. :rtype: list .. py:method:: _fetch_all_funding_rates_async(tickers, start_date: int, end_date: int, exch: str, trials: int = 3, pause: int = 1) -> Union[List, None] :async: Fetches funding rates data for a list of tickers. :param tickers: List of ticker symbols. :type tickers: list :param start_date: Start date in integers in milliseconds since Unix epoch. :type start_date: int :param end_date: End date in integers in milliseconds since Unix epoch. :type end_date: int :param exch: Name of exchange. :type exch: str :param trials: Number of attempts to fetch data. :type trials: int, default 3 :param pause: Pause in seconds to respect the rate limit. :type pause: int, default 0.5 :returns: **data_resp** -- List of lists of dictionaries with timestamps and funding rates data for each ticker. :rtype: list .. py:method:: _fetch_all_funding_rates(tickers, start_date: int, end_date: int, exch: str, trials: int = 3, pause: int = 1) -> Union[List, None] Fetches funding rates data for a list of tickers. :param tickers: List of ticker symbols. :type tickers: list :param start_date: Start date in integers in milliseconds since Unix epoch. :type start_date: int :param end_date: End date in integers in milliseconds since Unix epoch. :type end_date: int :param exch: Name of exchange. :type exch: str :param trials: Number of attempts to fetch data. :type trials: int, default 3 :param pause: Pause in seconds to respect the rate limit. :type pause: int, default 0.5 :returns: **data_resp** -- List of lists of dictionaries with timestamps and funding rates data for each ticker. :rtype: list .. py:method:: _fetch_open_interest_async(ticker: str, freq: str, start_date: int, end_date: int, exch: str, trials: int = 3) -> Union[List, None] :async: Fetches open interest data for a specific ticker. :param ticker: Ticker symbol. :type ticker: str :param freq: Frequency of data, e.g. '1m', '5m', '1h', '1d'. :type freq: str :param start_date: Start date in integers in milliseconds since Unix epoch. :type start_date: int :param end_date: End date in integers in milliseconds since Unix epoch. :type end_date: int :param exch: Name of exchange. :type exch: str :param trials: Number of attempts to fetch data. :type trials: int, default 3 :returns: **data_resp** -- List of dictionaries with timestamps and open interest data. :rtype: list .. py:method:: _fetch_open_interest(ticker: str, freq: str, start_date: int, end_date: int, exch: str, trials: int = 3) -> Union[List, None] Fetches open interest data for a specific ticker. :param ticker: Ticker symbol. :type ticker: str :param freq: Frequency of data, e.g. '1m', '5m', '1h', '1d'. :type freq: str :param start_date: Start date in integers in milliseconds since Unix epoch. :type start_date: int :param end_date: End date in integers in milliseconds since Unix epoch. :type end_date: int :param exch: Name of exchange. :type exch: str :param trials: Number of attempts to fetch data. :type trials: int, default 3 :returns: **data_resp** -- List of dictionaries with timestamps and open interest data. :rtype: list .. py:method:: _fetch_all_open_interest_async(tickers, freq: str, start_date: int, end_date: int, exch: str, trials: int = 3, pause: int = 1) -> Union[List, None] :async: Fetches open interest data for a list of tickers. :param tickers: List of ticker symbols. :type tickers: list :param freq: Frequency of data, e.g. '1m', '5m', '1h', '1d'. :type freq: str :param start_date: Start date in integers in milliseconds since Unix epoch. :type start_date: int :param end_date: End date in integers in milliseconds since Unix epoch. :type end_date: int :param exch: Name of exchange. :type exch: str :param trials: Number of attempts to fetch data. :type trials: int, default 3 :param pause: Pause in seconds to respect the rate limit. :type pause: int, default 0.5 :returns: **data_resp** -- List of lists of dictionaries with timestamps and open interest data for each ticker. :rtype: list .. py:method:: _fetch_all_open_interest(tickers, freq: str, start_date: int, end_date: int, exch: str, trials: int = 3, pause: int = 1) -> Union[List, None] Fetches open interest data for a list of tickers. :param tickers: List of ticker symbols. :type tickers: list :param freq: Frequency of data, e.g. '1m', '5m', '1h', '1d'. :type freq: str :param start_date: Start date in integers in milliseconds since Unix epoch. :type start_date: int :param end_date: End date in integers in milliseconds since Unix epoch. :type end_date: int :param exch: Name of exchange. :type exch: str :param trials: Number of attempts to fetch data. :type trials: int, default 3 :param pause: Pause in seconds to respect the rate limit. :type pause: int, default 0.5 :returns: **data_resp** -- List of lists of dictionaries with timestamps and open interest data for each ticker. :rtype: list .. py:method:: convert_params(data_req: cryptodatapy.extract.datarequest.DataRequest) -> cryptodatapy.extract.datarequest.DataRequest Converts data request parameters to CCXT format. :param data_req: Parameters of data request in CryptoDataPy format. :type data_req: DataRequest :returns: **data_req** -- Parameters of data request in CCXT format. :rtype: DataRequest .. py:method:: wrangle_data_resp(data_type: str) -> pandas.DataFrame Wrangle data response. :param data_type: Type of data, e.g. 'ohlcv', 'funding_rate', 'open_interest'. :type data_type: str :returns: **df** -- Wrangled dataframe with DatetimeIndex and values in tidy format. :rtype: pd.DataFrame .. py:method:: fetch_tidy_ohlcv_async(data_req: cryptodatapy.extract.datarequest.DataRequest) -> pandas.DataFrame :async: Gets entire OHLCV history and wrangles the data response into tidy data format. :param data_req: Parameters of data request in CryptoDataPy format. :type data_req: DataRequest :returns: **df** -- Dataframe with entire OHLCV data history retrieved and wrangled into tidy data format. :rtype: pd.DataFrame .. py:method:: fetch_tidy_ohlcv(data_req: cryptodatapy.extract.datarequest.DataRequest) -> pandas.DataFrame Gets entire OHLCV history and wrangles the data response into tidy data format. :param data_req: Parameters of data request in CryptoDataPy format. :type data_req: DataRequest :returns: **df** -- Dataframe with entire OHLCV data history retrieved and wrangled into tidy data format. :rtype: pd.DataFrame .. py:method:: fetch_tidy_funding_rates_async(data_req: cryptodatapy.extract.datarequest.DataRequest) -> pandas.DataFrame :async: Gets entire funding rates history and wrangles the data response into tidy data format. :param data_req: Parameters of data request in CryptoDataPy format. :type data_req: DataRequest :returns: **df** -- Dataframe with entire data history retrieved and wrangled into tidy data format. :rtype: pd.DataFrame .. py:method:: fetch_tidy_funding_rates(data_req: cryptodatapy.extract.datarequest.DataRequest) -> pandas.DataFrame Gets entire funding rates history and wrangles the data response into tidy data format. :param data_req: Parameters of data request in CryptoDataPy format. :type data_req: DataRequest :returns: **df** -- Dataframe with entire data history retrieved and wrangled into tidy data format. :rtype: pd.DataFrame .. py:method:: fetch_tidy_open_interest_async(data_req: cryptodatapy.extract.datarequest.DataRequest) -> pandas.DataFrame :async: Gets entire open interest history and wrangles the data response into tidy data format. :param data_req: Parameters of data request in CryptoDataPy format. :type data_req: DataRequest :returns: **df** -- Dataframe with entire data history retrieved and wrangled into tidy data format. :rtype: pd.DataFrame .. py:method:: fetch_tidy_open_interest(data_req: cryptodatapy.extract.datarequest.DataRequest) -> pandas.DataFrame Gets entire open interest history and wrangles the data response into tidy data format. :param data_req: Parameters of data request in CryptoDataPy format. :type data_req: DataRequest :returns: **df** -- Dataframe with entire data history retrieved and wrangled into tidy data format. :rtype: pd.DataFrame .. py:method:: get_data_async(data_req: cryptodatapy.extract.datarequest.DataRequest) -> pandas.DataFrame :async: Get data specified by data request. Parameters data_req: DataRequest Parameters of data request in CryptoDataPy format. :returns: **df** -- DataFrame with DatetimeIndex (level 0), ticker (level 1), and values for selected fields (cols). :rtype: pd.DataFrame - MultiIndex .. py:method:: get_data(data_req: cryptodatapy.extract.datarequest.DataRequest) -> pandas.DataFrame Get data specified by data request. Parameters data_req: DataRequest Parameters of data request in CryptoDataPy format. :returns: **df** -- DataFrame with DatetimeIndex (level 0), ticker (level 1), and values for selected fields (cols). :rtype: pd.DataFrame - MultiIndex