Skip to content

Using main.py CLI

iAmGiG edited this page Nov 15, 2025 · 2 revisions

Using main.py CLI

The main.py command-line interface is the primary way to interact with AutoTrader-AgentEdge for paper trading operations.

Overview

Status: βœ… Fully Functional (as of October 23, 2025) Purpose: Unified terminal interface for all trading operations

Commands

test-voter

Test the VoterAgent with live market data.

python main.py test-voter

What it does:

  • Initializes VoterAgent with production parameters
  • Fetches 60 days of AAPL market data
  • Calculates MACD and RSI indicators
  • Generates trading decision with confidence
  • Displays component analysis

Example Output:

πŸ€– Testing Production VoterAgent...
βœ… VoterAgent configured:
   MACD: (13/34/8)
   RSI: 14 period, 30/70 levels

Fetching AAPL market data...
βœ… Loaded 42 data points
   Price range: $226.79 - $262.77

πŸ“Š Trading Decision:
   Action: BUY (Confidence: 65.0%)
   Reasoning: Weak signal: Only MACD signals BUY
   Current Price: $258.45

πŸ”§ Component Analysis:
   MACD: BUY (Histogram: 0.111064)
   RSI: HOLD (Value: 51.6)

check-positions

Check current paper trading positions and account status.

python main.py check-positions

Requirements: Alpaca paper trading credentials in config.json

What it does:

  • Connects to Alpaca paper trading account
  • Fetches account overview (buying power, portfolio value, cash)
  • Lists all open positions with P&L
  • Shows recent orders

Example Output:

πŸ“Š Checking Paper Trading Positions...
πŸ“ˆ Account Overview:
   Status: ACTIVE
   Buying Power: $90,800.04
   Portfolio Value: $100,211.33
   Cash: $90,800.04

πŸ“‹ Current Positions (1):
   SPY: 14.0 shares @ $657.60
     Market Value: $9,411.29 | P&L: $+204.96 (+2.2%)

πŸ’° Total Position Value: $9,411.29

πŸ“‹ Recent Orders (2):
   SPY: SELL 7.0 @ LIMIT
     Status: NEW

paper-trade

Run full trading cycle check and execute updates as needed.

python main.py paper-trade [SYMBOL]

Arguments:

  • SYMBOL (optional): Focus on specific symbol (e.g., SPY)

What it does:

  1. Fetches remote broker state (source of truth)
  2. Reconciles local vs remote state
  3. Reviews positions and calculates stop adjustments
  4. Re-evaluates losing positions using VoterAgent
  5. Executes stop updates for profitable positions
  6. Closes positions if VoterAgent signals SELL with >60% confidence
  7. Updates local state

Example Output:

πŸ”„ Paper Trading System Check & Update
============================================================
πŸ”§ Initializing Trading Infrastructure...

1️⃣ Fetching Remote Broker State...
   πŸ’° Portfolio Value: $100,211.01
   πŸ’΅ Available Cash: $90,800.04
   πŸ“Š Active Positions: 1
   πŸ“‹ Open Orders: 2

2️⃣ Reconciling Local vs Remote State...
   πŸ”„ Updating 1 discrepancies:
     πŸ”΄ UNKNOWN_POSITION: SPY - NEEDS_HUMAN_REVIEW

3️⃣ Reviewing Positions and Executing Updates...
   πŸ“ˆ SPY:
      Quantity: 14 shares
      Entry: $657.60
      Current: $672.21
      P&L: $+14.62 (+2.2%)

5️⃣ Updating Local State...
   πŸ’Ύ Local state synchronized with all updates

πŸ“Š Trading Cycle Summary:
   πŸ“ˆ Active Positions: 1
   πŸ”„ Stop Adjustments: 0
   πŸ“‰ Losing Positions Reviewed: 0
   ⚠️  State Discrepancies Fixed: 1
   βœ… Actions Executed: 0

πŸ’€ No actions required this cycle

analysis

Generate performance analysis reports.

python main.py analysis

What it does:

  • Runs advanced backtesting analysis
  • Generates performance metrics
  • Creates visualization reports

Configuration

Required API Keys

Create config/config.json:

{
  "POLYGON_IO": "your_polygon_key",
  "ALPHA_VANTAGE_KEY": "your_av_key",
  "ALPACA_PAPER_API_KEY": "your_alpaca_key",
  "ALPACA_PAPER_SECRET": "your_alpaca_secret",
  "ALPACA_ENDPOINT": "https://paper-api.alpaca.markets/v2"
}

Command-Specific Requirements

Command Requires
test-voter POLYGON_IO or ALPHA_VANTAGE_KEY
check-positions ALPACA_PAPER_API_KEY + SECRET
paper-trade All of the above
analysis Market data keys

Troubleshooting

Command Not Found

# Make sure you're in the repo root
cd /path/to/AutoTrader-AgentEdge

# Run with python explicitly
python main.py test-voter

API Credentials Error

❌ Error: Alpaca paper API credentials required

Solution: Add Alpaca credentials to config/config.json

Insufficient Data

❌ Insufficient market data (35 < 42)

Solution: VoterAgent requires at least 42 data points for reliable MACD/RSI calculations. Try a different symbol or check your market data API keys.

Import Error

If you see import errors, ensure dependencies are installed:

pip install -e .

Advanced Usage

Automated Trading Cycles

Run paper trading checks on a schedule:

# Morning check (9:20 AM)
python main.py paper-trade SPY

# Evening check (3:50 PM)
python main.py paper-trade SPY

Multiple Symbols

# Check different positions
python main.py paper-trade SPY
python main.py paper-trade QQQ
python main.py paper-trade AAPL

Cost Efficiency

The main.py CLI is designed for cost efficiency:

  • API Calls: ~10-15 per full trading cycle
  • Caching: 85%+ cache hit rate reduces API usage
  • Batching: Multiple operations in single cycle
  • GTC Orders: Broker execution reduces monitoring

This is 90% fewer API calls compared to reactive trading systems.

Next Steps


Fully Functional: October 23, 2025 | Part of Issue #327