Skip to content

mrjpsilver/pilot-desk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PilotDesk

A day-trading copilot built with Phoenix LiveView and Elixir, integrating with Alpaca for market data and order execution.

Overview

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:

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

Core Features

Signal Generation & Strategy Engine

  • Technical indicator library (EMA, RSI, MACD, Bollinger Bands)
  • Custom strategy builder with backtesting
  • Real-time signal generation and evaluation
  • Confidence scoring for automated execution

Human-in-the-Loop Approvals

  • Signal review interface with detailed analysis
  • Pre-trade confirmation dialogs
  • Multi-factor authentication for Live mode
  • Override capabilities with audit logging

Risk Management & Guardrails

  • Position size limits
  • Daily loss limits
  • Maximum concurrent positions
  • Symbol whitelists/blacklists
  • Time-of-day trading restrictions
  • Automatic circuit breakers

Trade Journaling

  • Automatic journal entry creation
  • Pre-trade plan documentation
  • Post-trade review prompts
  • Emotional state tracking
  • Performance analytics and insights

Learning & Education

  • Built-in trading education modules
  • Risk management tutorials
  • Performance analytics and pattern recognition
  • Trade replay functionality
  • Milestone-based Live mode enablement

Technology Stack

  • 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

Prerequisites

  • Elixir 1.15+ and Erlang/OTP 26+
  • Docker and Docker Compose
  • Node.js (for asset compilation)
  • Alpaca API account (for Simulation/Live modes)

Getting Started

1. Clone and Setup

cd PilotDesk
mix deps.get

2. Start PostgreSQL with Docker

docker-compose up -d

This starts two PostgreSQL instances:

  • Development database on port 5434
  • Test database on port 5435

3. Create and Migrate Database

mix ecto.create
mix ecto.migrate

4. Install Assets

cd assets && npm install && cd ..

5. Start Phoenix Server

mix phx.server

Visit http://localhost:4000 in your browser.

Or start in interactive mode:

iex -S mix phx.server

Development

Running Tests

mix test

Database Management

# 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

Docker Commands

# 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 -v

Configuration

Alpaca API Keys

For Simulation and Live modes, configure Alpaca API keys:

  1. Sign up at alpaca.markets
  2. Generate API keys (separate keys for Paper and Live trading)
  3. 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).

Environment Variables

# 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_secret

Project Structure

PilotDesk/
├── 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)

Architecture

Contexts

  • 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

GenServers

  • MarketData.Server: Manage market data streams
  • SignalGenerator.Server: Continuous signal evaluation
  • StrategyRunner.Server: Automated strategy execution
  • Guardrails.Monitor: Real-time risk monitoring

PubSub Topics

  • market_data:{symbol}: Real-time price updates
  • signals:user:{id}: User-specific trading signals
  • positions:user:{id}: Position updates
  • notifications:user:{id}: User notifications

Roadmap

  • 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

Safety & Disclaimers

  • 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

Contributing

This is a personal project. Contributions, issues, and feature requests are welcome!

License

[Add your license here]

Learn More About Phoenix

Learn More About Alpaca

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors