Skip to main content

AlpacaCode

PyPI version Python License: MIT

Trading strategy backtester, paper trader, and research CLI powered by Alpaca Markets.

Install

pip install alpacacode

Quick Start

# Create .env with your API keys
cat > .env << 'EOF'
ALPACA_PAPER_API_KEY=your_key
ALPACA_PAPER_SECRET_KEY=your_secret
MASSIVE_API_KEY=your_massive_key
DATABASE_URL=postgresql://user:pass@host/dbname
EOF

# Launch the CLI
alpacacode

Features

  • Parameterized backtesting — grid search over dip threshold, take profit, hold days, and stop loss to find optimal strategy parameters ranked by Sharpe ratio
  • Paper trading — continuous background trading on Alpaca's paper API with daily P&L email reports
  • Market research — news, company profiles, financials, technicals, analyst ratings, and valuation comparisons
  • Multi-agent system — backtest, validate, paper trade, reconcile, and report via an orchestrated agent pipeline
  • Extended hours & intraday exits — pre/after-market trading (4AM-8PM ET) and 5-minute bar TP/SL timing
  • Interactive CLI — Rich-powered terminal with streaming log output and Plotly equity curve charts

Commands

agent:backtest lookback:1m          Run parameterized backtest
agent:paper duration:7d             Paper trade in background
agent:full lookback:1m duration:1m  Full cycle (BT > Validate > PT > Validate)
agent:validate run-id:<uuid>        Validate a backtest or paper trade run
agent:reconcile window:7d           Reconcile DB vs Alpaca positions

news:TSLA                           Company news headlines
price:TSLA                          Quote and technicals
financials:AAPL                     Income and balance sheet
analysts:AAPL                       Ratings and price targets
valuation:AAPL,MSFT                 Side-by-side valuation comparison
movers                              Top market gainers and losers

trades                              Recent trades from DB
runs                                Recent backtest/paper runs
agent:top                           Rank strategies by Sharpe ratio

Documentation

Full user guide: cli.alpacacode.dev/guide

Environment Variables

Variable Required Description
ALPACA_PAPER_API_KEY Yes Alpaca paper trading API key
ALPACA_PAPER_SECRET_KEY Yes Alpaca paper trading secret
MASSIVE_API_KEY Yes Polygon-compatible market data key
DATABASE_URL Yes PostgreSQL connection string
XAI_API_KEY No XAI Grok for AI research commands
EODHD_API_KEY No EOD Historical Data (intraday prices)
POSTMARK_API_KEY No Email notifications for paper trading

License

MIT

Metadata

Release files for alpacacode 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for alpacacode 0.1.0
File Size Uploaded
alpacacode-0.1.0.tar.gz 125.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for alpacacode 0.1.0
File Interpreter ABI Platform
alpacacode-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 264.5 kB

Release files / alpacacode-0.1.0.tar.gz

Download URL alpacacode-0.1.0.tar.gz
Size 125.3 kB
Tags Source
SHA-256 checksum
How to use checksums
cb5d4d945867e7e435abd7c41ad43a3a9b493f338e3ef0a6bc2e0c662d618ffe
BLAKE2b-256 checksum
How to use checksums
83acb484df1dd3aa9b8257f32852a25991f5c02ff43db711e10a3a72f7719c9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / alpacacode-0.1.0-py3-none-any.whl

Download URL alpacacode-0.1.0-py3-none-any.whl
Size 139.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1c250e168b22dab2909cf3c5e7f763b49b9f84d7b1d19728da7eb0a977739d97
BLAKE2b-256 checksum
How to use checksums
7f04c3cafd652bc38abdea329323e9301c6ca74459240fff432e863a6dcdd9bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page