v0.1.31 - Alternative Crypto API Support with Automatic Fallback
π Alternative Crypto API Support with Automatic Fallback
This release adds alternative API support for crypto data synchronization, enabling servers blocked by CryptoCompare to fetch data from another aipriceaction instance.
π§ Key Changes
Alternative Crypto Data Source
- New
AiPriceActionClientfor fetching from alternative API endpoints - Automatic source selection via environment variables
- Seamless fallback to CryptoCompare if alternative API fails
- Host header support for CDN/proxy bypass
Efficient Data Fetching
- Single API call fetches all cryptos (efficient batch processing)
- Supports all intervals: 1D (daily), 1H (hourly), 1m (minute)
- Filters crypto-specific data from combined response
Configuration via Environment Variables
CRYPTO_WORKER_TARGET_URL: Alternative API base URLCRYPTO_WORKER_TARGET_HOST: Optional Host header for CDN/proxy bypass
π Use Cases
Scenario: Server Blocked by CryptoCompare
Server A (has CryptoCompare access):
./target/release/aipriceaction serve --port 3000Server B (blocked by CryptoCompare):
export CRYPTO_WORKER_TARGET_URL="https://api-server-a.example.com"
export CRYPTO_WORKER_TARGET_HOST="api.aipriceaction.com"
./target/release/aipriceaction serve --port 3001Server B worker now fetches crypto data from Server A's /tickers endpoint.
π Architecture
Data Flow:
- Crypto worker checks environment variables on startup
- If
CRYPTO_WORKER_TARGET_URLis set β use alternative API - If not set β use CryptoCompare (default behavior)
- On failure β automatic fallback to CryptoCompare
API Call Example:
GET https://api-server-a.example.com/tickers?mode=crypto&interval=1m&start_date=2025-11-19
Host: api.aipriceaction.com
Returns all crypto data in one response (108,646 records for 98 cryptos).
π Bug Fixes
Fixed Host Header Handling
- Fixed "builder error" when setting Host header in reqwest
- Use
HeaderValue::from_str()for proper header encoding - Add graceful fallback if header value is invalid
- Improved error messages with detailed debugging info
π Technical Details
New Components:
src/services/crypto_api_client.rs: API proxy client (218 lines)CryptoDataSourceenum: Abstracts data source (CryptoCompare vs ApiProxy)- Automatic fallback logic in
CryptoFetcher
Startup Logging:
INFO Starting crypto worker with two-tier sync strategy
INFO - Data Source: Alternative API (https://api-server.example.com)
INFO - Host Header: api.aipriceaction.com
INFO - Fallback: CryptoCompare API (if alternative fails)
Fetch Logging:
DEBUG Setting Host header: api.aipriceaction.com
DEBUG Host header set successfully
DEBUG Sending request to: https://api-server.example.com/tickers?...
INFO Fetched 195 records for interval 1D from API
π Files Modified
src/services/crypto_api_client.rs(NEW): API proxy clientsrc/services/crypto_fetcher.rs: Dual-source support with fallback (+189 lines)src/services/mod.rs: Export new clientsrc/worker/crypto_worker.rs: Startup logging for data source (+26 lines)CLAUDE.md: Documentation for environment variables (+28 lines)
βοΈ Configuration
Environment Variables:
# Alternative API URL (required to enable alternative source)
export CRYPTO_WORKER_TARGET_URL="https://api-server.example.com"
# Host header for CDN/proxy bypass (optional)
export CRYPTO_WORKER_TARGET_HOST="api.aipriceaction.com"Important Notes:
- Worker-only feature: CLI commands (
crypto-pull) always use CryptoCompare directly - Automatic fallback ensures reliability
- Zero changes to CSV format or enhancement logic
- Drop-in replacement for blocked servers
π― Benefits
β
Enables crypto sync on servers blocked by CryptoCompare
β
Single API call for all cryptos (efficient)
β
Automatic fallback ensures reliability
β
Host header support for CDN/proxy scenarios
β
Zero configuration changes to existing deployments
β
Same CSV format and enhancement pipeline
Full Changelog: v0.1.30...v0.1.31