# joshbazz/polymarket_copy_trader architecture

> Architecture diagram of the GitHub repository joshbazz/polymarket_copy_trader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/joshbazz/polymarket_copy_trader
- Repository: https://github.com/joshbazz/polymarket_copy_trader

## Overview

##### Main Components Identification

a) Core Components:
- Trade Monitoring System (trade_monitor.py)
- Trade Tailing System (trade_tailer.py)
- Risk Management System (risk_manager.py)
- Proxy Wallet Management (proxy_wallets.py)
- Application Module (app_mod.py)

b) External Integrations:
- Polymarket API
- User's Proxy Wallet
- Top Ranked Wallets (Data Source)

**[User Interface]**
- ↓
**[Main Controller (main.py)]**
- ↓
**[Trade Processing Pipeline]**
- ↓
**[External Services]**

##### Component Relationships

a) Data Flow:
- Trade Monitor → Trade Tailer (market data flow)
- Trade Tailer → Risk Manager (trade validation flow)
- Risk Manager → Proxy Wallet (execution flow)

b) Dependencies:
- JSON data storage (tail_trades.json) connections
- Example data relationships (example_data folder)

##### Specific Design Elements

Use the following visual elements:

- Blue rectangles: Core system components
- Green rectangles: External services (Polymarket API)
- Yellow diamonds: Decision points (Risk Manager)
- Red rectangles: Critical components (Proxy Wallet Management)

##### Detailed Component Breakdown

a) Trade Monitor:
- Market data collection
- Wallet ranking analysis
- Trade signal generation

b) Trade Tailer:
- Signal processing
- Trade replication logic
- Management

c) Risk Manager:
- Risk calculation
- Sizing
- Execution validation

##### Technical Stack Representation

- Python runtime
- Required dependencies (from requirements.txt)
- API integration points
- Data storage (JSON files)

##### Implementation Details

- Event-driven architecture for trade monitoring
- Pipeline pattern for trade processing
- Service-oriented structure for external integrations
- State management through JSON storage

##### Additional Notes

Annotations for:
- Authentication requirements
- API key management
- Proxy wallet allowances
- Configuration requirements

**[System Overview]**
- ↓
**[Component Details]**
- ↓
**[Integration Points]**
- ↓
**[Configuration Requirements]**

Remember to maintain a balance between detail and clarity, focusing on the core functionality of automatically tailing top-ranked wallet trades while properly managing risk and execution through proxy wallets.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "User Interface Layer"
        UI[User Interface]
    end

    subgraph "Control Layer"
        MC[Main Controller]:::controller
    end

    subgraph "Core Processing Layer"
        TM[Trade Monitor]:::core
        TT[Trade Tailer]:::core
        RM[Risk Manager]:::core
        PW[Proxy Wallet Management]:::core
        AM[Application Module]:::core
    end

    subgraph "External Services"
        PA[Polymarket API]:::external
        UPW[User's Proxy Wallet]:::external
        TRW[Top Ranked Wallets]:::external
    end

    subgraph "Data Storage"
        TD[Trade Data Storage]:::storage
        ETD[Example Trade Data]:::storage
        UF[Utility Functions]:::utility
        TD_REQ[Technical Dependencies]:::utility
    end

    %% Relationships
    UI --> MC
    MC --> TM
    TM --> TT
    TT --> RM
    RM --> PW
    PW --> PA
    TM --> TRW
    PW --> UPW
    AM --> MC

    %% Data relationships
    TT --> TD
    TD --> ETD
    MC --> UF
    MC --> TD_REQ

    %% Click events
    click MC "https://github.com/Joshbazz/polymarket_copy_trader/blob/main/main.py"
    click TM "https://github.com/Joshbazz/polymarket_copy_trader/blob/main/trade_monitor.py"
    click TT "https://github.com/Joshbazz/polymarket_copy_trader/blob/main/trade_tailer.py"
    click RM "https://github.com/Joshbazz/polymarket_copy_trader/blob/main/risk_manager.py"
    click PW "https://github.com/Joshbazz/polymarket_copy_trader/blob/main/proxy_wallets.py"
    click AM "https://github.com/Joshbazz/polymarket_copy_trader/blob/main/app_mod.py"
    click TD "https://github.com/Joshbazz/polymarket_copy_trader/blob/main/tail_trades.json"
    click ETD "https://github.com/Joshbazz/polymarket_copy_trader/blob/main/example_data/example_tail_trades.json"
    click TD_REQ "https://github.com/Joshbazz/polymarket_copy_trader/blob/main/requirements.txt"
    click UF "https://github.com/Joshbazz/polymarket_copy_trader/blob/main/nice_funcs.py"

    %% Styling
    classDef core fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef controller fill:#ff9e9e,stroke:#333,stroke-width:2px
    classDef external fill:#90EE90,stroke:#333,stroke-width:2px
    classDef storage fill:#FFD700,stroke:#333,stroke-width:2px
    classDef utility fill:#DDA0DD,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Controller]:::controller
        L3[External Services]:::external
        L4[Data Storage]:::storage
        L5[Utilities]:::utility
    end
```
