# timur-ten/ttrade architecture

> Architecture diagram of the GitHub repository timur-ten/ttrade, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/timur-ten/ttrade
- Repository: https://github.com/timur-ten/ttrade

## Overview

TTrade is a crypto market-data, paper-trading, and research platform: Binance data is parsed and synchronized into an order book, strategies drive simulated execution, and recorded raw feeds can be replayed through the same engine for performance reporting. C++ owns the latency-sensitive feed, book, strategy, and simulation path; .NET services consume ZeroMQ/Protobuf events for persistence, risk, analytics, and REST queries. The graph includes documented capabilities whose implementation was not sampled, but limits their internal wiring to what the README or sampled entry points support.

Main entry points: [`cpp/libs/engine/src/trading_engine.cpp`](https://github.com/timur-ten/ttrade/blob/main/cpp/libs/engine/src/trading_engine.cpp) (Trading engine), [`cpp/libs/bus`](https://github.com/timur-ten/ttrade/tree/main/cpp/libs/bus) (ZeroMQ / Protobuf bus), [`cpp/apps/trader/main.cpp`](https://github.com/timur-ten/ttrade/blob/main/cpp/apps/trader/main.cpp) (Live trader), [`cpp/libs/feed`](https://github.com/timur-ten/ttrade/tree/main/cpp/libs/feed) (Feed clients)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cpp_market["C++ market data"]
  node_feedhandler["Trade feed handler<br/>[main.cpp]"]
  node_bookbuilder["Book builder<br/>[main.cpp]"]
  node_recorder["Tape recorder<br/>[main.cpp]"]
  node_parser["Binance parser<br/>[binance_parser.cpp]"]
  node_feed_clients["Feed clients"]
  node_tape["Tape reader/writer<br/>[tape.cpp]"]
  node_book_sync["Book synchronization<br/>[synchronizer.cpp]"]
  node_order_book["Order book<br/>[order_book.cpp]"]
end

subgraph group_cpp_trade["Trading and research"]
  node_trader["Live trader<br/>[main.cpp]"]
  node_backtester["Backtester<br/>[main.cpp]"]
  node_engine["Trading engine<br/>[trading_engine.cpp]"]
  node_strategies["Trading strategies"]
  node_simulator["Exchange simulator"]
  node_performance["Performance analytics<br/>[performance.cpp]"]
end

subgraph group_dotnet[".NET services"]
  node_marketdata_service["Market data subscriber<br/>[TTrade.MarketData]"]
  node_risk_service["Risk monitor<br/>[TTrade.Risk]"]
  node_analytics_service["Analytics service<br/>[TTrade.Analytics]"]
end

subgraph group_transport["Messaging and observability"]
  node_bus_codec["ZeroMQ / Protobuf bus"]
  node_contracts["Protobuf contracts"]
  node_metrics["Prometheus metrics"]
end

subgraph group_storage_api["Persistence and API"]
  node_persistence_service["Persistence recorder<br/>[TTrade.Persistence]"]
  node_timescale_writer["Timescale writer<br/>[TickWriter.cs]"]
  node_timescale[("TimescaleDB")]
  node_gateway["REST gateway<br/>[Program.cs]"]
  node_repository["Market data repository"]
end

node_binance(("Binance"))
node_operator(("Operator / user"))
node_grafana["Grafana"]

node_binance -->|"streams / snapshots"| node_feed_clients
node_feedhandler -->|"opens stream"| node_feed_clients
node_feedhandler -->|"parses trades"| node_parser
node_feedhandler -->|"publishes trades"| node_bus_codec
node_bookbuilder -->|"opens stream / REST"| node_feed_clients
node_bookbuilder -->|"parses depth"| node_parser
node_bookbuilder -->|"synchronizes diffs"| node_book_sync
node_book_sync -->|"updates book"| node_order_book
node_bookbuilder -->|"publishes book"| node_bus_codec
node_recorder -->|"captures stream"| node_feed_clients
node_recorder -->|"writes raw records"| node_tape
node_trader -->|"opens stream / REST"| node_feed_clients
node_trader -->|"feeds messages"| node_engine
node_engine -->|"parses payloads"| node_parser
node_engine -->|"synchronizes updates"| node_book_sync
node_engine -->|"maintains book"| node_order_book
node_engine -->|"dispatches market events"| node_strategies
node_engine -->|"simulates execution"| node_simulator
node_trader -->|"publishes fills / state"| node_bus_codec
node_trader -->|"records metrics"| node_metrics
node_operator -->|"selects strategy"| node_trader
node_backtester -->|"replays records"| node_tape
node_backtester -->|"feeds recorded events"| node_engine
node_backtester -->|"builds report"| node_performance
node_backtester -->|"selects strategy"| node_strategies
node_marketdata_service -->|"subscribes to trades"| node_bus_codec
node_marketdata_service -->|"streams market data"| node_persistence_service
node_persistence_service -->|"subscribes to events"| node_bus_codec
node_persistence_service -->|"records data"| node_timescale_writer
node_timescale_writer -->|"writes hypertables"| node_timescale
node_gateway -->|"handles queries"| node_repository
node_repository -->|"reads market data"| node_timescale
node_operator -->|"queries REST API"| node_gateway
node_risk_service -->|"consumes positions / sends commands"| node_bus_codec
node_analytics_service -->|"consumes trading events"| node_bus_codec
node_grafana -.->|"scrapes metrics"| node_metrics

click node_feedhandler "https://github.com/timur-ten/ttrade/blob/main/cpp/apps/feedhandler/main.cpp"
click node_bookbuilder "https://github.com/timur-ten/ttrade/blob/main/cpp/apps/bookbuilder/main.cpp"
click node_recorder "https://github.com/timur-ten/ttrade/blob/main/cpp/apps/recorder/main.cpp"
click node_parser "https://github.com/timur-ten/ttrade/blob/main/cpp/libs/feed/src/binance_parser.cpp"
click node_feed_clients "https://github.com/timur-ten/ttrade/tree/main/cpp/libs/feed"
click node_tape "https://github.com/timur-ten/ttrade/blob/main/cpp/libs/feed/src/tape.cpp"
click node_book_sync "https://github.com/timur-ten/ttrade/blob/main/cpp/libs/book/src/synchronizer.cpp"
click node_order_book "https://github.com/timur-ten/ttrade/blob/main/cpp/libs/book/src/order_book.cpp"
click node_trader "https://github.com/timur-ten/ttrade/blob/main/cpp/apps/trader/main.cpp"
click node_backtester "https://github.com/timur-ten/ttrade/blob/main/cpp/apps/backtester/main.cpp"
click node_engine "https://github.com/timur-ten/ttrade/blob/main/cpp/libs/engine/src/trading_engine.cpp"
click node_strategies "https://github.com/timur-ten/ttrade/tree/main/cpp/libs/strategy"
click node_simulator "https://github.com/timur-ten/ttrade/blob/main/cpp/libs/sim/src/exchange_simulator.cpp"
click node_performance "https://github.com/timur-ten/ttrade/blob/main/cpp/libs/analytics/src/performance.cpp"
click node_bus_codec "https://github.com/timur-ten/ttrade/tree/main/cpp/libs/bus"
click node_contracts "https://github.com/timur-ten/ttrade/tree/main/proto"
click node_metrics "https://github.com/timur-ten/ttrade/tree/main/cpp/libs/metrics"
click node_marketdata_service "https://github.com/timur-ten/ttrade/tree/main/csharp/src/TTrade.MarketData"
click node_risk_service "https://github.com/timur-ten/ttrade/tree/main/csharp/src/TTrade.Risk"
click node_analytics_service "https://github.com/timur-ten/ttrade/tree/main/csharp/src/TTrade.Analytics"
click node_persistence_service "https://github.com/timur-ten/ttrade/tree/main/csharp/src/TTrade.Persistence"
click node_timescale_writer "https://github.com/timur-ten/ttrade/blob/main/csharp/src/TTrade.Persistence/TickWriter.cs"
click node_gateway "https://github.com/timur-ten/ttrade/blob/main/csharp/src/TTrade.Gateway/Program.cs"
click node_repository "https://github.com/timur-ten/ttrade/blob/main/csharp/src/TTrade.Gateway/MarketDataRepository.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_feedhandler,node_bookbuilder,node_recorder,node_parser,node_feed_clients,node_tape,node_book_sync,node_order_book,node_operator toneBlue
class node_trader,node_backtester,node_engine,node_strategies,node_simulator,node_performance toneAmber
class node_marketdata_service,node_risk_service,node_analytics_service toneMint
class node_bus_codec,node_contracts,node_metrics toneRose
class node_persistence_service,node_timescale_writer,node_timescale,node_gateway,node_repository,node_binance,node_grafana toneIndigo
```

## Components

### C++ market data

- [Trade feed handler](https://github.com/timur-ten/ttrade/blob/main/cpp/apps/feedhandler/main.cpp): `cpp/apps/feedhandler/main.cpp`
- [Book builder](https://github.com/timur-ten/ttrade/blob/main/cpp/apps/bookbuilder/main.cpp): `cpp/apps/bookbuilder/main.cpp`
- [Tape recorder](https://github.com/timur-ten/ttrade/blob/main/cpp/apps/recorder/main.cpp): `cpp/apps/recorder/main.cpp`
- [Binance parser](https://github.com/timur-ten/ttrade/blob/main/cpp/libs/feed/src/binance_parser.cpp): `cpp/libs/feed/src/binance_parser.cpp`
- [Feed clients](https://github.com/timur-ten/ttrade/tree/main/cpp/libs/feed): `cpp/libs/feed`
- [Tape reader/writer](https://github.com/timur-ten/ttrade/blob/main/cpp/libs/feed/src/tape.cpp): `cpp/libs/feed/src/tape.cpp`
- [Book synchronization](https://github.com/timur-ten/ttrade/blob/main/cpp/libs/book/src/synchronizer.cpp): `cpp/libs/book/src/synchronizer.cpp`
- [Order book](https://github.com/timur-ten/ttrade/blob/main/cpp/libs/book/src/order_book.cpp): `cpp/libs/book/src/order_book.cpp`

### Trading and research

- [Live trader](https://github.com/timur-ten/ttrade/blob/main/cpp/apps/trader/main.cpp): `cpp/apps/trader/main.cpp`
- [Backtester](https://github.com/timur-ten/ttrade/blob/main/cpp/apps/backtester/main.cpp): `cpp/apps/backtester/main.cpp`
- [Trading engine](https://github.com/timur-ten/ttrade/blob/main/cpp/libs/engine/src/trading_engine.cpp): `cpp/libs/engine/src/trading_engine.cpp`
- [Trading strategies](https://github.com/timur-ten/ttrade/tree/main/cpp/libs/strategy): `cpp/libs/strategy`
- [Exchange simulator](https://github.com/timur-ten/ttrade/blob/main/cpp/libs/sim/src/exchange_simulator.cpp): `cpp/libs/sim/src/exchange_simulator.cpp`
- [Performance analytics](https://github.com/timur-ten/ttrade/blob/main/cpp/libs/analytics/src/performance.cpp): `cpp/libs/analytics/src/performance.cpp`

### .NET services

- [Market data subscriber](https://github.com/timur-ten/ttrade/tree/main/csharp/src/TTrade.MarketData): `csharp/src/TTrade.MarketData`
- [Risk monitor](https://github.com/timur-ten/ttrade/tree/main/csharp/src/TTrade.Risk): `csharp/src/TTrade.Risk`
- [Analytics service](https://github.com/timur-ten/ttrade/tree/main/csharp/src/TTrade.Analytics): `csharp/src/TTrade.Analytics`

### Messaging and observability

- [ZeroMQ / Protobuf bus](https://github.com/timur-ten/ttrade/tree/main/cpp/libs/bus): `cpp/libs/bus`
- [Protobuf contracts](https://github.com/timur-ten/ttrade/tree/main/proto): `proto`
- [Prometheus metrics](https://github.com/timur-ten/ttrade/tree/main/cpp/libs/metrics): `cpp/libs/metrics`

### Persistence and API

- [Persistence recorder](https://github.com/timur-ten/ttrade/tree/main/csharp/src/TTrade.Persistence): `csharp/src/TTrade.Persistence`
- [Timescale writer](https://github.com/timur-ten/ttrade/blob/main/csharp/src/TTrade.Persistence/TickWriter.cs): `csharp/src/TTrade.Persistence/TickWriter.cs`
- **TimescaleDB**
- [REST gateway](https://github.com/timur-ten/ttrade/blob/main/csharp/src/TTrade.Gateway/Program.cs): `csharp/src/TTrade.Gateway/Program.cs`
- [Market data repository](https://github.com/timur-ten/ttrade/blob/main/csharp/src/TTrade.Gateway/MarketDataRepository.cs): `csharp/src/TTrade.Gateway/MarketDataRepository.cs`

### Other components

- **Binance**
- **Operator / user**
- **Grafana**

## Connections

- Binance → Feed clients: streams / snapshots
- Trade feed handler → Feed clients: opens stream
- Trade feed handler → Binance parser: parses trades
- Trade feed handler → ZeroMQ / Protobuf bus: publishes trades
- Book builder → Feed clients: opens stream / REST
- Book builder → Binance parser: parses depth
- Book builder → Book synchronization: synchronizes diffs
- Book synchronization → Order book: updates book
- Book builder → ZeroMQ / Protobuf bus: publishes book
- Tape recorder → Feed clients: captures stream
- Tape recorder → Tape reader/writer: writes raw records
- Live trader → Feed clients: opens stream / REST
- Live trader → Trading engine: feeds messages
- Trading engine → Binance parser: parses payloads
- Trading engine → Book synchronization: synchronizes updates
- Trading engine → Order book: maintains book
- Trading engine → Trading strategies: dispatches market events
- Trading engine → Exchange simulator: simulates execution
- Live trader → ZeroMQ / Protobuf bus: publishes fills / state
- Live trader → Prometheus metrics: records metrics
- Operator / user → Live trader: selects strategy
- Backtester → Tape reader/writer: replays records
- Backtester → Trading engine: feeds recorded events
- Backtester → Performance analytics: builds report
- Backtester → Trading strategies: selects strategy
- Market data subscriber → ZeroMQ / Protobuf bus: subscribes to trades
- Market data subscriber → Persistence recorder: streams market data
- Persistence recorder → ZeroMQ / Protobuf bus: subscribes to events
- Persistence recorder → Timescale writer: records data
- Timescale writer → TimescaleDB: writes hypertables
- REST gateway → Market data repository: handles queries
- Market data repository → TimescaleDB: reads market data
- Operator / user → REST gateway: queries REST API
- Risk monitor → ZeroMQ / Protobuf bus: consumes positions / sends commands
- Analytics service → ZeroMQ / Protobuf bus: consumes trading events
- Grafana → Prometheus metrics: scrapes metrics
