The cryptofeed proxy system provides transparent HTTP and WebSocket proxy support for all exchanges with zero code changes required. Built following START SMALL principles using Pydantic v2 for type-safe configuration.
Environment Variables:
export CRYPTOFEED_PROXY_ENABLED=true
export CRYPTOFEED_PROXY_DEFAULT__HTTP__URL="socks5://proxy.example.com:1080"Python:
from cryptofeed.proxy import ProxySettings, ProxyConfig, ConnectionProxies, init_proxy_system
# Configure proxy
settings = ProxySettings(
enabled=True,
default=ConnectionProxies(
http=ProxyConfig(url="socks5://proxy.example.com:1080")
)
)
# Initialize proxy system
init_proxy_system(settings)
# Existing code works unchanged - proxy applied transparently
feed = Binance(symbols=['BTC-USDT'], channels=[TRADES])
feed.start() # Now uses proxy automaticallyaiohttp>=3.8aiohttp-socks>=0.8(required for SOCKS4/SOCKS5 HTTP proxy support)
# config.yaml
proxy:
enabled: true
default:
http:
url: "socks5://default-proxy:1080"
exchanges:
binance:
http:
url: "http://binance-proxy:8080"
coinbase:
http:
url: "socks5://coinbase-proxy:1080"- ✅ Zero Code Changes: Existing feeds work unchanged
- ✅ Type Safe: Full Pydantic v2 validation
- ✅ Transparent: Proxy applied automatically based on exchange
- ✅ Flexible: HTTP, HTTPS, SOCKS4, SOCKS5 proxy support
- ✅ Per-Exchange: Different proxies for different exchanges
- ✅ Production Ready: Environment variables, YAML, error handling
| Document | Purpose | Audience |
|---|---|---|
| User Guide | Configuration examples and usage patterns | Users, DevOps |
| Technical Specification | Implementation details and API reference | Developers |
| Architecture | Design decisions and engineering principles | Architects, Contributors |
| Type | HTTP | WebSocket | Example URL |
|---|---|---|---|
| HTTP | ✅ | http://proxy:8080 |
|
| HTTPS | ✅ | https://proxy:8443 |
|
| SOCKS4 | ✅ | ✅ | socks4://proxy:1080 |
| SOCKS5 | ✅ | ✅ | socks5://user:pass@proxy:1080 |
SOCKS proxies require the aiohttp-socks package for HTTP transports and python-socks for WebSocket transports.
End-to-end proxy regression tests are opt-in to avoid accidental external calls. To run the Binance connectivity check through a real SOCKS proxy:
export CRYPTOFEED_TEST_SOCKS_PROXY="socks5://host:1080"
export CRYPTOFEED_TEST_BINANCE_SYMBOL="BTCUSDT" # optional override
pytest tests/integration/test_live_binance.py -v -m "live_binance and live_proxy"If Binance blocks the chosen region, the test reports HTTP 451 and skips gracefully.
See live-testing.md for region-specific proxy examples and troubleshooting tips.
# Route all traffic through corporate proxy
export CRYPTOFEED_PROXY_ENABLED=true
export CRYPTOFEED_PROXY_DEFAULT__HTTP__URL="socks5://corporate-proxy:1080"
export CRYPTOFEED_PROXY_DEFAULT__WEBSOCKET__URL="socks5://corporate-proxy:1081"proxy:
enabled: true
exchanges:
binance:
http:
url: "socks5://asia-proxy:1080"
coinbase:
http:
url: "http://us-proxy:8080"proxy:
enabled: true
exchanges:
binance:
http:
url: "socks5://binance-direct:1080"
timeout_seconds: 3 # Ultra-low timeout| Method | Use Case | Example |
|---|---|---|
| Environment Variables | Docker, Kubernetes, CI/CD | CRYPTOFEED_PROXY_ENABLED=true |
| YAML Files | Production deployments | proxy: {enabled: true, ...} |
| Python Code | Dynamic configuration | ProxySettings(enabled=True, ...) |
Core Dependencies:
pydantic >= 2.0(configuration validation)pydantic-settings(environment variable loading)aiohttp(HTTP proxy support)websockets(WebSocket connections)
Optional Dependencies:
python-socks(SOCKS proxy support for WebSockets)
Proxy support is included in cryptofeed by default. For SOCKS WebSocket support:
pip install python-socksImplementation Status: ✅ COMPLETE
- Core MVP: ✅ Complete (~150 lines of code)
- Testing: ✅ Complete (40 tests passing)
- Documentation: ✅ Complete (comprehensive guides)
- Production Ready: ✅ Complete (all environments supported)
Engineering Principles Applied:
- ✅ START SMALL: MVP functionality only
- ✅ YAGNI: No external managers, HA, monitoring until proven needed
- ✅ KISS: Simple 3-component architecture
- ✅ FRs over NFRs: Core functionality first, enterprise features deferred
- ✅ Zero Breaking Changes: Existing code works unchanged
Configuration Issues:
- See User Guide for comprehensive examples
- Check proxy URL format and network connectivity
- Verify environment variables are set correctly
Development Questions:
- See Technical Specification for API details
- Check Architecture for design decisions
- Review test files for usage examples
Common Problems:
- Proxy not applied: Check
CRYPTOFEED_PROXY_ENABLED=true - WebSocket proxy fails: Install
python-socksfor SOCKS support - Configuration not loaded: Check environment variable naming
- Connection timeouts: Adjust
timeout_secondsin proxy config
- New Users: Start with User Guide
- Developers: Review Technical Specification
- Contributors: Read Architecture design principles
The proxy system is production-ready and battle-tested. It follows cryptofeed's philosophy of making simple things simple while keeping complex things possible.