Overview
The terminal is composed of five independent Python modules that communicate through a shared SQLite database. The Telegram bot layer handles all user interaction; the monitoring engine runs in a backgroundasyncio task per active user.
Architecture Diagram
Data Flow
Each active user spawns an independent asyncio monitoring task. Every 30 seconds the task callscheck_new_trades(), which fans out to all enabled pattern detectors in parallel. Pattern detectors call search_markets() and get_user_activity() against the Polymarket Gamma API, apply detection logic, score the signal, and write results to the database.
Module Responsibilities
| Module | Responsibility |
|---|---|
bot.py | Telegram interface, command routing, notification delivery |
monitor.py | Per-user asyncio task, 30s cycle orchestration |
detectors.py | Five pattern detector implementations |
execution.py | CLOB API order placement and position management |
database.py | SQLite schema, migrations, query helpers |
Caching Strategy
| Cache | TTL | Purpose |
|---|---|---|
Market data (_market_cache) | Session | Keyed on conditionId, id, and slug |
| Whale analysis | 6 hours | Per wallet, limits Gamma API calls |
Signal deduplication (seen_trades) | 24 hours | Prevents re-firing same market/pattern |