Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPU-HFT

Rust-based high-frequency trading infrastructure: TCP tuning, market data pipelines, lightning order placement, risk management, AWS node selection, cross-exchange routing, and high-concurrency storage.

Features

  • TCP latency tuning — Low-latency socket options (Nagle off, buffer sizes, keepalive) for exchange and client connections
  • Market data pipeline — Ingest ticks, broadcast to subscribers, last-tick cache; ultra-low latency signal distribution
  • Lightning order engine — Smart order execution with configurable max slippage (bps) and fast place path
  • Risk management — Position/order size limits, daily loss limit, circuit breaker, and risk alerts (info/warning/critical)
  • AWS node selection — Probe regions (e.g. Tokyo, Hong Kong, Singapore, Sydney) and select lowest-latency nodes
  • Cross-exchange routing — Tokyo/Hong Kong–style hub selection; record fills and track improvement vs baseline (e.g. >30%)
  • High-concurrency storage — NVMe-style random read/write store with optional batch writer for throughput

Requirements

  • Rust 1.70+ (e.g. rustup)

Optional for deployment:

  • Docker (for image build and CI/CD)

Quick start

# Build (release profile: LTO, single codegen unit)
cargo build --release

# Run
cargo run --release

# Test (unit + integration)
cargo test

# Benchmarks
cargo bench

Docker

# Build image
docker build -t cpu-hft:latest .

# Run container
docker run --rm cpu-hft:latest

# With Compose
docker compose up --build

The image is multi-stage: Rust builder for release, then a minimal debian:bookworm-slim runtime with the binary and non-root user.

Project layout

├── Cargo.toml
├── Dockerfile
├── docker-compose.yml
├── README.md
├── plan.txt
├── src/
│   ├── lib.rs          # Library root and re-exports
│   ├── main.rs         # Demo: pipeline, order, risk, AWS, cross-exchange, storage
│   ├── tcp.rs          # TCP tuning
│   ├── market_data.rs  # Ticks, pipeline, signal distribution
│   ├── order.rs        # Orders, slippage, lightning engine
│   ├── risk.rs         # Limits, alerts, circuit breaker
│   ├── aws.rs          # AWS region/node latency selection
│   ├── cross_exchange.rs # Hub routing (Tokyo/HK, improvement %)
│   └── storage.rs      # High-concurrency K/V and batch writer
├── tests/
│   └── integration_test.rs
└── benches/
    ├── order_throughput.rs
    ├── market_data_latency.rs
    └── storage_concurrent_rw.rs

Configuration

  • TCP: TcpTuning::default() (nodelay, buffer sizes, keepalive); extend with socket2 for full tuning.
  • Risk: RiskLimits::default() (max position, order size, daily loss, optional VaR); customize before building RiskManager.
  • AWS: AwsNodeSelector::default_hft_regions() (Tokyo, HK, Singapore, Sydney); replace probe_region() with real EC2/HTTP probes in production.
  • Cross-exchange: CrossExchangeRouter::new(baseline_latency_us, target_improvement_pct).

Tests

  • Unit: 14 tests in src/*.rs (tcp, market_data, order, risk, aws, cross_exchange, storage).
  • Integration: 2 tests in tests/integration_test.rs (market data → order → risk; AWS → cross-exchange → storage).

License

See repository or project policy.

About

Rust-based high-frequency trading infrastructure: TCP tuning, market data pipelines, lightning order placement, risk management, AWS node selection, cross-exchange routing, and high-concurrency storage.

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages