# wisespace-io/binance-rs architecture

> Architecture diagram of the GitHub repository wisespace-io/binance-rs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wisespace-io/binance-rs
- Repository: https://github.com/wisespace-io/binance-rs

## Overview

##### Component Details

a) Spot Trading API Section:
- Market Data Module (src/market.rs)
- Account Operations Module (src/account.rs)
- User Stream Module (src/userstream.rs)
- General Operations Module (src/general.rs)

b) Futures Trading API Section (src/futures/):
- Futures Market Module
- Futures Account Module
- Futures User Stream Module
- Futures WebSocket Module

c) WebSocket Streams Section:
- Real-time Market Data Streams
- User Data Streams
- Multiple Stream Support
- Connection Management

##### Interaction Flows

- Client authentication flow
- REST API request/response paths
- WebSocket connection establishment
- Data streaming directions
- Error handling paths

##### Implementation Details

Notes showing:
- Supported API endpoints
- Authentication methods
- Rate limiting
- Market data types
- Order types
- WebSocket event types

##### Technical Notes

Annotations for:
- Async operations
- Thread safety considerations
- Memory management
- Connection pooling
- Rate limiting

##### The various types of market data and trading operations supported

Keep the abstraction level focused on the architectural components while providing enough detail to understand the interaction patterns and data flows. This will help developers understand both the high-level structure and the specific implementation details of the library.

Remember to indicate that this is a client library, so all external connections are to Binance's APIs, and show how the library handles both REST and WebSocket connections in a unified way while maintaining separate concerns for different trading types (spot vs. futures).

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External["External Binance APIs"]
        REST["REST API Endpoints"]:::external
        WS["WebSocket API Endpoints"]:::external
        TEST["Testnet Endpoints"]:::external
    end

    subgraph Core["Binance-RS Client"]
        CONFIG["Configuration Layer"]:::config
        click CONFIG "https://github.com/wisespace-io/binance-rs/blob/master/src/config.rs"
        
        ERROR["Error Handling"]:::error
        click ERROR "https://github.com/wisespace-io/binance-rs/blob/master/src/errors.rs"
        
        CLIENT["API Client"]:::core
        click CLIENT "https://github.com/wisespace-io/binance-rs/blob/master/src/client.rs"
        
        UTIL["Utility Module"]:::util
        click UTIL "https://github.com/wisespace-io/binance-rs/blob/master/src/util.rs"
        
        API["API Definitions"]:::api
        click API "https://github.com/wisespace-io/binance-rs/blob/master/src/api.rs"

        subgraph Spot["Spot Trading API"]
            direction TB
            MARKET["Market Data"]:::spot
            click MARKET "https://github.com/wisespace-io/binance-rs/blob/master/src/market.rs"
            
            ACCOUNT["Account Operations"]:::spot
            click ACCOUNT "https://github.com/wisespace-io/binance-rs/blob/master/src/account.rs"
            
            USERSTREAM["User Stream"]:::spot
            click USERSTREAM "https://github.com/wisespace-io/binance-rs/blob/master/src/userstream.rs"
            
            GENERAL["General Operations"]:::spot
            click GENERAL "https://github.com/wisespace-io/binance-rs/blob/master/src/general.rs"
            
            SAVINGS["Savings Module"]:::spot
            click SAVINGS "https://github.com/wisespace-io/binance-rs/blob/master/src/savings.rs"
            
            MODEL_SPOT["Data Models"]:::spot
            click MODEL_SPOT "https://github.com/wisespace-io/binance-rs/blob/master/src/model.rs"
            
            WS_SPOT["WebSocket Streams"]:::ws
            click WS_SPOT "https://github.com/wisespace-io/binance-rs/blob/master/src/websockets.rs"
        end

        subgraph Futures["Futures Trading API"]
            direction TB
            F_MARKET["Futures Market Data"]:::futures
            click F_MARKET "https://github.com/wisespace-io/binance-rs/blob/master/src/futures/market.rs"
            
            F_ACCOUNT["Futures Account"]:::futures
            click F_ACCOUNT "https://github.com/wisespace-io/binance-rs/blob/master/src/futures/account.rs"
            
            F_USERSTREAM["Futures User Stream"]:::futures
            click F_USERSTREAM "https://github.com/wisespace-io/binance-rs/blob/master/src/futures/userstream.rs"
            
            F_GENERAL["Futures General"]:::futures
            click F_GENERAL "https://github.com/wisespace-io/binance-rs/blob/master/src/futures/general.rs"
            
            F_MODEL["Futures Data Models"]:::futures
            click F_MODEL "https://github.com/wisespace-io/binance-rs/blob/master/src/futures/model.rs"
            
            F_WS["Futures WebSocket"]:::ws
            click F_WS "https://github.com/wisespace-io/binance-rs/blob/master/src/futures/websockets.rs"
        end
    end

    %% Connections
    REST --> CLIENT
    WS --> WS_SPOT
    WS --> F_WS
    TEST -.-> CLIENT

    CLIENT --> Spot
    CLIENT --> Futures
    CONFIG --> CLIENT
    ERROR --> CLIENT
    API --> CLIENT
    UTIL --> CLIENT

    %% Styling
    classDef external fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef config fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef error fill:#FF6B6B,stroke:#333,stroke-width:2px
    classDef spot fill:#B0C4DE,stroke:#333,stroke-width:2px
    classDef futures fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef ws fill:#9370DB,stroke:#333,stroke-width:2px
    classDef util fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef api fill:#F0E68C,stroke:#333,stroke-width:2px
```
