naveedkhan1998/alpaca-main
关于
Realtime trading data boilerplate
商业与金融可以做什么
- Interactive Terminal Charts — TradingView Lightweight Charts with candlesticks, volume, presets, historical bar-by-bar replay, and configurable indicators (SMA, EMA, WMA, VWMA, RSI, MACD, Bollinger Bands, Keltner Channel, ATR, VWAP, OBV, and more).
- Integrated Options Chain — Dense & Greeks views, call/put & ITM/OTM strike filters, expiration switcher, and live spot indicator right beside the chart.
- Resilient Market-Data Pipeline — Paginated history, bounded retries, decimal candle storage, fractional crypto volumes, and automatic SIP-first selection with IEX fallback when SIP entitlement is unavailable.
- Self-Correcting Live Candles — Timestamp-ordered provisional trade candles are replaced by Alpaca's authoritative minute bars and updated bars; higher timeframes rebuild cleanly from stored minutes.
实测星标增长
- 24小时
- 正在收集历史
- 7天
- 正在收集历史
- 15天
- 正在收集历史
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文
Alpaca Main
Build your market tool. Not the plumbing.
An open-source, full-stack Alpaca API trading terminal & market-data starter — with TradingView charts, options chains, historical replay, real-time WebSockets, and Dockerized Django + React infrastructure.
Explore the Live Demo → · Quick Start · Screenshots · Architecture · Make It Yours
You have an idea for a market screener, an options research dashboard, or a custom trading workflow. Before you can build what makes it unique, you have to wire up authentication, watchlists, historical candle ingestion, live WebSocket streaming, PostgreSQL storage, background jobs, and a responsive terminal UI.
Alpaca Main gives you that production-grade starting point out of the box. It brings a Django REST + Channels backend, a sharp React + TradingView Lightweight Charts frontend, Alpaca market-data pipelines, and Dockerized services together in one extensible Nx monorepo.
This started as a personal open-source project and unexpectedly became the foundation for real client work. The goal is still the same: give developers a serious head start. MIT licensed — free to use, modify, and build commercial products on.
Highlights
- Interactive Terminal Charts — TradingView Lightweight Charts with candlesticks, volume, presets, historical bar-by-bar replay, and configurable indicators (SMA, EMA, WMA, VWMA, RSI, MACD, Bollinger Bands, Keltner Channel, ATR, VWAP, OBV, and more).
- Integrated Options Chain — Dense & Greeks views, call/put & ITM/OTM strike filters, expiration switcher, and live spot indicator right beside the chart.
- 14,000+ Searchable Instruments — Fast symbol/name search, exchange & asset-class filters, tradable/marginable/shortable/fractionable badges, and custom watchlists.
- Resilient Market-Data Pipeline — Paginated history, bounded retries, decimal candle storage, fractional crypto volumes, and automatic SIP-first selection with IEX fallback when SIP entitlement is unavailable.
- Self-Correcting Live Candles — Timestamp-ordered provisional trade candles are replaced by Alpaca's authoritative minute bars and updated bars; higher timeframes rebuild cleanly from stored minutes.
- Full-Stack Foundation — User accounts, JWT auth, Google OAuth, Django REST Framework, Django Channels WebSockets, Celery + Beat workers, Redis caching, Flower monitoring, and a
paper_tradingapp ready to extend.
For ingestion details and data-refresh behavior, see the backend market-data documentation.
Screenshots
Screenshots automatically adapt to your GitHub dark or light theme.
Instrument Directory & Filtering
Asset Overview, Trading Permissions & Margin Profile
What You Can Build
| Your idea | The head start you get |
|---|---|
| A personal market terminal | Watchlists, 14k+ asset search, TradingView charts, options chain, and streaming updates |
| A research or screening tool | Historical OHLCV storage, multiple timeframes, and scheduled Celery scans |
| A strategy research interface | Built-in chart replay and technical indicators, with room for your own backtesting engine |
| A custom trading application | Accounts, JWT auth, DRF APIs, async workers, and a modular React UI |
| A market-data pipeline | Alpaca ingestion, paginated backfills, PostgreSQL persistence, and Redis caching |
This is a boilerplate and working reference application, not a packaged profitable strategy or a turnkey live-trading system. You bring the domain logic, execution controls, and deployment requirements.
Try It Before You Clone It
| Access | What you can do |
|---|---|
| Guest (no sign-up) | Explore historical charts, options chains, replay controls, instruments, and example watchlists |
| Registered | Create custom watchlists, add or remove assets, and enable real-time streaming updates |
Guest access is read-only and rate-limited to keep the shared demo sustainable. You do not need Alpaca credentials to try the demo.
Quick Start
1. Prerequisites
- Node.js 20.19+ or 22.12+ and npm (Vite 8 frontend)
- Docker & Docker Compose with the Docker daemon running
- uv for backend dependencies (Python 3.14+)
- Alpaca API key & secret for local market-data access
2. Clone & Configure
git clone https://github.com/naveedkhan1998/alpaca-main.git
cd alpaca-main
mkdir -p .envs
Create .envs/.env with your local configuration:
APCA_API_KEY=YOUR_ALPACA_KEY
APCA_API_SECRET_KEY=YOUR_ALPACA_SECRET_KEY
POSTGRES_DB=alpaca
POSTGRES_USER=postgres
POSTGRES_PASSWORD=CHOOSE_A_LOCAL_DATABASE_PASSWORD
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
REDIS_URL=redis://redis:6379/0
REDIS_CACHE_URL=redis://redis:6379/1
SECRET_KEY=GENERATE_A_RANDOM_SECRET
Keep
.envs/.envprivate — never commit API credentials or secrets. Stock data automatically checks SIP entitlement first and falls back to IEX if SIP access is denied.
3. Install & Launch
npm install
npm run dev
npm install checks prerequisites and installs both frontend and backend dependencies. npm run dev launches the Vite frontend locally and starts the Dockerized backend services (applying migrations automatically on startup).
| Service | URL |
|---|---|
| Frontend (React + Vite) | http://localhost:5173 |
| Backend API (Django + DRF) | http://localhost:8000 |
| Django Admin | http://localhost:8000/admin/ |
| Flower (Celery Monitor) | http://localhost:5555 |
Local-development note: The startup script creates a default admin account when the database has no users. Change its credentials before exposing the app.
Make It Yours
The repository is organized by feature and service boundary so you can extend it cleanly:
| Path | What to build |
|---|---|
frontend/src/features/graphs/ |
Custom indicators, chart presets, options views, and replay controls |
frontend/src/features/ |
New screens and Redux feature slices |
frontend/src/shared/ |
Reusable UI primitives and RTK Query API clients |
backend/apps/core/services/ |
Market-data ingestion, persistence, and processing services |
backend/apps/core/tasks.py |
Scheduled scans, backfills, and async Celery workflows |
backend/apps/paper_trading/ |
Simulation and paper-trading execution logic |
backend/apps/ |
New Django apps for your own domain |
Keep private strategies and credentials separate from anything you publish — the infrastructure is reusable; your alpha does not have to be open source.
Under the Hood
| Layer | Technologies |
|---|---|
| Frontend | React 19, TypeScript, Vite 8, Redux Toolkit, Tailwind CSS, Radix UI, TradingView Lightweight Charts |
| Backend | Django 6, Django REST Framework, SimpleJWT, Django Channels (WebSockets) |
| Data | Alpaca Market Data API, PostgreSQL 17, Redis 7 |
| Async & Jobs | Celery, Celery Beat, Flower, dedicated market-data WebSocket service |
| Tooling | Nx, Docker Compose, npm, uv |
| Quality | Pytest, Vitest, Ruff, Black, ESLint, Prettier |
Data Flow
flowchart LR
REST[Alpaca REST API] --> Celery[Celery Workers & Beat]
Stream[Alpaca Live Stream] --> WS[Market-Data WebSocket Service]
Celery --> PG[(PostgreSQL + Redis)]
WS --> PG
PG --> API[Django REST API & Channels]
API --> UI[React + TradingView Terminal]
View detailed architecture diagram

