Metadata-Version: 2.4
Name: alpacacode
Version: 0.1.0
Summary: Trading strategy backtester, paper trader, and research CLI powered by Alpaca Markets
Author-email: AlpacaCode <info@alpacacode.dev>
License-Expression: MIT
Project-URL: Homepage, https://cli.alpacacode.dev
Project-URL: Repository, https://github.com/kaljuvee/alpacacode
Project-URL: Documentation, https://cli.alpacacode.dev/guide
Keywords: trading,backtesting,alpaca,paper-trading,stocks,cli
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Office/Business :: Financial :: Investment
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pandas>=2.0
Requires-Dist: numpy>=1.24
Requires-Dist: plotly>=5.0
Requires-Dist: yfinance>=0.2
Requires-Dist: python-dotenv>=1.0
Requires-Dist: requests>=2.31
Requires-Dist: openai>=1.0
Requires-Dist: alpaca-py>=0.20
Requires-Dist: sqlalchemy>=2.0
Requires-Dist: psycopg2-binary>=2.9
Requires-Dist: pyyaml>=6.0
Requires-Dist: rich>=13.0
Requires-Dist: httpx>=0.25
Provides-Extra: web
Requires-Dist: streamlit>=1.30; extra == "web"
Requires-Dist: python-fasthtml>=0.6; extra == "web"
Requires-Dist: fastapi>=0.110; extra == "web"
Requires-Dist: uvicorn[standard]>=0.27; extra == "web"
Provides-Extra: agents
Requires-Dist: langchain-openai>=0.1; extra == "agents"
Requires-Dist: langgraph>=0.1; extra == "agents"
Requires-Dist: langchain-core>=0.2; extra == "agents"
Provides-Extra: all
Requires-Dist: alpacacode[agents,web]; extra == "all"
Dynamic: license-file

# AlpacaCode

[![PyPI version](https://img.shields.io/pypi/v/alpacacode.svg)](https://pypi.org/project/alpacacode/)
[![Python](https://img.shields.io/pypi/pyversions/alpacacode.svg)](https://pypi.org/project/alpacacode/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Trading strategy backtester, paper trader, and research CLI powered by [Alpaca Markets](https://alpaca.markets/).

## Install

```bash
pip install alpacacode
```

## Quick Start

```bash
# 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](https://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
