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