Kraky 🐙
A lightweight, production-ready Rust SDK for the Kraken Exchange WebSocket API v2 with built-in orderbook imbalance detection and Telegram alert integration.
Why Kraky?
Building with cryptocurrency exchange WebSocket APIs is complex. Kraky handles the hard parts:
- 🔄 Connection Management - Smart reconnection with exponential backoff
- 📊 State Synchronization - Automatic orderbook reconstruction from incremental updates
- 📈 Trading Signals - Built-in orderbook imbalance detection (bullish/bearish)
- 🤖 Telegram Alerts - Real-time notifications on your phone
- 🔐 WebSocket Trading - Place orders without REST API
- ⚡ Lightweight & Modular - Feature flags let you compile only what you need (7.2-8.5 MB)
🏆 For Hackathon Judges
Test the SDK in under 2 minutes - no credentials needed!
Prerequisites
- Rust 1.70+ (install here)
Quick Start
# Clone and test
# Run tests (69 passing)
# Run the demo - shows all core features
What You'll See
The demo showcases:
- ✅ WebSocket connection to Kraken
- ✅ Real-time orderbook updates
- ✅ Trade stream
- ✅ Ticker data
- ✅ Orderbook imbalance detection (trading signals)
- ✅ Connection event callbacks
- ✅ Backpressure monitoring
More Examples
# Basic examples (no credentials needed)
# Advanced examples (require Telegram/Kraken credentials - see SETUP.md)
📝 Need credentials? See SETUP.md for Telegram and Kraken API setup.
Installation
Add to your Cargo.toml:
[]
= { = "https://github.com/SarpTekin/kraky" }
= { = "1.35", = ["full"] }
Feature Flags
Kraky uses feature flags for modular compilation:
# Default (orderbook + reconnect + events)
= { = "..." }
# With analytics (imbalance detection)
= { = "...", = ["analytics"] }
# With Telegram alerts
= { = "...", = ["telegram-alerts"] }
# Everything (market data + analytics + telegram + trading)
= { = "...", = ["full"] }
Available features:
orderbook,trades,ticker,ohlc- Market data typesanalytics- Orderbook imbalance detectiontelegram,telegram-alerts- Telegram bot integrationauth,private,trading- Authentication and tradingchecksum- CRC32 orderbook validationsimd- SIMD-accelerated JSON parsing
See docs.rs for complete feature documentation.
Quick Start
use KrakyClient;
async
Examples
Kraky includes 18 working examples:
Basic (No Credentials):
orderbook.rs- Orderbook depth updatestrades.rs- Real-time trade streamticker.rs- Price and volume dataohlc.rs- Candlestick datamulti_subscribe.rs- Multiple concurrent subscriptionsdemo.rs- Comprehensive feature showcase
Advanced (Requires Setup):
telegram_imbalance_bot.rs- Orderbook imbalance alertswhale_watcher.rs- Large order detectionsimple_price_alerts.rs- Price threshold alertstelegram_private_alerts.rs- Account activity notificationstelegram_trading_bot.rs- Automated trading with alertsexport_to_csv.rs- Market data export- And more...
See examples/ directory for all examples.
Documentation
- 📚 API Documentation: docs.rs/kraky - Complete API reference
- 🔧 Setup Guide: SETUP.md - Telegram and Kraken API credentials
- 💡 Examples: examples/ - 18 working examples with explanations
Features
Core Features (Always Included)
- ✅ WebSocket connection management
- ✅ Automatic reconnection with exponential backoff
- ✅ Connection lifecycle events
- ✅ Managed orderbook state
- ✅ Type-safe API with zero-copy parsing
Market Data (Opt-in)
- 📊 Orderbook depth (default)
- 💱 Real-time trades
- 📈 Ticker updates
- 📉 OHLC/candlestick data
Analytics (Opt-in)
- 🎯 Orderbook imbalance detection
- 📊 Bullish/Bearish signal generation
- ✅ CRC32 checksum validation
- ⚡ SIMD-accelerated JSON parsing
Integration (Opt-in)
- 🤖 Telegram bot notifications
- 🐋 Whale detection alerts
- 💰 Price threshold alerts
- 🔐 Private account data (balances, orders, executions)
- 💸 WebSocket trading (place/cancel/amend orders)
Architecture
Kraky is built with:
- Tokio - Async runtime for efficient I/O
- Tokio-Tungstenite - WebSocket client
- Serde - Zero-copy JSON parsing
- Feature Flags - Modular compilation
- BTreeMap - Ordered orderbook storage (O(log n) operations)
Binary Size:
- Minimal (orderbook only): ~7.2 MB
- Full featured: ~8.5 MB
- Each data type adds only 40-50 KB
See docs.rs/kraky for detailed architecture documentation.
Testing
# Run all tests
# Results: 69 tests passing
# - 47 unit tests
# - 22 doctests
Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Ensure
cargo test --all-featurespasses - Submit a pull request
License
Licensed under the MIT License. See LICENSE for details.
Links
- Documentation: docs.rs/kraky
- Repository: github.com/SarpTekin/kraky
- Setup Guide: SETUP.md
- Examples: examples/
Built for the Kraken Forge Hackathon 🐙