Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

OpenKrab/ClawPoly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🦞 ClawPoly

ClawPoly is a local-first Polymarket trading bot focused on practical execution for small-to-mid bankrolls.
It combines event mispricing (value_betting) + MM-lite filtering, then gates every trade with risk controls and Kelly sizing.


Features

  • 2026 High-Frequency Async Stack:
    • Full Asynchronous Execution: Parallel market scanning and orderbook analysis using asyncio for maximum speed.
    • 🏎️ fast_loop: HF Momentum / News Scalping — 100ms scans + front-running Binance/Oracle feeds. (ROI: 8–15%/mo).
    • 🤖 llm_catalyst_sniper: AI-Driven Catalyst Sniping — Using LLMs to front-run news and sentiment shifts.
    • 💧 market_making: Automated Market Making (AMM) — Capturing spreads + liquidity rewards. (ROI: 1–3%/mo).
    • 🕸️ intra_market_arb: Intra-market Arbitrage — Exploiting mathematical violations within a single event.
    • 🌦️ weather_trader: Weather Probability Edge — Trading temperature ranges using real-time forecast data.
  • Whitelist Execution Guardrails:
    • Optional fee/rebate-only markets (feesEnabled)
    • Minimum spread threshold before execution
  • Risk Engine:
    • Conservative/Moderate/Aggressive profiles
    • Fractional Kelly sizing + max concurrent limits + stop-loss
  • Execution Safety Layer:
    • paper -> live mode switch
    • kill switch (immediate live stop + cancel-all in loop)
    • max loss/day guard + slippage cap + cooldown
  • Terminal Experience:
    • Rich CLI output
    • Optional live TUI mode for scan/trade cycles
  • 24/7 Autonomous Trading:
    • Continuous trading loops with real-time monitoring
    • OpenClaw Gateway integration for AI-powered decision making
    • WebSocket support for real-time AI scoring
  • Polymarket API Integration:
    • Gamma API (events/markets)
    • CLOB API (orderbook/prices/trading)
    • Data API (positions/P&L)

Trading Flow

flowchart TD
    A[Fetch Active Events/Markets] --> B[Strategy Scan]
    B --> C[value_betting + MM-lite signals]
    C --> D[Whitelist Filters]
    D -->|fee/rebate + min spread| E[Risk Manager]
    E -->|kelly + limits + stop-loss| F[Execute or Dry-Run]
    F --> G[Trade Log + TUI Update]
Loading

24/7 Autonomous Trading

ClawPoly supports continuous, autonomous trading operations with real-time monitoring and AI-powered decision making through OpenClaw integration.

Continuous Trading Mode

# Start 24/7 trading with live TUI monitoring
python main.py run --risk conservative --live --tui

# Background operation (no TUI)
python main.py run --risk moderate --live

OpenClaw Gateway Integration

ClawPoly integrates with OpenClaw AI assistant for enhanced trading capabilities:

  • Real-time AI Scoring: WebSocket connection to OpenClaw Gateway for live AI analysis
  • Voice Commands: Control trading via voice through OpenClaw's voice wake/talk modes
  • Multi-channel Monitoring: Receive alerts and updates via WhatsApp, Telegram, Discord
  • Skill-based Commands: Use natural language to query positions, scan markets, and manage trades

Safety & Monitoring (24/7)

  • Kill Switch: Emergency stop with python main.py kill-switch --on
  • Real-time Stats: python main.py stats for P&L tracking
  • Position Monitoring: python main.py balance for current holdings
  • Risk Limits: Automatic daily loss caps and position limits
  • Health Checks: Built-in monitoring for API connectivity and wallet balance

Getting Started

Prerequisites

  • Python 3.9+
  • Polymarket wallet + USDC on Polygon

Installation

  1. Clone and install dependencies
git clone https://github.com/OpenKrab/ClawPoly.git
cd ClawPoly
pip install -r requirements.txt
  1. Configure environment
cp .env.example .env
  1. Run tests
python -m pytest tests/ -q -p no:asyncio

