# lu-yi-hsun/iqoptionapi architecture

> Architecture diagram of the GitHub repository lu-yi-hsun/iqoptionapi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lu-yi-hsun/iqoptionapi
- Repository: https://github.com/lu-yi-hsun/iqoptionapi

## Overview

##### Main Components
- API Core Module: Represent the main package (iqoptionapi) that encapsulates the functionality.
- HTTP Subsystem: This is located under iqoptionapi/http – include components such as app initialization, authentication (login, logout), user profile retrieval, registration, balance management (changebalance, billing, buyback), and other REST API endpoints.
- WebSocket (WS) Subsystem: Under iqoptionapi/ws, highlight the WebSocket client, channel handlers (located in iqoptionapi/ws/chanels), and objects (in iqoptionapi/ws/objects). These handle real-time data such as candlestick information, digital option events, order management, and other live trading updates.
- Utility/Helper Components: Include modules like constants.py, country_id.py, expiration.py, and global_value.py that support configuration and operation across HTTP and WS interactions.
- Documentation and Tests: Though not part of the runtime architecture, show external documentation (docs folder) and testing (tests folder) as complementary parts of the development cycle.

– One branch leads to the HTTP Subsystem. Here, list each REST endpoint (login, logout, getprofile, etc.) to show how the library communicates with IQ Option’s HTTP API.
– The other branch leads to the WebSocket Subsystem. Within this branch, show a layer for “Channels” (each channel handling a different aspect like heartbeat, candles, digital options, etc.) and a layer for “Objects” (which model the data coming over WS).

##### Architectural Patterns and Principles
- Modularity: Emphasize the separation between HTTP and WS communication. Each set of modules is designed to handle different communication protocols.
- Layered Design: The design separates the core API functionality from the low-level communication details. Utilities, constants, and supporting modules facilitate clean separation of concerns.
- Extensibility: The many “chanels” and “objects” modules reflect a pattern where individual endpoints/handlers can be extended or modified without affecting the overall system.
- Dependency Management: Although not explicitly a pattern here, note that configuration files (setup.py, requirements.txt) show that the library is structured to encapsulate all external dependencies.

##### Relevant Technologies and Frameworks
- Python is the main programming language.
- HTTP requests (likely using standard libraries or custom wrappers) are implemented in the HTTP subsystem.
- WebSocket communication for real-time data, with specialized channel implementations.
- The project includes test suites (under tests) and documentation (in docs) to support the API’s reliability and maintainability.
- CI/CD artifacts are visible (like .travis.yml, .github), indicating automated testing and deployment pipelines.

