# beatzxbt/bybit-smm architecture

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

- Interactive diagram: https://gitdiagram.com/beatzxbt/bybit-smm
- Repository: https://github.com/beatzxbt/bybit-smm

## Overview

Based on our analysis of the file tree and README, we recognize that this project is an algorithmic trading bot—a market making bot specifically designed for Bybit (with an optional Binance data feed). The project is organized around handling live market data via websockets and REST endpoints, processing that data with indicators and strategies, and (optionally) managing orders via an order management component.

##### Main components
- Environment & Configuration: Represent the .env, parameters.yaml, and configuration files that hold API keys and trading parameters.
- Exchange Interface Modules: Separate components under the “src/exchanges” directory for each supported exchange (Bybit and Binance). Each exchange has its own directories for REST endpoints (GET, POST) and websocket functionalities (with dedicated websocket handlers for different event types, e.g., orderbook updates, trades, executions).
- Shared State & Data Aggregation: A central shared state class (e.g., src/sharedstate.py) that aggregates incoming market data from the various exchange modules. Also consider the “src/exchanges/common” module that includes utilities like local order books.
- Indicators Module: Components found in “src/indicators” that calculate market indicators (for example, Bollinger Band Width, EMA) used by the strategy.
- Strategy Engine: Under the “src/strategy” directory you have the core logic (core.py) and specific features (the features subdirectory) that process market data, evaluate inventory levels, and determine optimal bid/ask quotes. This module incorporates logic for generating pricing, spread adjustments, and managing edge cases.
- Order Management System (OMS): Although mentioned as “currently disabled,” this module (likely in src/strategy/oms.py) is responsible for managing order states, transitions, and sending orders in a rate-limited efficient manner.
- Utility Modules: The “src/utils” folder provides supportive functionality such as rounding, JIT functions, and miscellaneous helpers.

##### Relationships and Data Flow
- Next, connect the Indicators module to the “Strategy Engine” where different features (e.g., ob_imbalance, trades_imbalance, mark_spread) calculate market conditions and generate optimal quotes. Also, incorporate a relationship from the shared market data directly to strategy modules since some features likely use raw data as well.
- Finally, from the Strategy Engine, show a connection to the “OMS” (Order Management System) which handles order placement and (when enabled) order state transitions. Additionally, show feedback loops or confirmation channels back from the OMS to the shared state if necessary.

##### Architectural Patterns and Technologies
- That the project separates responsibilities clearly by having different directories for exchange-specific code, strategy, and calculation modules.
- There is an adherence to a clean modular design where data flow is unidirectional: from external market data -> aggregation/shared state -> processing/indicators -> strategy decision making -> order management.
- Python is used as the primary language with supporting libraries indicated in the requirements.txt.
- The use of websockets (real-time data streaming) and REST endpoints suggests an architecture that handles asynchronous data processing, ensuring that components remain decoupled and can be maintained or replaced individually.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Exchange Interfaces"
        subgraph "Bybit"
            BE("Bybit Endpoints"):::exchange
            BW("Bybit Websockets"):::exchange
        end
        subgraph "Binance"
            BE2("Binance Endpoints"):::exchange
            BW2("Binance Websockets"):::exchange
        end
    end

    Config("Configuration (.env & parameters.yaml)"):::config
    Aggregator("Market Data Aggregator"):::aggregator
    LOB("Local Order Book"):::aggregator
    Indicators("Indicators Module (Bollinger, EMA)"):::indicator
    Strategy("Strategy Engine (Core & Features)"):::strategy
    OMS("Order Management System (OMS)"):::oms
    Utility("Utility Modules"):::utility

    %% Data flow from Exchange Interfaces to Aggregator
    BE -->|"market_data_stream"| Aggregator
    BW -->|"market_data_stream"| Aggregator
    BE2 -->|"market_data_stream"| Aggregator
    BW2 -->|"market_data_stream"| Aggregator

    %% Shared Data and Indicator Processing
    Aggregator -->|"orderbook_update"| LOB
    Aggregator -->|"calc_indicators"| Indicators
    Aggregator -->|"raw_data"| Strategy
    Indicators -->|"indicator_output"| Strategy

    %% Strategy to Order Management and feedback loop
    Strategy -->|"order_submission"| OMS
    OMS -->|"order_confirmation"| Aggregator

    %% Configuration feeding parameters
    Config -->|"config_params"| Strategy
    Config -->|"config_params"| OMS

    %% Utility support for modules
    Utility -->|"support_funcs"| Indicators
    Utility -->|"helper_funcs"| Strategy
    Utility -->|"utility_support"| OMS

    %% Click Events for Component Mappings
    click Config "https://github.com/beatzxbt/bybit-smm/blob/master/.env.example"
    click BE "https://github.com/beatzxbt/bybit-smm/tree/master/src/exchanges/bybit"
    click BW "https://github.com/beatzxbt/bybit-smm/tree/master/src/exchanges/bybit/websockets/handlers"
    click BE2 "https://github.com/beatzxbt/bybit-smm/tree/master/src/exchanges/binance"
    click BW2 "https://github.com/beatzxbt/bybit-smm/tree/master/src/exchanges/binance/websockets/handlers"
    click Aggregator "https://github.com/beatzxbt/bybit-smm/blob/master/src/sharedstate.py"
    click LOB "https://github.com/beatzxbt/bybit-smm/blob/master/src/exchanges/common/localorderbook.py"
    click Indicators "https://github.com/beatzxbt/bybit-smm/tree/master/src/indicators"
    click Strategy "https://github.com/beatzxbt/bybit-smm/tree/master/src/strategy"
    click OMS "https://github.com/beatzxbt/bybit-smm/blob/master/src/strategy/oms.py"
    click Utility "https://github.com/beatzxbt/bybit-smm/tree/master/src/utils"

    %% Styles for clear color coding
    classDef exchange fill:#DDEEFF,stroke:#333,stroke-width:2px;
    classDef aggregator fill:#FFEFD5,stroke:#cc9900,stroke-width:2px;
    classDef indicator fill:#E6FFCC,stroke:#669900,stroke-width:2px;
    classDef strategy fill:#FFCCCC,stroke:#CC0000,stroke-width:2px;
    classDef oms fill:#CCCCFF,stroke:#3333CC,stroke-width:2px;
    classDef config fill:#FFFFCC,stroke:#999900,stroke-width:2px;
    classDef utility fill:#FFEECC,stroke:#CC6600,stroke-width:2px;
```