Quick Start Commands

# Show config
python main.py config

# Browse active markets
python main.py markets -n 20

# One-shot scan (no trades)
python main.py scan -n 20

# Continuous dry-run with live TUI
python main.py run --risk moderate --tui

# Live trading (real money)
python main.py run --risk conservative --live --tui

Core Commands

python main.py --help
python main.py balance
python main.py config
python main.py markets --search "bitcoin"
python main.py scan --strategy value_betting -n 30
python main.py run --strategy weather_trader --strategy fast_loop --mode live --tui
python main.py history --last 50
python main.py stats
python main.py provider-test
python main.py kill-switch --status
python main.py kill-switch --on --reason "manual stop"
python main.py cancel-all
python main.py run --risk moderate --max-trades 3 --tui

Strategy Defaults (Current)

  • ENABLED_STRATEGIES=value_betting,market_making
  • ONLY_FEE_REBATE_MARKETS=true
  • MIN_SPREAD=0.02
  • MIN_SIGNAL_CONFIDENCE=0.25
  • FEE_AWARE=true
  • STRATEGY_SCAN_CANDIDATE_LIMIT=600

Public strategy aliases now map to the legacy internal ids automatically. Examples: For 4-layer model routing, also configure:

  • AI_PROVIDER=claude (supported: claude, codex, openclaw, opencode, kilocode)
  • AI_PROVIDER_MODEL= (optional label used in signal metadata)
  • AI_PROVIDER_LIVE=false (set true to call real provider APIs)

These defaults are tuned for the real-world pattern of:

  • event mispricing selection
  • MM-lite opportunities in liquid, fee/rebate-eligible markets
  • avoiding low-quality, low-spread fills

Configuration

Example .env baseline:

PRIVATE_KEY=your_private_key_here
FUNDER_ADDRESS=your_wallet_address_here
SIGNATURE_TYPE=0

RISK_LEVEL=conservative
ENABLED_STRATEGIES=value_betting,market_making
AI_PROVIDER=claude
AI_PROVIDER_MODEL=
AI_PROVIDER_LIVE=false
AI_PROVIDER_TIMEOUT_SEC=8
AI_PROVIDER_MAX_LIVE_CALLS=25
STRATEGY_PROVIDER_OVERRIDES=weather_trader:claude,fast_loop:kilocode
STRATEGY_MODEL_OVERRIDES=
STRATEGY_SCAN_CANDIDATE_LIMIT=600

TRADING_MODE=paper
MAX_DAILY_LOSS_USD=25
DAILY_LOSS_PROXY_PCT=1.0
MAX_SLIPPAGE_PCT=0.02
TRADE_COOLDOWN_SEC=20
MAX_POSITION_USD=0
KILL_SWITCH_STATE_PATH=execution_state.json

ANTHROPIC_API_KEY=
AI_CLAUDE_BASE_URL=https://api.anthropic.com/v1/messages

OPENAI_API_KEY=
AI_CODEX_BASE_URL=https://api.openai.com/v1

OPENCLAW_API_KEY=
AI_OPENCLAW_BASE_URL=ws://127.0.0.1:18789
AI_PROVIDER_MODEL=

OPENCODE_API_KEY=
AI_OPENCODE_BASE_URL=https://opencode.ai/zen/v1

KILOCODE_API_KEY=
AI_KILOCODE_BASE_URL=https://openrouter.ai/api/v1

SCAN_INTERVAL=60
MIN_LIQUIDITY=500
MIN_VOLUME=1000

ONLY_FEE_REBATE_MARKETS=true
MIN_SPREAD=0.02
MIN_SIGNAL_CONFIDENCE=0.25
FEE_AWARE=true

See .env.example for the full set of options.

