一键导入
ccxt-multi-exchange
CCXT multi-exchange crypto broker integration for better liquidity during after-hours capital shift
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
CCXT multi-exchange crypto broker integration for better liquidity during after-hours capital shift
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Normalize long-form CODEX cycle folders to short form before notebooks run. Trigger: cyc001_reg001_*, hard-coded cyc paths breaking, staged CODEX raw data failing in Notebooks 1/2.
v5.6.0 joint multi-TF model: single model per symbol with broadcast 1Hour context replaces dual 15Min/1Hour models. Trigger: (1) replacing weighted-voting model aggregation, (2) adding broadcast features to vectorized env, (3) limited training data + worried about overfitting from doubling obs_dim, (4) backtest builder mismatch with newer feature counts.
DEPRECATED in v5.6.0 — see joint-multi-tf-v560 skill. Documents the v5.2.0 dual-model approach (train separate 15Min/1Hour models, combine via weighted voting). Still relevant for: (1) loading legacy v5.5.0 dual models, (2) understanding the historical aggregation layer, (3) resampling pattern via origin='start'.
Surface a shipped-but-undocumented CLI feature in user-facing docs. Trigger: user reports a known feature missing from README/readthedocs even though the CLI command exists.
KINTSUGI Snakefile + CLI changes that route SLURM jobs around accounts saturated by OTHER users on the same QOS pool. Trigger: QOSGrpMemLimit, jobs stuck pending despite available GPU slots in config, noisy neighbor on shared QOS, multi-user investment pool exhaustion, _build_cycle_assignment static-vs-live.
KINTSUGI SLURM batch processing: Maximize throughput using multi-account resource calculation with GPU+CPU pools per account. Trigger: SLURM job submission, batch processing, resource maximization, GPU+CPU concurrent, headless processing, resource pool.
| name | ccxt-multi-exchange |
| description | CCXT multi-exchange crypto broker integration for better liquidity during after-hours capital shift |
| author | Claude Code |
| date | "2026-01-26T00:00:00.000Z" |
| version | 3.5.0 |
| Item | Details |
|---|---|
| Date | 2026-01-26 |
| Goal | Improve crypto liquidity during after-hours by routing to multiple US-regulated exchanges |
| Environment | Python 3.11+, ccxt>=4.0.0 |
| Status | Success |
Alpaca reports platform-specific volume, not global exchange volume:
| Metric | Alpaca Platform | Global Exchange |
|---|---|---|
| BTC/USD daily volume | ~$250k-$750k | ~$30B |
| Hourly liquidity | ~5-15 BTC | Effectively unlimited |
| Impact | Slippage risk, partial fills | Minimal |
Additional Alpaca Limitations:
Solution: Use CCXT unified library to route to US-regulated exchanges with better liquidity during capital shift (after-hours/weekends).
Market Hours (9:30-4:00 ET):
└── Alpaca (equities + crypto)
After Hours / Weekends (shifted):
└── CCXT Unified Interface
├── Coinbase International (primary - best compliance)
├── Coinbase (secondary - standard retail)
├── Kraken (tertiary - lower fees)
└── Binance.US (quaternary - if needed)
from alpaca_trading.trading.ccxt_broker import CCXTBroker, CCXTBrokerConfig
config = CCXTBrokerConfig(
exchanges=['coinbase', 'kraken'],
keys_file='API_key_CCXT.txt',
sandbox=False,
rate_limit_buffer_ms=100,
max_retries=3,
)
broker = CCXTBroker(config)
# AlpacaBroker-compatible interface
account = broker.get_account() # Aggregated across exchanges
positions = broker.get_positions() # All exchange positions
order = broker.submit_order( # Routes to best exchange
symbol='BTC/USD',
qty=0.01,
side='buy',
type='limit',
limit_price=50000,
)
from alpaca_trading.trading.exchange_selector import ExchangeSelector
selector = ExchangeSelector(
broker=ccxt_broker,
min_balance_buffer=100.0, # Keep $100 buffer
prefer_maker=True, # Prioritize lower maker fees
)
# Find best exchange for a trade
result = selector.select_exchange(
symbol='BTC/USD',
side='buy',
notional=10000, # $10k trade
)
# Returns: ExchangeScore(exchange_id='coinbase', score=145.0, ...)
from alpaca_trading.risk.capital_shift import CapitalShiftManager, CapitalShiftConfig
config = CapitalShiftConfig(
enabled=True,
shift_fraction=0.75,
max_crypto_allocation=0.50,
use_ccxt_when_shifted=True, # Enable CCXT routing
ccxt_keys_file='API_key_CCXT.txt',
)
shift_mgr = CapitalShiftManager(
config,
alpaca_broker=alpaca_broker,
ccxt_broker=ccxt_broker,
)
# Get appropriate broker based on shift status
allocation = shift_mgr.calculate_asset_allocations(...)
crypto_broker = shift_mgr.get_crypto_broker(allocation)
# Returns CCXT broker when shifted, Alpaca otherwise
# API_key_CCXT.txt (NOT in git)
coinbase_api_key=your_api_key_here
coinbase_secret=your_secret_here
kraken_api_key=your_api_key_here
kraken_secret=your_secret_here
binanceus_api_key=your_api_key_here
binanceus_secret=your_secret_here
# Enable CCXT for after-hours crypto
python scripts/live_trader.py --paper 1 --use-ccxt 1 --ccxt-keys-file API_key_CCXT.txt
# Without CCXT (Alpaca only)
python scripts/live_trader.py --paper 1 --capital-shift 1
| Attempt | Why it Failed | Lesson Learned |
|---|---|---|
| Single exchange only | Insufficient funds during large trades | Multi-exchange failover essential |
| Using non-US exchanges | Regulatory compliance issues | Stick to Coinbase, Kraken, Binance.US |
| Hardcoded symbol mapping | BTC/USD vs BTC/USDT varies by exchange | Dynamic symbol mapping per exchange |
| No rate limit handling | 429 errors during high activity | Use CCXT's built-in rate limiting + buffer |
| Immediate failover | Network glitches caused unnecessary switches | Retry 3x before failover |
| Not checking balance before routing | Insufficient funds errors after exchange selection | Balance-aware exchange selection |
| Same credentials file as Alpaca | Confusing, different key formats | Separate API_key_CCXT.txt file |
| Not handling sandbox mode | Test orders hit live exchanges | Pass sandbox=True in config |
# Recommended CCXT configuration
CCXTBrokerConfig(
exchanges=['coinbaseinternational', 'coinbase', 'kraken'], # US-regulated only
sandbox=False, # True for testing
rate_limit_buffer_ms=100, # Extra safety margin
max_retries=3, # Before exchange failover
)
# Exchange priority and fees (4 exchanges)
EXCHANGE_PRIORITY = {
'coinbaseinternational': 1, # Primary - best US compliance
'coinbase': 2, # Secondary - standard retail
'kraken': 3, # Tertiary - lower fees (0.16%)
'binanceus': 4, # Quaternary - regulatory concerns
}
EXCHANGE_FEES = {
'coinbaseinternational': {'maker': 0.004, 'taker': 0.006}, # 0.4%/0.6%
'coinbase': {'maker': 0.004, 'taker': 0.006}, # 0.4%/0.6%
'kraken': {'maker': 0.0016, 'taker': 0.0026}, # 0.16%/0.26%
'binanceus': {'maker': 0.001, 'taker': 0.001}, # 0.1%/0.1%
}
get_positions() returns positions from ALL exchangesccxt.InsufficientFunds, ccxt.RateLimitExceeded, ccxt.NetworkError| File | Action | Description |
|---|---|---|
alpaca_trading/trading/ccxt_broker.py | Created | CCXT broker wrapper |
alpaca_trading/trading/exchange_selector.py | Created | Exchange routing logic |
alpaca_trading/data/fetcher.py | Modified | Added fetch_crypto_ohlcv_ccxt() |
alpaca_trading/risk/capital_shift.py | Modified | Dual broker support, get_crypto_broker() |
scripts/live_trader.py | Modified | --use-ccxt, --ccxt-keys-file args |
config/requirements.txt | Modified | Added ccxt>=4.0.0 |
CLAUDE.md | Modified | CCXT documentation section |
137 tests across two test files, using mock ccxt infrastructure (no real exchange connections):
tests/test_ccxt_broker.py — 102 tests covering CCXTBroker (16 public methods)tests/test_exchange_selector.py — 35 tests covering ExchangeSelector (6 public methods)Uses module-level sys.modules['ccxt'] mock injection with real exception class hierarchies. See the optional-dependency-test-mocking skill for the reusable pattern.
python -m pytest tests/test_ccxt_broker.py tests/test_exchange_selector.py -v
# Verify these scenarios:
1. [x] CCXT broker initializes with valid credentials
2. [x] Exchange failover on InsufficientFunds
3. [x] get_positions() aggregates across exchanges
4. [x] submit_order() routes to best exchange
5. [ ] Capital shift activates CCXT when shifted
6. [ ] Capital shift uses Alpaca when not shifted
7. [x] Symbol mapping works (BTC/USD -> BTC/USDT)
8. [x] Sandbox mode prevents live orders during testing
9. [x] Position reconciliation across both brokers
10. [x] Rate limiting prevents 429 errors