Skip to content

Latest commit

 

History

History
151 lines (109 loc) · 6.41 KB

File metadata and controls

151 lines (109 loc) · 6.41 KB

Crypto Setup — Coinbase, Kraken, Binance.US

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.

Contents

Zero-credential path (start here)

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.

Permission rules (read this first)

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 .env

Coinbase Advanced Trade

Coinbase Advanced Trade is the API surface ccxt targets (the legacy "Coinbase Pro" was retired).

  1. Sign up / log in at https://www.coinbase.com. Complete identity verification (required for API access).
  2. Go to https://www.coinbase.com/settings/api (or Settings → Advanced settings → API).
  3. Click New API Key.
  4. Permissions: enable View and Trade. Leave Transfer off.
  5. 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.
  6. 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.

Kraken

  1. Sign up at https://www.kraken.com. Complete the verification tier required for API trading (Intermediate is typical).
  2. Go to https://www.kraken.com/u/security/api.
  3. Click Add key.
  4. Permissions: enable Query Funds, Query Open Orders & Trades, Query Closed Orders & Trades, Modify Orders, Cancel/Close Orders. Leave Withdraw Funds and Transfer Funds off.
  5. Optional but recommended: set a Nonce window of 5–10 and Key expiration to 90 days.
  6. 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.

Binance.US

(US residents — use Binance.US, not binance.com. Binance.com US-blocks since 2019.)

  1. Sign up at https://www.binance.us and complete KYC.
  2. Go to Profile → API Management.
  3. Click Create API, choose a label, complete 2FA.
  4. Permissions: enable Enable Reading and Enable Spot & Margin Trading. Leave Enable Withdrawals off (it's off by default; do not change).
  5. Restrict access to trusted IPs only — paste your IP. Binance.US enforces this per-key.
  6. 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/USDTBTC/USD).

Sandbox / testnet

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.

Verify with ccxt

Once keys are in .env and chmod 600 is applied, verify auth:

bwc doctor

For 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.

What lives where in the book

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/