# cia76/quikpy architecture

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

- Interactive diagram: https://gitdiagram.com/cia76/quikpy
- Repository: https://github.com/cia76/quikpy

## Overview

##### Main Components

a) Client Application Layer:
- Python Applications (represented by the Examples directory)
- QuikPy Wrapper (QuikPy.py)

b) Communication Layer:
- LUA Scripts (QUIK/lua directory)
- Socket Communication (QUIK/socket directory)

c) Trading Terminal:
- QUIK Trading Terminal
- Market Data Feeds
- Trading Infrastructure

##### Component Relationships

- Python application → QuikPy wrapper → LUA scripts → QUIK terminal → Market
- Market → QUIK terminal → LUA scripts → QuikPy wrapper → Python application

##### Detailed Component Breakdown

a) Python Layer (Top):
- Market Data (Ticker.py, Bars.py)
- Account Management (Accounts.py)
- Order Management (Transactions.py)
- Real-time Data (Stream.py)

b) Integration Layer (Middle):
- QuikPy Wrapper
- LUA Scripts:
- QuikSharp.lua (main script)
- qsfunctions.lua (core functions)
- qscallbacks.lua (event handling)
- qsutils.lua (utilities)
- socket.lua (communication)

c) Trading Infrastructure (Bottom):
- QUIK Terminal
- Market Connection
- Order Routing
- Market Data Distribution

##### Important Elements to Highlight

- Multi-script support capability
- Real-time data streaming paths
- Market data flow
- Order flow
- Event callback system

##### Technical Details

- Socket-based communication
- JSON configuration
- LUA 5.4.1 dependency
- Python requirements (pytz, pandas)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef python fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef lua fill:#90EE90,stroke:#333,stroke-width:2px
    classDef infra fill:#ffb366,stroke:#333,stroke-width:2px
    classDef interface fill:#e6e6e6,stroke:#333,stroke-width:2px
    classDef config fill:#ffe6cc,stroke:#333,stroke-width:2px

    %% Python Application Layer
    subgraph PythonLayer["Python Applications"]
        Market["Market Data Apps"]:::python
        Account["Account Management"]:::python
        Order["Order Management"]:::python
        Stream["Real-time Data"]:::python
        Multi["Multi-Script Support"]:::python
        Connect["Connection Management"]:::python
    end

    %% QuikPy Wrapper
    Wrapper["QuikPy Wrapper"]:::python

    %% LUA Integration Layer
    subgraph LuaLayer["LUA Integration"]
        QuikSharp["QuikSharp.lua"]:::lua
        QSFunctions["qsfunctions.lua"]:::lua
        QSCallbacks["qscallbacks.lua"]:::lua
        QSUtils["qsutils.lua"]:::lua
        Socket["socket.lua"]:::lua
        Config["config.json"]:::config
        DKJSON["dkjson.lua"]:::lua
        Quik2["Quik_2.lua"]:::lua
    end

    %% Trading Infrastructure
    subgraph Infrastructure["Trading Infrastructure"]
        Terminal["QUIK Terminal"]:::infra
        MarketData["Market Data Feeds"]:::infra
        OrderRouting["Order Routing"]:::infra
    end

    %% Relationships
    Market --> Wrapper
    Account --> Wrapper
    Order --> Wrapper
    Stream --> Wrapper
    Multi --> Wrapper
    Connect --> Wrapper

    Wrapper --> QuikSharp
    QuikSharp --> QSFunctions
    QuikSharp --> QSCallbacks
    QuikSharp --> QSUtils
    QuikSharp --> Socket
    QuikSharp --> Config
    QuikSharp --> DKJSON
    QuikSharp --> Quik2

    QSFunctions --> Terminal
    Terminal --> MarketData
    Terminal --> OrderRouting

    %% Click Events
    click Market "https://github.com/cia76/QuikPy/blob/master/Examples/Ticker.py"
    click Account "https://github.com/cia76/QuikPy/blob/master/Examples/Accounts.py"
    click Order "https://github.com/cia76/QuikPy/blob/master/Examples/Transactions.py"
    click Stream "https://github.com/cia76/QuikPy/blob/master/Examples/Stream.py"
    click Multi "https://github.com/cia76/QuikPy/blob/master/Examples/MultiScripts.py"
    click Connect "https://github.com/cia76/QuikPy/blob/master/Examples/Connect.py"
    click Wrapper "https://github.com/cia76/QuikPy/blob/master/QuikPy.py"
    click QuikSharp "https://github.com/cia76/QuikPy/blob/master/QUIK/lua/QuikSharp.lua"
    click QSFunctions "https://github.com/cia76/QuikPy/blob/master/QUIK/lua/qsfunctions.lua"
    click QSCallbacks "https://github.com/cia76/QuikPy/blob/master/QUIK/lua/qscallbacks.lua"
    click QSUtils "https://github.com/cia76/QuikPy/blob/master/QUIK/lua/qsutils.lua"
    click Socket "https://github.com/cia76/QuikPy/blob/master/QUIK/lua/socket.lua"
    click Config "https://github.com/cia76/QuikPy/blob/master/QUIK/lua/config.json"
    click DKJSON "https://github.com/cia76/QuikPy/blob/master/QUIK/lua/dkjson.lua"
    click Quik2 "https://github.com/cia76/QuikPy/blob/master/QUIK/lua/Quik_2.lua"

    %% Legend
    subgraph Legend
        PythonComp["Python Component"]:::python
        LuaComp["LUA Component"]:::lua
        InfraComp["Infrastructure Component"]:::infra
        ConfigComp["Configuration File"]:::config
    end
```
