Create exchange API keys with trade permissions only (never withdraw), IP-allowlist them where supported, and paste into .env. Public market-data examples need no credentials.
- Zero-credential path (start here)
- Permission rules (read this first)
- Coinbase Advanced Trade
- Kraken
- Binance.US
- Sandbox / testnet
- Verify with ccxt
- What lives where in the book
You can run every market-data example in strategies/crypto/data_fetcher.py and the public-endpoint backtests right now, with no signup and no keys. ccxt's public REST endpoints (orderbook, OHLCV, ticker) are unauthenticated:
python -c "
from strategies.crypto.data_fetcher import fetch_ohlcv
import pandas as pd
df = fetch_ohlcv('coinbase', 'BTC/USD', '1h', limit=24)
print(df.tail())
"This is the recommended first step (see Ch 8). Only generate keys when you reach the paper/live trading examples in Ch 9.
Apply these to every exchange key you create. They are non-negotiable:
| Permission | Setting |
|---|---|
| View / read | Enabled |
| Trade / spot orders | Enabled |
| Withdraw | Disabled — always |
| Transfer to other accounts | Disabled |
| Margin / futures / derivatives | Disabled unless explicitly used |
| IP allowlist | Set to your VPS or home IP wherever the exchange supports it |
| Key expiration | 90 days where offered; rotate on the calendar |
A trade-only key that leaks costs you trading P&L until you revoke. A withdraw-enabled key that leaks empties the account. Treat the distinction as load-bearing.
After saving credentials to .env:
chmod 600 .envCoinbase Advanced Trade is the API surface ccxt targets (the legacy "Coinbase Pro" was retired).
- Sign up / log in at https://www.coinbase.com. Complete identity verification (required for API access).
- Go to https://www.coinbase.com/settings/api (or Settings → Advanced settings → API).
- Click New API Key.
- Permissions: enable View and Trade. Leave Transfer off.
- IP allowlist: add your machine's public IP (
curl ifconfig.me) and your VPS IP if applicable. If you skip this, treat the key as more sensitive and rotate often. - Copy the API Key and API Secret. Coinbase shows the secret once.
Paste into .env:
COINBASE_API_KEY=organizations/.../apiKeys/...
COINBASE_API_SECRET=<paste the full PEM block here, including the BEGIN/END lines, with newlines escaped as \n>
Coinbase Advanced Trade keys use ECDSA — the secret is a multi-line PEM. Keep the \n escapes if your loader requires single-line .env; ccxt handles both forms.
- Sign up at https://www.kraken.com. Complete the verification tier required for API trading (Intermediate is typical).
- Go to https://www.kraken.com/u/security/api.
- Click Add key.
- Permissions: enable Query Funds, Query Open Orders & Trades, Query Closed Orders & Trades, Modify Orders, Cancel/Close Orders. Leave Withdraw Funds and Transfer Funds off.
- Optional but recommended: set a Nonce window of 5–10 and Key expiration to 90 days.
- Save and copy the API Key and Private Key.
KRAKEN_API_KEY=................................................
KRAKEN_API_SECRET=........................................................================Kraken does not expose IP allowlisting on standard accounts; protect the key with file permissions and rotation instead.
(US residents — use Binance.US, not binance.com. Binance.com US-blocks since 2019.)
- Sign up at https://www.binance.us and complete KYC.
- Go to Profile → API Management.
- Click Create API, choose a label, complete 2FA.
- Permissions: enable Enable Reading and Enable Spot & Margin Trading. Leave Enable Withdrawals off (it's off by default; do not change).
- Restrict access to trusted IPs only — paste your IP. Binance.US enforces this per-key.
- Copy the API Key and Secret Key.
BINANCE_US_API_KEY=................................................
BINANCE_US_API_SECRET=................................................Binance.US's symbol set is smaller than the global venue. Some pairs in book examples may not list — substitute liquid alternatives (BTC/USDT → BTC/USD).
For dry-running order placement before risking funds:
- Coinbase: no public sandbox for Advanced Trade. Use small live orders or the in-process paper executor (
strategies/infrastructure/paper_executor.py). - Kraken: no public sandbox. Same recommendation.
- Binance.US: no testnet. (Global Binance has https://testnet.binance.vision, but credentials are not interchangeable with Binance.US.)
The book's recommendation: paper-trade against the in-process PaperExecutor first, then graduate to small live orders ($10–$50) on the real exchange. This mirrors the 30-day plan in Ch 15.
Once keys are in .env and chmod 600 is applied, verify auth:
bwc doctorFor an exchange-specific manual check:
import ccxt
from bwc.config import settings
ex = ccxt.coinbase({
"apiKey": settings.coinbase_api_key,
"secret": settings.coinbase_api_secret,
})
print(ex.fetch_balance()["total"]) # expect: {'USD': ..., 'BTC': ..., ...}HTTP 401 / signature errors → key/secret swapped, secret newline-mangled, or wrong exchange (Binance global vs Binance.US). See TROUBLESHOOTING.md.
Rate limits hit during backtests → enable ccxt's built-in throttle: ccxt.coinbase({"enableRateLimit": True, ...}). The book's data_fetcher.py does this by default.
| Topic | Chapter | Module |
|---|---|---|
| Public market-data fetcher | Ch 8 | strategies/crypto/data_fetcher.py |
| Crypto momentum scanner | Ch 9 | strategies/crypto/momentum_scanner.py |
| Grid trader | Ch 9 | strategies/crypto/grid_trader.py |
| DCA bot | Ch 9 | strategies/crypto/dca_bot.py |
| Cross-exchange arbitrage | Ch 9 | strategies/crypto/arbitrage_bot.py |
| Node.js mirrors | Ch 9 | bots/nodejs_bot/ |