Complete Python scripts and systemd services for contrarian trading strategy execution across Polymarket and Hyperliquid.
trading-strategy/
├── scripts/
│ ├── polymarket/
│ │ ├── contrarian-monitor.py (>72% consensus extremes)
│ │ └── strength-filtered-monitor.py (>80% consensus only)
│ ├── hyperliquid/
│ │ ├── funding-monitor.py (>0.12% funding rate)
│ │ └── funding-oi-monitor.py (>0.15% funding + OI extreme)
│ └── common/
│ └── paper-trader.py (paper trading automation)
├── systemd/
│ ├── contrarian-monitor.service
│ ├── polymarket-strength-filtered.service
│ ├── hyperliquid-funding.service
│ ├── hyperliquid-funding-oi.service
│ └── paper-trader.service
└── deploy/
├── deploy.sh (deploy all to anjie)
├── start-all.sh (start all services)
├── stop-all.sh (stop all services)
└── status.sh (check service status)
Polymarket Contrarian Monitor (contrarian-monitor.py)
consensus-extremes.jsonlPolymarket Strength-Filtered Monitor (strength-filtered-monitor.py)
strength-filtered-extremes.jsonlHyperliquid Funding Monitor (funding-monitor.py)
funding-extremes.jsonlHyperliquid Funding+OI Monitor (funding-oi-monitor.py)
funding-oi-extremes.jsonlPaper Trader (paper-trader.py)
trades.jsonlmetrics.jsoncd /home/rdent/trading-strategy
./deploy/deploy.sh
This will:
~/trading/{polymarket,hyperliquid,common}/scripts/~/trading/systemd//etc/systemd/system/./deploy/start-all.sh
Or start individually:
ssh [email protected] "sudo systemctl start contrarian-monitor"
ssh [email protected] "sudo systemctl start polymarket-strength-filtered"
ssh [email protected] "sudo systemctl start hyperliquid-funding"
ssh [email protected] "sudo systemctl start hyperliquid-funding-oi"
ssh [email protected] "sudo systemctl start paper-trader"
./deploy/status.sh
Or:
ssh [email protected] "sudo systemctl status paper-trader"
ssh [email protected] "tail -f ~/trading/common/logs/paper-trader.log"
deploy.sh)./deploy/deploy.sh
What it does:
/etc/systemd/system/SSH Key Required:
~/.ssh/id_ed25519 for passwordless auth to [email protected]rdent userstart-all.sh)./deploy/start-all.sh
Starts services in order:
stop-all.sh)./deploy/stop-all.sh
Stops services in reverse order (trader first, then monitors).
status.sh)./deploy/status.sh
Shows:
After deployment, files are organized as:
~/trading/
├── polymarket/
│ ├── scripts/
│ │ ├── contrarian-monitor.py
│ │ └── strength-filtered-monitor.py
│ ├── logs/
│ │ ├── contrarian-monitor.log
│ │ └── strength-filtered-monitor.log
│ └── data/
│ ├── consensus-extremes.jsonl
│ ├── strength-filtered-extremes.jsonl
│ ├── monitor-state.json
│ └── strength-filtered-state.json
├── hyperliquid/
│ ├── scripts/
│ │ ├── funding-monitor.py
│ │ └── funding-oi-monitor.py
│ ├── logs/
│ │ ├── funding-monitor.log
│ │ └── funding-oi-monitor.log
│ └── data/
│ ├── funding-extremes.jsonl
│ ├── funding-oi-extremes.jsonl
│ ├── monitor-state.json
│ └── funding-oi-state.json
├── common/
│ ├── scripts/
│ │ └── paper-trader.py
│ ├── logs/
│ │ └── paper-trader.log
│ └── data/
│ ├── metrics.json
│ ├── trades.jsonl
│ └── trader-state.json
└── systemd/
├── contrarian-monitor.service
├── polymarket-strength-filtered.service
├── hyperliquid-funding.service
├── hyperliquid-funding-oi.service
└── paper-trader.service
Services are installed to /etc/systemd/system/ and enabled for auto-start on reboot.
Once deployed, services are managed via systemctl on anjie:
# Check status
sudo systemctl status contrarian-monitor
# Start service
sudo systemctl start contrarian-monitor
# Stop service
sudo systemctl stop contrarian-monitor
# Restart service
sudo systemctl restart contrarian-monitor
# Enable for auto-start
sudo systemctl enable contrarian-monitor
# View logs
sudo journalctl -u contrarian-monitor -f
Each monitor writes alerts to JSONL format (one alert per line):
{
"timestamp": "2026-02-11T15:05:00Z",
"market_title": "ETH Up Next 5m",
"consensus_outcome": "UP",
"consensus_probability": 82.5,
"contrarian_outcome": "DOWN",
"contrarian_probability": 17.5,
"strength": "EXTREME"
}
Paper trader updates metrics every time a trade exits:
{
"polymarket_pure": {
"wins": 5,
"losses": 2,
"pnl": 0.125,
"trades": 7
},
"polymarket_strength": { ... },
"hyperliquid_funding": { ... },
"hyperliquid_oi": { ... }
}
Detailed trade history in JSONL format:
{
"timestamp": "2026-02-11T15:05:00Z",
"strategy": "polymarket_pure",
"result": "WIN",
"pnl": 0.30,
"hold_time_seconds": 300
}
ssh [email protected] "tail -f ~/trading/polymarket/logs/contrarian-monitor.log"
ssh [email protected] "tail -f ~/trading/common/logs/paper-trader.log"
ssh [email protected] "sudo journalctl -u contrarian-monitor -n 50"
ssh [email protected] "sudo journalctl -u paper-trader -n 50"
ssh [email protected] "sudo systemctl restart paper-trader"
ssh [email protected] "cat ~/trading/common/data/metrics.json | jq"
curl command-line tool[email protected]~/.ssh/id_ed25519 for passwordless authThese scripts write data that feeds the live dashboard:
http://10.3.101.5/ → 💰 P&L tab
The dashboard reads:
metrics.json - Live strategy metricstrades.jsonl - Trade history*-extremes.jsonl - Strategy alertsAnd displays:
For issues:
tail -f ~/trading/*/logs/*.logsudo systemctl status <service-name>ssh [email protected] "ls -la ~/trading"Internal use only. Do not redistribute.
46 activities