##### Detail and Clarity
- Don’t hesitate to break the system down into as many individual components as possible. For example, list out individual HTTP request handlers and specific WS channel modules.
- Use annotations where necessary to call out design patterns (such as asynchronous processing in WS channels) and the overall workflow.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client/Application Layer"
        CLIENT["Client (Trading Bot/Client App)"]:::client
    end

    subgraph "API Core Layer"
        API["iqoptionapi (API Core)"]:::api
        UTIL["Utilities/Helpers"]:::utility
    end

    subgraph "HTTP Subsystem"
        HT_appinit["appinit.py"]:::http
        HT_auth["auth.py"]:::http
        HT_login["login.py"]:::http
        HT_logout["logout.py"]:::http
        HT_getprofile["getprofile.py"]:::http
        HT_register["register.py"]:::http
        HT_changebalance["changebalance.py"]:::http
        HT_billing["billing.py"]:::http
        HT_buyback["buyback.py"]:::http
    end

    subgraph "WebSocket Subsystem"
        subgraph "Client/Connection"
            WS_client["client.py"]:::ws
            WS_init["__init__.py"]:::ws
        end
        subgraph "Channels"
            WS_heartbeat["heartbeat.py"]:::ws
            WS_candles["candles.py"]:::ws
            WS_digital["digital_option.py"]:::ws
        end
        subgraph "Objects"
            WS_obj_base["base.py"]:::ws
            WS_obj_betinfo["betinfo.py"]:::ws
            WS_obj_candles["candles.py"]:::ws
        end
    end

    subgraph "Supplementary Components"
        DOCS["Documentation (docs)"]:::docs
        TESTS["Testing Suite (tests)"]:::tests
    end

    IQHTTP["IQ Option Server (HTTP)"]:::external
    IQWS["IQ Option Server (WebSocket)"]:::external

    %% Connections
    CLIENT -->|"calls"| API
    API -->|"HTTP_API"| HT_login
    API -->|"WS_Conn"| WS_client
    API -->|"uses"| UTIL

    HT_login -->|"request/response"| IQHTTP
    WS_client <-->|"realtime"| IQWS

    %% Click Events - API Core
    click API "https://github.com/lu-yi-hsun/iqoptionapi/tree/master/iqoptionapi/"

    %% Click Events - HTTP Subsystem
    click HT_appinit "https://github.com/lu-yi-hsun/iqoptionapi/blob/master/iqoptionapi/http/appinit.py"
    click HT_auth "https://github.com/lu-yi-hsun/iqoptionapi/blob/master/iqoptionapi/http/auth.py"
    click HT_login "https://github.com/lu-yi-hsun/iqoptionapi/blob/master/iqoptionapi/http/login.py"
    click HT_logout "https://github.com/lu-yi-hsun/iqoptionapi/blob/master/iqoptionapi/http/logout.py"
    click HT_getprofile "https://github.com/lu-yi-hsun/iqoptionapi/blob/master/iqoptionapi/http/getprofile.py"
    click HT_register "https://github.com/lu-yi-hsun/iqoptionapi/blob/master/iqoptionapi/http/register.py"
    click HT_changebalance "https://github.com/lu-yi-hsun/iqoptionapi/blob/master/iqoptionapi/http/changebalance.py"
    click HT_billing "https://github.com/lu-yi-hsun/iqoptionapi/blob/master/iqoptionapi/http/billing.py"
    click HT_buyback "https://github.com/lu-yi-hsun/iqoptionapi/blob/master/iqoptionapi/http/buyback.py"

    %% Click Events - WebSocket Subsystem
    click WS_client "https://github.com/lu-yi-hsun/iqoptionapi/blob/master/iqoptionapi/ws/client.py"
    click WS_init "https://github.com/lu-yi-hsun/iqoptionapi/blob/master/iqoptionapi/ws/__init__.py"
    click WS_heartbeat "https://github.com/lu-yi-hsun/iqoptionapi/tree/master/iqoptionapi/ws/chanels/"
    click WS_candles "https://github.com/lu-yi-hsun/iqoptionapi/tree/master/iqoptionapi/ws/chanels/"
    click WS_digital "https://github.com/lu-yi-hsun/iqoptionapi/tree/master/iqoptionapi/ws/chanels/"
    click WS_obj_base "https://github.com/lu-yi-hsun/iqoptionapi/tree/master/iqoptionapi/ws/objects/"
    click WS_obj_betinfo "https://github.com/lu-yi-hsun/iqoptionapi/tree/master/iqoptionapi/ws/objects/"
    click WS_obj_candles "https://github.com/lu-yi-hsun/iqoptionapi/tree/master/iqoptionapi/ws/objects/"

    %% Click Events - Utilities
    click UTIL "https://github.com/lu-yi-hsun/iqoptionapi/blob/master/iqoptionapi/constants.py"
    click UTIL "https://github.com/lu-yi-hsun/iqoptionapi/blob/master/iqoptionapi/country_id.py"
    click UTIL "https://github.com/lu-yi-hsun/iqoptionapi/blob/master/iqoptionapi/expiration.py"
    click UTIL "https://github.com/lu-yi-hsun/iqoptionapi/blob/master/iqoptionapi/global_value.py"

    %% Click Events - Documentation and Testing
    click DOCS "https://github.com/lu-yi-hsun/iqoptionapi/tree/master/docs/"
    click TESTS "https://github.com/lu-yi-hsun/iqoptionapi/tree/master/tests/"

    %% Styles
    classDef api fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef http fill:#A9DFBF,stroke:#145A32,stroke-width:2px;
    classDef ws fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef utility fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef external fill:#F5CBA7,stroke:#943126,stroke-width:2px;
    classDef client fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef docs fill:#85C1E9,stroke:#1B4F72,stroke-width:2px;
    classDef tests fill:#F5B7B1,stroke:#78281F,stroke-width:2px;
```
