# flattrade/pythonapi architecture

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

- Interactive diagram: https://gitdiagram.com/flattrade/pythonapi
- Repository: https://github.com/flattrade/pythonapi

## Overview

##### Main Components

a) Client Layer:
- Python API Client (NorenRestApi)
- WebSocket Client Connection
- API Helper Utilities

b) Communication Layer:
- REST API Endpoints
- WebSocket Feed
- Authentication/Session Management

c) Core Functionality Groups:
- Market Data Services
- Order Management
- Portfolio Management
- Account Management

##### Detailed Architecture Breakdown

- Main `NorenApiPy` class as the central interface
- WebSocket connection handler
- Authentication flow with session management

b) Create Market Data Flow:
- Symbol/Contract Search
- Real-time Quote Subscription
- Historical Data Retrieval
- Option Chain Data

c) Order Processing Flow:
- Order Placement
- Order Modification
- Order Cancellation
- Order Status Updates

d) Portfolio Management:
- Holdings
- Positions
- Trade Book
- Order Book

##### Specific Elements

- Session Token Management
- User Authentication
- API Key Validation

b) Market Data Services:
- Symbol Search
- Security Info
- Real-time Quotes
- Time-Price Series
- Option Chain

c) Order Management:
- Place Order
- Modify Order
- Cancel Order
- Order Book
- Trade Book

d) Portfolio Services:
- Holdings
- Positions
- Limits

e) WebSocket Services:
- Market Updates
- Order Updates
- Connection Management

##### Implementation Notes

- Use clear, readable fonts
- Maintain consistent spacing
- Version information
- Important configuration parameters
- Error handling paths

##### Technical Details

- Supported order types (Market, Limit, Stop Loss, etc.)
- Product types (CNC, MIS, etc.)
- Exchange connectivity (NSE, BSE, etc.)
- Data formats (JSON responses)
- WebSocket subscription patterns

Remember to include notes about scalability considerations and any important limitations or constraints of the system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Layer"
        API[NorenRestApi]
        WS[WebSocket Client]
        AH[API Helper]:::helper
    end

    subgraph "Communication Layer"
        REST[REST API Endpoints]
        WSF[WebSocket Feed]:::websocket
        AUTH[Authentication & Session]:::auth
    end

    subgraph "Market Data Services"
        MDS1[Symbol Search]:::market
        MDS2[Security Info]:::market
        MDS3[Real-time Quotes]:::market
        MDS4[Time-Price Series]:::market
        MDS5[Option Chain]:::market
    end

    subgraph "Order Management"
        OM1[Place Order]:::order
        OM2[Modify Order]:::order
        OM3[Cancel Order]:::order
        OM4[Order Book]:::order
        OM5[Trade Book]:::order
    end

    subgraph "Portfolio Services"
        PS1[Holdings]:::portfolio
        PS2[Positions]:::portfolio
        PS3[Limits]:::portfolio
    end

    %% Client Layer Connections
    API --> REST
    API --> AUTH
    WS --> WSF
    AH --> API

    %% Authentication Flow
    AUTH --> REST
    AUTH --> WSF

    %% Market Data Flow
    REST --> MDS1
    REST --> MDS2
    REST --> MDS3
    REST --> MDS4
    REST --> MDS5
    WSF -.-> MDS3

    %% Order Management Flow
    REST --> OM1
    REST --> OM2
    REST --> OM3
    REST --> OM4
    REST --> OM5
    WSF -.-> OM4

    %% Portfolio Management Flow
    REST --> PS1
    REST --> PS2
    REST --> PS3
    WSF -.-> PS2

    %% Click Events
    click AH "https://github.com/flattrade/pythonAPI/blob/main/api_helper.py"
    click WS "https://github.com/flattrade/pythonAPI/blob/main/tests/test_websocket_feed.py"
    click MDS4 "https://github.com/flattrade/pythonAPI/blob/main/tests/test_tpseries.py"
    click MDS5 "https://github.com/flattrade/pythonAPI/blob/main/tests/option_chain.xlsx"
    click OM1 "https://github.com/flattrade/pythonAPI/blob/main/tests/test_place_order.py"
    click PS2 "https://github.com/flattrade/pythonAPI/blob/main/tests/test_product_convertion.py"

    %% Styling
    classDef market fill:#90EE90
    classDef order fill:#ADD8E6
    classDef portfolio fill:#FFA500
    classDef websocket fill:#DDA0DD
    classDef auth fill:#FFB6C1
    classDef helper fill:#F0E68C

    %% Legend
    subgraph Legend
        L1[Market Data]:::market
        L2[Order Management]:::order
        L3[Portfolio Management]:::portfolio
        L4[WebSocket]:::websocket
        L5[Authentication]:::auth
        L6[Helper Utilities]:::helper
    end
```