Everyday Commands
Run these from the repository root:
| Command | Description |
|---|---|
npm run dev |
Start frontend and Dockerized backend infrastructure |
npm run dev:frontend |
Start only the frontend (expects backend running) |
npm run dev:backend |
Start backend infrastructure |
npm run lint / npm run lint:fix |
Lint or auto-fix both frontend and backend |
npm run format / npm run format:check |
Format or verify formatting (Prettier + Black) |
npm run test / npm run test:coverage |
Run Vitest + Pytest suites |
npm run build |
Production build of the frontend |
npm run makemigrations:local |
Generate Django migrations locally |
npm run migrate |
Apply migrations in the backend container |
npm run docker:logs / npm run docker:down |
Follow logs or stop Docker services |
Optional local observability stack (Vector + Loki + Grafana at localhost:3000):
docker compose -f docker-compose.yaml -f docker-compose.local.yaml up -d
Contributing & Community
Bug fixes, new indicators, onboarding polish, data-handling improvements, and tests are all welcome! Open an issue or submit a pull request.
If Alpaca Main saved you days of boilerplate, consider starring the repository — it helps other builders discover the project and motivates continued improvements.
License & Author
Created by Naveed Khan · mnaveedk.com · Email
Released under the MIT License. Personal and commercial use are welcome; preserve the copyright and license notice when distributing.
Not affiliated with Alpaca Markets. This is developer tooling, not financial advice. Validate data, test your own logic, and implement appropriate safeguards before using any derived application with real money.
探索相关项目
加载中…