Skip to content

adilsondias-engineer/29-cpp-trading-ui

Repository files navigation

Project 29: TradingOS Control Panel

Part of FPGA Trading Systems Portfolio

This project is part of a complete end-to-end trading system:

  • Main Repository: fpga-trading-systems
  • Project Number: 29 of 30
  • Category: C++ Application
  • Dependencies: Projects 24-28 (Trading system components)

SDL2 DRM/KMS graphical control panel for TradingOS, running directly on framebuffer without X11 or Wayland.

Overview

A dedicated graphical interface for monitoring and controlling the FPGA trading system. Renders directly to the framebuffer using SDL2's DRM/KMS backend, eliminating display server overhead and providing minimal-latency visual updates on a 5120x1440 ultrawide display.

Architecture

┌─────────────────────────────────────────────────────────────────────────────────────┐
│                    Project 29: TradingOS Control Panel                               │
├─────────────────────────────────────────────────────────────────────────────────────┤
│                                                                                      │
│  ┌──────────────┐    ┌─────────────────┐    ┌────────────────┐                      │
│  │  UIManager   │ ←→ │ ProcessManager  │ ←→ │ MetricsReader  │                      │
│  │              │    │                 │    │                │                      │
│  │ • SDL2 init  │    │ • fork/exec     │    │ • CPU usage    │                      │
│  │ • Rendering  │    │ • SCHED_FIFO    │    │ • GPU usage    │                      │
│  │ • Events     │    │ • CPU affinity  │    │ • Memory       │                      │
│  │ • Fonts      │    │ • Health check  │    │ • Prometheus   │                      │
│  └──────────────┘    └─────────────────┘    └────────────────┘                      │
│          │                    │                     │                                │
│          └────────────────────┼─────────────────────┘                                │
│                               ▼                                                      │
│  ┌──────────────────────────────────────────────────────────────────────────────┐   │
│  │                           Widgets                                             │   │
│  │  ┌───────────┐  ┌──────────────┐  ┌─────────────┐  ┌──────────┐  ┌────────┐  │   │
│  │  │ StatusBox │  │ ProgressBar  │  │  LogViewer  │  │  Button  │  │ Header │  │   │
│  │  │ (P24-P26) │  │ (CPU/GPU/Mem)│  │ (sys log)   │  │ (actions)│  │ (logo) │  │   │
│  │  └───────────┘  └──────────────┘  └─────────────┘  └──────────┘  └────────┘  │   │
│  └──────────────────────────────────────────────────────────────────────────────┘   │
│                                                                                      │
│  Display: 5120x1440 ultrawide @ 30 FPS (DRM/KMS direct framebuffer)                 │
└─────────────────────────────────────────────────────────────────────────────────────┘

Features

  • Process Control: Start, stop, restart P24 (Order Gateway), P25 (Market Maker), P26 (Execution Engine)
  • Real-time Metrics: CPU, GPU, and memory utilization progress bars
  • Per-process Status: Running state, BBO/s throughput, latency measurements
  • System Log Viewer: Color-coded log levels (INFO, WARN, ERROR)
  • Keyboard Navigation: Tab/Shift+Tab focus cycling, Enter to activate
  • About Dialog: System information and version display
  • Background Logo: Subtle 5120x1440 branded background

Display Configuration

  • Resolution: 5120x1440 ultrawide fullscreen
  • Backend: SDL2 DRM/KMS (no X11/Wayland required)
  • Frame Rate: 30 FPS (configurable)
  • Color Scheme: Dark theme with cyan accents

Dependencies

Library Purpose Required
SDL2 Core graphics and input Yes
SDL2_image PNG logo loading Optional
SDL2_ttf TrueType font rendering Optional
nlohmann/json Configuration parsing Yes

Without SDL2_ttf, the application falls back to bitmap text rendering.

Building

cd 29-trading-ui
mkdir -p build && cd build
cmake ..
make -j$(nproc)

Cross-compiling for TradingOS

./build-with-buildroot.sh

Configuration

Configuration file: config.json

{
    "display": {
        "width": 5120,
        "height": 1440,
        "fullscreen": true,
        "fps_limit": 30
    },
    "processes": {
        "p24": {
            "name": "Order Gateway",
            "executable": "/opt/trading/bin/order_gateway",
            "config": "/opt/trading/config/p24_config.json",
            "cpu_core": 14,
            "rt_priority": 80
        },
        "p25": {
            "name": "Market Maker",
            "executable": "/opt/trading/bin/market_maker",
            "config": "/opt/trading/config/p25_config.json",
            "cpu_core": 18,
            "rt_priority": 70
        },
        "p26": {
            "name": "Execution Engine",
            "executable": "/opt/trading/bin/order_execution",
            "config": "/opt/trading/config/p26_config.json",
            "cpu_core": 19,
            "rt_priority": 75
        }
    },
    "assets": {
        "logo": "/opt/trading/assets/logo2.png",
        "font": "/opt/trading/assets/DejaVuSans.ttf"
    }
}

Usage

Command Line Options

Usage: trading_ui [options]
Options:
  -c <file>    Config file (default: /opt/trading/config/ui_config.json)
  -w           Windowed mode (for development)
  -h           Show help

Running on Framebuffer

# Force DRM/KMS backend
export SDL_VIDEODRIVER=kmsdrm
./trading_ui

Development Mode (Windowed)

./trading_ui -w

File Structure

29-trading-ui/
├── CMakeLists.txt
├── config.json
├── README.md
├── start_ui.sh
├── assets/
│   ├── boot_logo.png
│   ├── DejaVuSans.ttf
│   └── DejaVuSerif.ttf
├── include/
│   ├── ui_manager.h
│   ├── process_manager.h
│   ├── metrics_reader.h
│   └── widgets.h
└── src/
    ├── main.cpp
    ├── ui_manager.cpp
    ├── process_manager.cpp
    ├── metrics_reader.cpp
    └── widgets.cpp

Widget Classes

Widget Purpose
Button Clickable action button with focus support
StatusBox Process status display with embedded buttons
ProgressBar System metric visualization
LogViewer Scrolling system log display
Header Title bar with logo
BackgroundLogo Full-screen background image
AboutDialog Modal information dialog

Process Management

The ProcessManager class handles:

  • fork/exec: Spawning trading processes
  • SCHED_FIFO: Real-time scheduling with configurable priority
  • CPU Affinity: Pinning processes to specific cores
  • Health Monitoring: Periodic process status checks
  • Signal Handling: Graceful shutdown via SIGTERM

Integration with TradingOS

The control panel is designed to run on TradingOS, a custom Linux distribution built with Buildroot. On boot, the system launches directly into this graphical interface without a desktop environment.

Startup sequence:

  1. TradingOS kernel boots
  2. systemd starts trading-ui.service
  3. SDL2 connects to DRM/KMS
  4. Control panel renders to framebuffer
  5. User controls trading processes via touch/keyboard

Technologies

  • C++20: Core language
  • SDL2: Graphics and input (DRM/KMS backend)
  • nlohmann/json: Configuration parsing
  • POSIX: Process management (fork, exec, signals)

Status

Complete - Runs on dedicated 5120x1440 ultrawide display without desktop environment.

About

C++ trading UI - Real-time trading interface with Qt/ImGui

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors