Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.apeindex.trade/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The platform is composed of five independent Python modules communicating through a shared SQLite database. The Telegram bot handles all user interaction; monitoring, copy trading, and position management run in background asyncio tasks.

Architecture Diagram

┌──────────────────────────────────────────────────────────┐
│                    Telegram Bot Layer                     │
│    polymarket_bot_v2.py (6,079 lines)                    │
│    (commands, menus, notifications, deep-links, digests)  │
└───────────────────────┬──────────────────────────────────┘

          ┌─────────────┴──────────────┐
          ▼                            ▼
┌──────────────────┐        ┌──────────────────────┐
│  Per-User        │        │  Copy Trade Loop      │
│  Monitoring Task │        │  copy_trader.py       │
│  monitor.py      │        │  60s polling per      │
│  30s cycle       │        │  tracked wallet       │
│                  │        │                       │
│  8 Pattern       │        │  FOK → GTC execution  │
│  Detectors       │        │  Paper + Live modes   │
└────────┬─────────┘        └──────────┬────────────┘
         │                             │
         └──────────┬──────────────────┘

        ┌───────────┴────────────┐
        ▼                        ▼
┌──────────────────┐   ┌──────────────────────────┐
│  Polymarket APIs │   │  SQLite Database          │
│  polymarket_api  │   │  14 tables                │
│  Gamma API       │   │  users, positions, trades │
│  CLOB API        │   │  signals, copy_wallets    │
│  Google News RSS │   │  referrals, paper, alerts │
│  Builder API hdr │   └──────────────────────────┘
└──────────────────┘


┌──────────────────────┐
│  wallet_manager.py   │
│  (1,998 lines)       │
│  On-chain ops        │
│  USDC lifecycle      │
│  Builder API         │
└──────────────────────┘

Module Responsibilities

ModuleLinesResponsibility
polymarket_bot_v2.py6,079Telegram interface, command routing, notification delivery, digests, deep-linking
monitor.py977Per-user asyncio task, 30s cycle, 8 pattern detectors, signal scoring
polymarket_api.py555Gamma API + CLOB API wrapper, TTL cache, Builder ID header injection
wallet_manager.py1,998Wallet generation, key encryption, USDC approval, on-chain execution, Builder API
copy_trader.py293Copy trade logic, FOK/GTC order execution, paper trade simulation

Caching Strategy

CacheTTLPurpose
Market data (_market_cache)SessionKeyed on conditionId, id, and slug
Whale analysis6 hoursPer wallet, limits Gamma API calls
Signal deduplication24 hoursPrevents re-firing same user+market+pattern

External APIs

APIPurpose
gamma-api.polymarket.comMarket discovery, user activity, position data
clob.polymarket.comOrder placement, position management
news.google.com/rss/searchGoogle News RSS for Pre-News pattern enrichment
Polygon RPCUSDC balance, allowance, on-chain transactions