Live provider routing:

  • claude: uses Anthropic Messages API (ANTHROPIC_API_KEY)
  • codex: uses OpenAI-compatible API (OPENAI_API_KEY + AI_CODEX_BASE_URL)
  • openclaw: OpenClaw Gateway integration with WebSocket support for real-time AI scoring (OPENCLAW_API_KEY + AI_OPENCLAW_BASE_URL=ws://127.0.0.1:18789 + explicit AI_PROVIDER_MODEL or strategy model override). Supports both REST API (http/https URLs) and WebSocket connections (ws/wss URLs) to OpenClaw Gateway.
  • opencode: uses OpenCode Zen API (OPENCODE_API_KEY + AI_OPENCODE_BASE_URL=https://opencode.ai/zen/v1)
  • kilocode: uses OpenAI-compatible API (KILOCODE_API_KEY + AI_KILOCODE_BASE_URL, fallback to OPENAI_API_KEY)
  • On API errors/timeouts or missing keys, strategy falls back to local deterministic scoring
  • Use python main.py provider-test to verify whether mode is truly live

Risk Profiles

Profile Max Position Max Concurrent Stop Loss Min Edge Kelly Fraction
Conservative 5% 3 10% 8% 25%
Moderate 10% 5 20% 5% 50%
Aggressive 20% 10 30% 3% 75%

Project Structure

  • main.py - CLI entrypoint
  • config/settings.py - env loading, risk profiles, runtime settings
  • src/scanner.py - scan loop, whitelist checks, execution orchestration
  • src/client.py - Polymarket CLOB wrapper
  • src/data/ - markets/orderbook/positions/history APIs
  • src/data/db.py - SQLite schema + stats queries
  • src/strategies/value_betting.py - event mispricing logic
  • src/strategies/market_making.py - MM-lite spread/liquidity logic
  • src/strategies/penny_sniper.py - close-to-expiry execution
  • src/strategies/sports_arb.py - guaranteed math edge sports logic
  • src/ai/provider.py - provider router (claude/kilocode/codex/openclaw with WebSocket support)
  • src/risk/manager.py - risk checks and portfolio gates
  • src/risk/kelly.py - Kelly sizing helpers
  • src/utils/display.py - rich display tables
  • src/utils/tui.py - live terminal monitoring view
  • SKILL.md - OpenClaw skill integration specification
  • tests/ - strategy + risk tests

Safety Notes

  • Live trading is off by default (dry-run first)
  • Use kill switch for emergency stop: python main.py kill-switch --on
  • Keep private keys only in .env (already gitignored)
  • Use conservative profile until execution behavior is stable
  • Respect liquidity/spread filters to reduce slippage risk

Testing

python -m pytest tests/ -q -p no:asyncio

Contributing

PRs are welcome. Please include tests for behavior changes, especially in:

  • strategy signal generation
  • whitelist/risk gating
  • execution safety paths

Built for the Lobster Way 🦞


OpenClaw Integration

ClawPoly integrates seamlessly with OpenClaw AI assistant for enhanced trading capabilities:

Setup OpenClaw Integration

  1. Install OpenClaw: npm install -g openclaw@latest
  2. Configure skill in ~/.openclaw/openclaw.json:
{
  "skills": {
    "entries": {
      "clawpoly": {
        "enabled": true,
        "apiKey": { "source": "env", "provider": "default", "id": "CLAUPOLY_PRIVATE_KEY" },
        "env": {
          "CLAUPOLY_PRIVATE_KEY": "your_private_key_here"
        }
      }
    }
  }
}

Voice & Chat Commands

Once integrated, you can control ClawPoly through OpenClaw using natural language:

  • "Show me current positions on Polymarket"
  • "Scan for arbitrage opportunities"
  • "Start trading with moderate risk"
  • "What's my P&L today?"
  • "Stop all trading immediately"

WebSocket AI Scoring

For real-time AI analysis, configure WebSocket connection:

# In .env
AI_OPENCLAW_BASE_URL=ws://127.0.0.1:18789
AI_PROVIDER=openclaw

This enables live AI scoring through OpenClaw Gateway for enhanced trading decisions.

About

ClawPoly is a local-first Polymarket trading bot focused on practical execution for small-to-mid bankrolls.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages