kraken-sdk

High-performance C++ Kraken SDK featuring seemless data streaming and unique Trading Strategy Engine, lock-free architecture for <1ms end-2-end latency, and enterprise-grade data reliability.

github
  • 2,050 Raised
  • 602 Views
  • 5 Judges

Categories

  • SDK Client

Gallery

Description

I built the Kraken Enterprise C++ SDK, a high-performance market data engine designed for latency-sensitive trading applications. Unlike standard API wrappers, this SDK features a unique built-in Trading Strategy Engine that allows developers to compose complex logic (like "Price > X AND Volume > Y") directly within the client. It offers a dual-mode architecture that lets users toggle between "Direct Mode" for sub-millisecond latency or "Queue Mode" for maximum throughput, making it adaptable to both HFT and algorithmic trading use cases.

🏆 Key Highlights
🎯 Trading Strategy Engine - Built-in intelligence with composition, presets, and runtime control
⚡ High Performance - Sub-microsecond latency, lock-free architecture, 88M+ ops/sec queue
📊 Enterprise Observability - OpenTelemetry, Prometheus, structured logging
🔒 Production-Grade Reliability - CRC32 validation, gap detection, automatic reconnection, outbound rate limiter with circuit breaker.
🧪 Comprehensive Testing - 25 test suites, 328 test cases, 100% pass rate
📚 Extensive Documentation - Doxygen API docs, guides, examples, configuration reference

Technical Highlights
The SDK is built on C++17 utilizing Boost.Beast for industry-standard WebSocket I/O and RapidJSON for zero-copy parsing, achieving parse times between 1.5 and 2.2 microseconds. A core architectural decision was the implementation of a Lock-Free SPSC (Single Producer Single Consumer) Queue using rigtorp/SPSCQueue, which eliminates thread contention and enables throughput of over 320,000 messages per second. For state management, I utilized std::map to ensure O(log n) efficiency for order book updates, keeping end-to-end latency from I/O to callback under 1 millisecond.


How It Works

The developer experience is designed for rapid integration using CMake. Configuration is handled flexibly via the Builder Pattern or Environment Variables (following 12-factor app principles).

Quick Build

# Ubuntu/WSL
sudo apt-get install -y build-essential cmake libssl-dev libboost-system-dev
git clone https://github.com/kgsahil/kraken-sdk.git
cd kraken-sdk
mkdir build && cd buildcmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)

Basic Workflow:
1. Initialize: Create the client with a config object.
2. Define Logic: Attach a callback or a pre-built strategy (e.g., PriceAlert).
3. Run: Start the event loop.

// Example: minimal setup for ticker streaming
kraken::KrakenClient client;

// 1. Define logic
client.on_ticker([](const kraken::Ticker& t) {
    std::cout << t.symbol << ": $" << t.last << std::endl;
});

// 2. Subscribe and Run
client.subscribe(kraken::Channel::Ticker, {"BTC/USD"});
client.run();



 Demo & Documentation

• Documentation Quality: The project includes extensive Doxygen API reference, 9 practical examples (from trading bots to data collectors), and 25 comprehensive test suites ensuring 100% pass rates across 328 test cases.

• Performance Dashboard: The SDK includes a terminal-based UI demo (./dashboard) that visualizes real-time metrics, throughput, and connection status.

• Benchmarks: Detailed Google Benchmark reports are included, verifying the sub-microsecond latency claims.



Future Enhancements

• Full Order Execution: Currently focused on market data and alerts; future versions will integrate full trading execution (Order Entry/Cancel/Replace) to complete the lifecycle.

• Python Bindings: wrapping the high-performance C++ core with pybind11 to make the strategy engine accessible to Python data scientists.

• Hardware Acceleration: Exploring FPGA offloading for the checksum validation logic to further reduce CPU load during high-volatility events.

AND MANY MORE...








Attachments