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

  1. Monitor Continuously: Use pqap status frequently to track performance
  2. Review Before Deploy: Always check pqap health before deploying
  3. Test Locally First: Try strategy changes locally before deploying to EC2
  4. Check Logs Regularly: Use pqap logs to catch issues early
  5. Track Strategy Performance: Use pqap strategy stats to identify winners

Troubleshooting

Command Not Found

If pqap command is not found after installation:

  1. Check if ~/.local/bin is in your PATH: bash echo $PATH

  2. Add to PATH if needed (add to ~/.bashrc or ~/.zshrc): bash export PATH="$PATH:$HOME/.local/bin"

  3. 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

System Overview

Polymarket API

Market data source

Data Collector

Every 5 minutes

SQLite Database

Price history + trades

Strategy Engine

Signal generation

ML Model

XGBoost (72% acc)

Execution Engine

Paper trading

Dashboard

You are here!

Telegram

Alerts & updates

Trading Strategies

Each strategy looks for different market inefficiencies:

Dual Arbitrage Active

Finds when YES + NO prices don't add to 100%. Risk-free profit.

Mean Reversion Active

Buys when price drops too far from average, sells when it recovers.

Market Maker Active

Places bid/ask orders to capture the spread.

Time Arbitrage Active

Exploits predictable price patterns at certain hours.

ML Prediction Active

Uses machine learning to predict 6-hour price direction.

Value Betting Disabled

Finds underpriced outcomes based on implied probability.

Data Storage (Single Source of Truth)

All data lives on EC2. Local machines are for development only. The EC2 instance is the authoritative source for all market data, trades, and positions.
Database Purpose Location
market_history.db Price snapshots every 5 minutes (8.2 MB) EC2 (primary)
pqap_prod.db Trades, positions, P&L history EC2 (primary)
paper_trading_state.json Current portfolio state EC2 (primary)

Environment Architecture

EC2 (Production)

  • Runs 24/7
  • All databases live here
  • Executes all trades
  • Single source of truth

Local (Development)

  • For code changes only
  • Syncs code to EC2
  • No production data
  • Can be turned off

Environment Details

Component Details
Dashboard URL https://pqap.tailwindtech.ai
Server AWS EC2 (us-east-1)
SSL Let's Encrypt via Traefik
Mode Paper Trading (simulated)

How It Works (Simple Version)

1. Data Collection: Every 5 minutes, we fetch prices from Polymarket for 50 markets and save them to our database.

2. Analysis: Our strategies analyze this data looking for patterns - like prices that moved too far from normal, or markets where the math doesn't add up.

3. Signals: When a strategy finds an opportunity, it generates a "signal" - a recommendation to buy or sell.

4. Execution: The execution engine takes these signals and simulates trades (paper trading). Eventually, this will place real orders.

5. Monitoring: This dashboard shows you what's happening. Telegram sends alerts for important events.