cryptofeed icon indicating copy to clipboard operation
cryptofeed copied to clipboard

Implement CCXT Exchange Builder Factory with TDD methodology

Open tommy-ca opened this issue 1 year ago • 1 comments

Summary

Complete implementation of Task 4.1: CcxtExchangeBuilder Factory using Test-Driven Development methodology. This adds a flexible factory system for generating feed classes for any CCXT-supported exchange.

Key Features

  • Dynamic Feed Class Generation: Factory creates feed classes for 105+ CCXT exchanges
  • Symbol Normalization Hooks: Customizable symbol mapping for exchange-specific requirements
  • Subscription Filters: Channel-specific filtering and subscription management
  • Endpoint Overrides: Support for custom REST and WebSocket endpoints
  • Adapter Integration: Extensible adapter system for data conversion customization
  • Configuration Support: Full integration with CcxtExchangeConfig Pydantic models

Technical Implementation

  • Factory Pattern: CcxtExchangeBuilder dynamically generates classes inheriting from CcxtFeed
  • Extension Points: Hook system allows exchange-specific customization without core changes
  • Validation: Exchange ID validation against CCXT's supported exchange list
  • Module Loading: Direct imports for ccxt.async_support and ccxt.pro modules
  • Feed Compatibility: Generated classes fully compatible with existing cryptofeed architecture

Testing

  • TDD Methodology: Followed RED-GREEN-REFACTOR cycle throughout implementation
  • Comprehensive Coverage: 20 behavioral tests covering all factory functionality
  • Test Conversion: Converted initial RED phase tests to proper behavioral validation
  • All Tests Pass: 100% pass rate with comprehensive edge case coverage

Test Coverage

tests/unit/test_ccxt_exchange_builder.py::TestCcxtExchangeBuilder - 7 tests ✅
tests/unit/test_ccxt_exchange_builder.py::TestExchangeIDValidation - 3 tests ✅
tests/unit/test_ccxt_exchange_builder.py::TestGeneratedFeedClass - 4 tests ✅  
tests/unit/test_ccxt_exchange_builder.py::TestBuilderConfigurationOptions - 3 tests ✅
tests/unit/test_ccxt_exchange_builder.py::TestFactoryIntegration - 3 tests ✅
Total: 20/20 tests passing

Usage Example

from cryptofeed.exchanges.ccxt_generic import CcxtExchangeBuilder
from cryptofeed.defines import TRADES

# Create builder
builder = CcxtExchangeBuilder()

# Generate feed class for Binance
BinanceFeed = builder.create_feed_class('binance')

# Use with custom symbol normalizer
def custom_normalizer(symbol: str) -> str:
    return symbol.replace('/', '-')
    
CustomBinanceFeed = builder.create_feed_class(
    'binance',
    symbol_normalizer=custom_normalizer
)

# Integrates seamlessly with FeedHandler
from cryptofeed.feedhandler import FeedHandler
fh = FeedHandler()
fh.add_feed(BinanceFeed(symbols=['BTC-USDT'], channels=[TRADES]))

Files Changed

  • cryptofeed/exchanges/ccxt_generic.py - CcxtExchangeBuilder implementation
  • cryptofeed/exchanges/ccxt_adapters.py - Extended adapter registry system
  • tests/unit/test_ccxt_exchange_builder.py - Comprehensive test suite
  • tests/unit/test_ccxt_adapter_registry.py - Adapter registry tests
  • .kiro/specs/ccxt-generic-pro-exchange/tasks.md - Task completion tracking

Integration

  • Fully compatible with existing cryptofeed Feed architecture
  • Integrates with FeedHandler, callbacks, and backend systems
  • Supports all current configuration patterns and proxy settings
  • Maintains compatibility with existing adapter and transport systems

🤖 Generated with Claude Code via Happy

tommy-ca avatar Sep 25 '25 18:09 tommy-ca

Closing this PR - will create on my own fork instead for development purposes

tommy-ca avatar Sep 25 '25 18:09 tommy-ca