How gendevelopment/dkgcopytrade works
This repository appears to implement a Polymarket copy-trading system, with the core trading logic in Python and a thin PHP/browser layer for access, status, and scheduled operations.
1. Core responsibility
- The project is centered on monitoring Polymarket activity, mirroring or reacting to trades, and keeping track of positions and outcomes.
- The codebase suggests a mix of live automation, reporting, and post-trade settlement.
2. External market integration
- polymarket_api.py and polymarket_clob.py are the main integration points to Polymarket.
- One likely handles higher-level API calls and the other the CLOB/trading interface, which is the execution boundary for placing or managing orders.
3. Tracking / signal ingestion
- tracker.py is probably the main watcher that detects relevant trader or market events and turns them into actionable signals.
- tracker_web3.py suggests an alternate or complementary event source using Web3/on-chain data rather than only the standard API layer.
4. Trade execution and orchestration
- main.py is likely the primary runtime entrypoint that wires the tracker, API clients, database, and execution logic together.
- manual_resolve.py and redeem.py indicate separate operational paths for resolving markets or claiming settled value after outcomes are known.
5. Persistence and configuration
- database.py is the persistence boundary for storing tracked data, trade state, and computed results.
- config.py holds environment- or deployment-specific settings, likely including API credentials, account identifiers, and runtime options.
- setup_key.py suggests a one-time or admin flow for initializing signing keys or secret material.
6. Analytics subsystem
- analytics.py is the computation/reporting layer for performance metrics, trade summaries, or strategy analysis.
- analytics.html is the corresponding static UI surface for viewing those results.
7. Operational dashboard
- dashboard.py appears to serve a runtime dashboard or backend for operational visibility.
- dashboard_static.html is the browser-facing presentation layer for that dashboard, likely fed by data from Python or PHP endpoints.
8. PHP web/auth boundary
- api.php and auth.php provide a separate web/API layer, likely for browser access, session handling, or authenticated control actions.
- This implies the system is split between Python for trading/analytics and PHP for lightweight web serving or integration with existing hosting.
9. Scheduling / watchdog
- watchdog_cron.php is a cron-oriented health or maintenance hook.
- It likely monitors process liveness, triggers periodic tasks, or ensures the trading system stays operational.
10. Testing
- test_clob.py is a focused test module for the trading/exchange integration, which is the most critical and failure-prone boundary in the system.
11. Main data flow
- External Polymarket data comes in through the API/Web3 trackers.
- Python components normalize and persist state in the database.
- Trading actions are executed through the CLOB client.
- Analytics and dashboard code read from persisted state and expose results through HTML/PHP entrypoints.
12. Architecture boundary summary
- The clearest boundary is: Python = trading engine, tracking, analytics, persistence, while PHP/HTML = operator-facing web access and scheduled web-side automation.
- For an architecture diagram, the key nodes are the Polymarket integrations, the tracker/execution pipeline, the database, and the two UI layers (dashboard/analytics plus auth/API).
Main entry points: main.py Main runtime · database.py Database · polymarket_api.py API client · polymarket_clob.py CLOB client
Components 18
Python core
Trading engine, tracking, persistence, and analytics.
- Main runtime · Primary entrypoint that wires tracking, execution, and storage.
main.py - Tracker · Monitors trader and market activity for copy-trading signals.
tracker.py - Web3 tracker · Alternate event source using Web3/on-chain data.
tracker_web3.py - Database · Stores tracked state, positions, and computed results.
database.py - Config · Runtime configuration and environment-specific values.
config.py - Analytics · Computes performance metrics and trade summaries.
analytics.py - Resolve ops · Manual market resolution workflow.
manual_resolve.py - Redeem ops · Claims settled value after market outcomes are known.
redeem.py - Key setup · One-time or admin setup for signing keys and secret material.
setup_key.py - CLOB test · Focused test coverage for the trading execution boundary.
test_clob.py
Web ops
PHP and HTML surfaces for operator access and scheduled web-side tasks.
- Dashboard · Backend for operational visibility and status access.
dashboard.py - Dashboard UI · Browser-facing dashboard surface.
dashboard_static.html - Analytics UI · Browser-facing results and reporting surface.
analytics.html - API layer · Web/API boundary for browser access and control actions.
api.php - Auth layer · Authentication and session boundary for web access.
auth.php - Watchdog · Periodic health and maintenance hook.
watchdog_cron.php
Polymarket edge
Integration boundaries to Polymarket and execution.
- API client · Higher-level Polymarket API integration.
polymarket_api.py - CLOB client · Trading and order execution boundary for Polymarket.
polymarket_clob.py
Connections 23
- Main runtime → Tracker: starts · Runs the primary signal watcher.
- Main runtime → Web3 tracker: uses · Optionally consumes on-chain event signals.
- Main runtime → API client: reads market data · Fetches market and account information.
- Main runtime → CLOB client: places trades · Sends orders and execution requests.
- Main runtime → Database: persists state · Stores tracked positions and runtime state.
- Tracker → API client: queries · Looks up markets, traders, and activity.
- Web3 tracker → API client: correlates · Maps chain events to market context.
- Tracker → Database: writes signals · Stores detected opportunities and state.
- Web3 tracker → Database: writes signals · Persists web3-derived tracking data.
- API client → CLOB client: feeds execution · Provides context needed for order placement.
- CLOB client → Database: records fills · Persists execution results and position changes.
- Analytics → Database: reads history · Analyzes stored trades and outcomes.
- Dashboard → Database: reads status · Serves operational state to the UI.
- Dashboard UI → Dashboard: views · Browser UI presents dashboard data.
- Analytics UI → Analytics: views · Static report surface presents analytics output.
- API layer → Auth layer: checks auth · Uses authentication/session controls.
- API layer → Dashboard: controls · Exposes operator-facing actions and status.
- Watchdog → Dashboard: health checks · Monitors runtime availability and maintenance signals.
- Resolve ops → API client: resolves · Performs manual market resolution operations.
- Redeem ops → CLOB client: settles · Claims or finalizes settled positions.
- Key setup → Config: initializes · Bootstraps key material and configuration.
- CLOB test → CLOB client: validates · Tests the execution client boundary.
- Config → Main runtime: configures · Provides runtime settings to the orchestrator.