A high-performance trading simulator built with C++ and Qt/QML that processes real-time market data from cryptocurrency exchanges to estimate transaction costs and measure market impact.
This trading simulator connects to cryptocurrency exchange WebSocket feeds to receive real-time Level 2 order book data, processes market orders, and provides detailed analytics on transaction costs and market impact.
graph LR
A[Exchange WebSocket API] -->|Real-time L2 Data| B[WebSocket Client]
B -->|JSON Messages| C[Order Book Manager]
C -->|Bid/Ask Levels| D[Market Impact Calculator]
C -->|Price Data| E[Transaction Cost Estimator]
F[User Input] -->|Order Parameters| D
F -->|Trade Size/Side| E
D -->|Impact Metrics| G[QML Interface]
E -->|Cost Breakdown| G
C -->|Order Book Display| G
G -->|Visualization| H[User Display]
style A fill:#e1f5ff
style B fill:#fff4e1
style C fill:#ffe1e1
style D fill:#e1ffe1
style E fill:#e1ffe1
style F fill:#f0e1ff
style G fill:#ffe1f5
style H fill:#e1f5ff
- Real-time Market Data: WebSocket connection to exchange L2 order book feeds
- Order Simulation: Simulates market buy/sell orders with configurable sizes
- Impact Analysis: Calculates and visualizes market impact metrics
- Transaction Cost Estimation: Provides detailed breakdown of trading costs
- Modern UI: Built with Qt/QML for a responsive interface
- Cross-platform: Supports Windows, macOS, and Linux
- CMake 3.10 or higher
- Qt 6.6 or higher (with WebSocket module)
- C++17 compatible compiler
Before running the simulator, you must configure the WebSocket endpoint in include/QuantConstants.h:
static constexpr const char* SOCKET_ENDPOINT = "wss://your-websocket-endpoint-here";The simulator expects L2 order book data in the following JSON format:
{
"timestamp": "2025-05-04T10:39:13Z",
"exchange": "OKX",
"symbol": "BTC-USDT-SWAP",
"asks": [
["95445.5", "9.06"],
["95448", "2.05"]
],
"bids": [
["95445.4", "1104.23"],
["95445.3", "0.02"]
]
}Format Details:
timestamp: ISO 8601 formatted timestampexchange: Exchange identifier (e.g., "OKX")symbol: Trading pair symbolasks: Array of [price, quantity] arrays (sell orders)bids: Array of [price, quantity] arrays (buy orders)
You can test the simulator using OKX SPOT exchange WebSocket feeds, which provide data in the expected format:
wss://ws.okx.com:8443/ws/v5/public
Subscribe to order book updates using OKX's WebSocket API documentation.
-
Clone the repository:
git clone https://github.com/AnasElii/Trading_Simulator-.git cd Trading_Simulator- -
Configure the WebSocket endpoint: Edit
include/QuantConstants.hand set your WebSocket endpoint URL. -
Build the project:
mkdir build cd build cmake .. cmake --build .
-
Run the simulator:
./TradingSimulator
Trading_Simulator-/
├── include/ # Header files
│ └── QuantConstants.h # Configuration constants
├── interface/ # QML UI files
├── src/ # C++ source files
├── CMakeLists.txt # CMake build configuration
└── README.md
- Launch the application
- The simulator will connect to the configured WebSocket endpoint
- Real-time order book data will be displayed
- Enter order parameters (size, side) to simulate trades
- View calculated market impact and transaction costs
- Order Book Management: Maintains real-time bid/ask levels
- Market Impact Calculator: Analyzes price impact of market orders
- Transaction Cost Estimator: Breaks down trading costs including slippage
- WebSocket Client: Handles real-time data streaming
- QML Interface: Provides interactive visualization
If your exchange requires authentication, configure API credentials in QuantConstants.h:
static QString GetApiKey();
static QString GetApiSecret();
static QString GetApiPassphrase();Contributions are welcome! Please feel free to submit a Pull Request.
This project is available for personal and educational use.
Anas Elii (@AnasElii)
This simulator was developed to demonstrate real-time market data processing and trading simulation capabilities.
