Ajasra 24394d7b92 Add custom exceptions and enhance error handling in exchanges module
- Introduced a new `exceptions.py` file containing custom exceptions for the exchanges module, improving error specificity and handling.
- Updated the `factory.py` and `registry.py` files to utilize the new exceptions, enhancing robustness in error reporting and logging.
- Implemented validation logic in `ExchangeCollectorConfig` to ensure proper configuration, raising appropriate exceptions when validation fails.
- Enhanced logging throughout the factory methods to provide better insights into the collector creation process and error scenarios.
- Added comprehensive documentation for the exchanges module, detailing the architecture, error handling, and usage examples.

These changes significantly improve the error handling and maintainability of the exchanges module, aligning with project standards and enhancing developer experience.
2025-06-07 14:29:09 +08:00

55 lines
1.6 KiB
Python

"""
Exchange registry for supported exchanges.
This module contains the registry of supported exchanges and their capabilities,
separated to avoid circular import issues.
"""
from utils.logger import get_logger
from .exceptions import ExchangeNotSupportedError
# Initialize logger
logger = get_logger('exchanges')
# Exchange registry for factory pattern
EXCHANGE_REGISTRY = {
'okx': {
'collector': 'data.exchanges.okx.collector.OKXCollector',
'websocket': 'data.exchanges.okx.websocket.OKXWebSocketClient',
'name': 'OKX',
'supported_pairs': ['BTC-USDT', 'ETH-USDT', 'SOL-USDT', 'DOGE-USDT', 'TON-USDT'],
'supported_data_types': ['trade', 'orderbook', 'ticker', 'candles']
}
}
def get_supported_exchanges() -> list:
"""Get list of supported exchange names."""
exchanges = list(EXCHANGE_REGISTRY.keys())
logger.debug(f"Available exchanges: {exchanges}")
return exchanges
def get_exchange_info(exchange_name: str) -> dict:
"""
Get information about a specific exchange.
Args:
exchange_name: Name of the exchange
Returns:
Dictionary containing exchange information
Raises:
ExchangeNotSupportedError: If exchange is not found in registry
"""
exchange_name = exchange_name.lower()
exchange_info = EXCHANGE_REGISTRY.get(exchange_name)
if not exchange_info:
error_msg = f"Exchange '{exchange_name}' not found in registry"
logger.error(error_msg)
raise ExchangeNotSupportedError(error_msg)
logger.debug(f"Retrieved info for exchange: {exchange_name}")
return exchange_info