A day-trading copilot built with Phoenix LiveView and Elixir, integrating with Alpaca for market data and order execution.
PilotDesk is an intelligent trading platform that emphasizes learning, human-in-the-loop decision making, automation, simulation, and journaling. The system provides three distinct trading modes:
-
Sandbox Mode 🟢
- Hypothetical trading environment for learning
- Practice day trading strategies without risk
- Uses mock market data
- No real money or API connections
- Perfect for beginners to learn the platform and trading concepts
-
Simulation Mode 🔵
- Execute simulated automated trading
- Uses Alpaca Paper Trading API for realistic market data
- Test algorithms and alerts before going live
- Includes realistic order fills, slippage, and latency
- Automated execution based on strategy confidence levels
- All guardrails active
-
Live Mode 🔴
- Real money trading with Alpaca Live API
- Automated and human-in-the-loop workflows
- Multi-layered approval process for all trades
- Circuit breakers and risk guardrails
- Comprehensive audit trail
- Requires completion of learning modules and strong Simulation performance
- Technical indicator library (EMA, RSI, MACD, Bollinger Bands)
- Custom strategy builder with backtesting
- Real-time signal generation and evaluation
- Confidence scoring for automated execution
- Signal review interface with detailed analysis
- Pre-trade confirmation dialogs
- Multi-factor authentication for Live mode
- Override capabilities with audit logging
- Position size limits
- Daily loss limits
- Maximum concurrent positions
- Symbol whitelists/blacklists
- Time-of-day trading restrictions
- Automatic circuit breakers
- Automatic journal entry creation
- Pre-trade plan documentation
- Post-trade review prompts
- Emotional state tracking
- Performance analytics and insights
- Built-in trading education modules
- Risk management tutorials
- Performance analytics and pattern recognition
- Trade replay functionality
- Milestone-based Live mode enablement
- Backend: Elixir 1.19+ / Erlang/OTP 28+
- Framework: Phoenix 1.8+ with LiveView
- Database: PostgreSQL 16 (Docker)
- Styling: TailwindCSS 4.1+
- Build Tools: esbuild 0.25+
- Market Data: Alpaca Markets API
- Real-time: Phoenix PubSub + WebSockets
- Elixir 1.15+ and Erlang/OTP 26+
- Docker and Docker Compose
- Node.js (for asset compilation)
- Alpaca API account (for Simulation/Live modes)
cd PilotDesk
mix deps.getdocker-compose up -dThis starts two PostgreSQL instances:
- Development database on port 5434
- Test database on port 5435
mix ecto.create
mix ecto.migratecd assets && npm install && cd ..mix phx.serverVisit http://localhost:4000 in your browser.
Or start in interactive mode:
iex -S mix phx.servermix test# Create database
mix ecto.create
# Run migrations
mix ecto.migrate
# Rollback migrations
mix ecto.rollback
# Reset database (drop, create, migrate, seed)
mix ecto.reset
# Seed data
mix run priv/repo/seeds.exs# Start databases
docker-compose up -d
# Stop databases
docker-compose down
# View logs
docker-compose logs -f
# Remove volumes (WARNING: deletes all data)
docker-compose down -vFor Simulation and Live modes, configure Alpaca API keys:
- Sign up at alpaca.markets
- Generate API keys (separate keys for Paper and Live trading)
- Set environment variables:
export ALPACA_PAPER_KEY_ID="your_paper_key"
export ALPACA_PAPER_SECRET_KEY="your_paper_secret"
export ALPACA_LIVE_KEY_ID="your_live_key"
export ALPACA_LIVE_SECRET_KEY="your_live_secret"Or add to config/runtime.exs (not recommended for Live keys - use secrets management).
# Database
DATABASE_URL=ecto://postgres:postgres@localhost:5434/pilot_desk_dev
# Phoenix
SECRET_KEY_BASE=your_secret_key_base
PORT=4000
# Alpaca (optional, only for Simulation/Live)
ALPACA_PAPER_KEY_ID=your_paper_key
ALPACA_PAPER_SECRET_KEY=your_paper_secretPilotDesk/
├── config/ # Application configuration
├── lib/
│ ├── pilot_desk/ # Core business logic contexts
│ │ ├── accounts/ # User accounts and balances
│ │ ├── trading/ # Positions, orders, executions
│ │ ├── signals/ # Signal generation
│ │ ├── strategies/ # Trading strategies
│ │ ├── journal/ # Trade journaling
│ │ └── guardrails/ # Risk management
│ └── pilot_desk_web/ # Web layer (LiveViews, components)
│ ├── live/ # LiveView modules
│ ├── components/ # Reusable UI components
│ └── router.ex # Route definitions
├── priv/
│ ├── repo/migrations/ # Database migrations
│ └── static/ # Static assets
├── test/ # Test files
└── assets/ # Frontend assets (JS, CSS)
- Accounts: User management, account balances, preferences
- Trading: Position management, order execution, trade history
- Signals: Signal generation and evaluation
- Strategies: Strategy builder, backtesting engine
- Journal: Trade journaling and notes
- Guardrails: Risk management and circuit breakers
- MarketData: Price feeds (mock and Alpaca)
- Notifications: Alerts and notifications
MarketData.Server: Manage market data streamsSignalGenerator.Server: Continuous signal evaluationStrategyRunner.Server: Automated strategy executionGuardrails.Monitor: Real-time risk monitoring
market_data:{symbol}: Real-time price updatessignals:user:{id}: User-specific trading signalspositions:user:{id}: Position updatesnotifications:user:{id}: User notifications
- Phase 0: Project foundation and setup
- Phase 1: UI mockups and navigation
- Phase 2: Mock API and data layer
- Phase 3: Core trading workflows
- Phase 4: Signal generation and strategy engine
- Phase 5: Journaling and learning features
- Phase 6: Simulation mode intelligence
- Phase 7: Alpaca integration
- Phase 8: Live mode safeguards
- Phase 9: Real-time features and polish
- Phase 10: Testing and deployment
- This software is for educational purposes
- Day trading involves substantial risk of loss
- Never trade with money you cannot afford to lose
- Always test thoroughly in Sandbox and Simulation before Live trading
- The developers are not responsible for trading losses
- Consult with a financial advisor before live trading
This is a personal project. Contributions, issues, and feature requests are welcome!
[Add your license here]
- Official website: https://www.phoenixframework.org/
- Guides: https://hexdocs.pm/phoenix/overview.html
- Docs: https://hexdocs.pm/phoenix
- Forum: https://elixirforum.com/c/phoenix-forum
- Source: https://github.com/phoenixframework/phoenix
- Official website: https://alpaca.markets
- API Documentation: https://docs.alpaca.markets/
- Paper Trading: https://app.alpaca.markets/paper/dashboard/overview