PQAP Command-Line Interface
A unified command-line tool for managing the PQAP trading platform.
Installation
Install the CLI tool to make it available system-wide as the pqap command:
./scripts/install_cli.sh
This will create a symlink in /usr/local/bin (or ~/.local/bin) so you can run pqap from anywhere.
Usage
System Commands
Show System Status
pqap status
Displays: - Running status and PID - Configuration details - Paper trading summary (capital, P&L, positions, trades) - Database statistics - Dashboard URL
Start Trading Engine
pqap start
Starts the PQAP trading engine in the background.
Stop Trading Engine
pqap stop
Stops the running PQAP process.
Restart Trading Engine
pqap restart
Stops and restarts PQAP (useful after config changes).
Position & Trading Commands
View Current Positions
pqap positions
Shows all open positions with: - Market question - Side (BUY/SELL) - Position size - Entry price - Current price - Unrealized P&L
View Recent Trades
# Show last 20 trades (default)
pqap trades
# Show last N trades
pqap trades --last 50
Displays trade history with timestamps, strategy, side, size, price, P&L, and fees.
View P&L Summary
pqap pnl
Shows comprehensive P&L breakdown: - Overall performance (total trades, wins, losses, win rate) - P&L by strategy - Last 7 days daily performance
Strategy Commands
List All Strategies
pqap strategies
Shows: - Strategy name and status (enabled/disabled) - Allocated capital - Key parameters - Performance statistics (trades, P&L)
Enable a Strategy
pqap strategy enable <strategy_name>
Enables a strategy in the config file.
Example:
pqap strategy enable momentum_v1
Note: Restart PQAP for changes to take effect.
Disable a Strategy
pqap strategy disable <strategy_name>
Disables a strategy in the config file.
Example:
pqap strategy disable market_maker_v1
Note: Restart PQAP for changes to take effect.
View Strategy Statistics
pqap strategy stats <strategy_name>
Shows detailed statistics for a specific strategy: - Overall performance metrics - Best and worst trades - Recent trade history
Example:
pqap strategy stats dual_arb_v1
Deployment Commands
Sync Code to EC2
pqap sync
Syncs code changes to EC2 (excludes .git, .env, databases, logs).
Deploy to EC2
pqap deploy
Syncs code and restarts PQAP on EC2.
Utility Commands
View Logs
# Show last 50 lines (default)
pqap logs
# Show last N lines
pqap logs --lines 100
Health Check
pqap health
Performs comprehensive health checks: - PQAP running status - Config file exists - Database accessible - Paper state file valid - Log file exists - API endpoint responding
Examples
Daily Workflow
# Morning: Check status
pqap status
# Review positions
pqap positions
# Check P&L
pqap pnl
# View recent activity
pqap trades --last 10
# Afternoon: Enable new strategy
pqap strategy enable value_bet_v1
pqap restart
# Evening: Check performance
pqap strategy stats value_bet_v1
# Check logs for issues
pqap logs --lines 50
Troubleshooting
# Check if everything is healthy
pqap health
# If PQAP isn't running
pqap start
# Check logs for errors
pqap logs --lines 100
# Restart if needed
pqap restart
Strategy Management
# See all strategies and performance
pqap strategies
# Enable multiple strategies
pqap strategy enable dual_arb_v1
pqap strategy enable mean_reversion_v1
# Disable underperforming strategy
pqap strategy stats momentum_v1 # Check stats first
pqap strategy disable momentum_v1
# Restart to apply changes
pqap restart
Deployment
# Test locally first
pqap health
# Quick code sync to EC2
pqap sync
# Full deployment with restart
pqap deploy
Output Colors
The CLI uses colored output for better readability:
- Green (✓): Success messages, positive P&L
- Red (✗): Error messages, negative P&L, losses
- Yellow (⚠): Warning messages
- Cyan (ℹ): Info messages
- Bold: Headers and section titles
Configuration
The CLI reads from:
- Config: configs/dev.yaml
- Database: data/pqap_dev.db
- Paper State: data/paper_trading_state.json
- Logs: pqap.log
Tips
- Monitor Continuously: Use
pqap statusfrequently to track performance - Review Before Deploy: Always check
pqap healthbefore deploying - Test Locally First: Try strategy changes locally before deploying to EC2
- Check Logs Regularly: Use
pqap logsto catch issues early - Track Strategy Performance: Use
pqap strategy statsto identify winners
Troubleshooting
Command Not Found
If pqap command is not found after installation:
-
Check if
~/.local/binis in your PATH:bash echo $PATH -
Add to PATH if needed (add to
~/.bashrcor~/.zshrc):bash export PATH="$PATH:$HOME/.local/bin" -
Reload shell:
bash source ~/.bashrc # or source ~/.zshrc
Permission Denied
If you get permission errors:
chmod +x scripts/pqap_cli.py
chmod +x scripts/install_cli.sh
Database Locked
If database is locked, make sure only one PQAP instance is running:
pqap stop
pqap start
Advanced Usage
Scripting with pqap
You can use pqap in shell scripts:
#!/bin/bash
# Daily status report
echo "=== Daily PQAP Report ==="
pqap status
pqap pnl
pqap positions
Monitoring Loop
# Monitor positions every minute
watch -n 60 pqap positions
Automated Deployment
# Deploy script with checks
if pqap health; then
pqap sync
pqap deploy
else
echo "Health check failed, not deploying"
exit 1
fi