A simple Telegram-controlled cryptocurrency trading bot for the Kraken exchange, built with Rust for high performance and safety. The symbols_config.json file allows you to customize trading pairs, thresholds, and strategies. Please see the example file.
- Telegram Integration: Full control via Telegram bot commands
- Kraken Exchange: Direct integration with Kraken's REST API
- Real-time Trading: Execute trades and monitor positions
- Async Architecture: High-performance async/await implementation
- Error Handling: Robust error management and recovery
- Modular Design: Clean separation with reusable telegram-bot crate
- Environment Configuration: Secure credential management via
.envfiles
- Rust: Install via rustup
- Nightly Toolchain: Required for advanced formatting
rustup install nightly rustup component add rustfmt --toolchain nightly
- Telegram Bot: Create a bot via @BotFather
- Kraken Account: API credentials from Kraken
-
Clone the repository:
git clone <your-repo-url> cd kraken_bot
-
Set up environment variables:
cp .env.example .env # Edit .env with your actual credentials -
Configure your
.envfile:# Telegram Bot Configuration TELOXIDE_TOKEN=your_telegram_bot_token_here # Kraken API Configuration KRAKEN_API_KEY=your_kraken_api_key_here KRAKEN_SECRET_KEY=your_kraken_secret_key_here # Chat ID for notifications KRAKEN_BOT_CHAT_ID=your_chat_id_here # Optional: Logging level RUST_LOG=info
-
Build and run:
cargo build --release cargo run
kraken_bot/
├── src/
│ ├── main.rs # Application entry point
│ ├── kraken_pos.rs # Trading bot core logic & Kraken integration
│ ├── kraken_execute_strategy.rs # Trading strategy execution
│ └── kraken_execute_trade.rs # Trade execution utilities
├── Cargo.toml # Dependencies and metadata
├── rustfmt.toml # Rust formatting configuration
├── .env.example # Environment variables template
└── README.md # This file
This project uses nightly rustfmt with advanced formatting features:
# Format all code
cargo +nightly fmt
# Or use the convenience script
./format.sh# Debug build
cargo build
# Release build (optimized)
cargo build --release
# Run with logging
RUST_LOG=debug cargo runTradingBot: Main bot implementation with Kraken API integrationTelegramBotHandler: Generic Telegram bot handler fromtelegram-botcrateBotState: Application state management with thread-safe access- Strategy Execution: Modular trading strategy implementation
| Crate | Purpose |
|---|---|
telegram-bot |
Custom Telegram bot framework (local crate) |
teloxide |
Telegram Bot API bindings |
kraken-async-rs |
Async Kraken exchange API client |
tokio |
Async runtime |
serde |
Serialization/deserialization |
rust_decimal |
High-precision decimal arithmetic |
dotenvy |
Environment variable loading |
chrono |
Date and time handling |
- API Keys: Stored in
.envfile (never commit to git) - Environment Variables: Loaded securely at runtime
- Error Handling: Sensitive data excluded from error messages
- Input Validation: All user inputs validated and sanitized
The bot supports various commands through Telegram:
/start- Initialize the bot/status- Check bot status/positions- View current positions/execute- Execute trading strategy/stop- Stop the bot
| Variable | Description | Required |
|---|---|---|
TELOXIDE_TOKEN |
Telegram bot token from @BotFather | Yes |
KRAKEN_API_KEY |
Kraken API key | Yes |
KRAKEN_SECRET_KEY |
Kraken API secret | Yes |
KRAKEN_BOT_CHAT_ID |
Telegram chat ID for notifications | Yes |
RUST_LOG |
Logging level (debug/info/warn/error) | No |
- Log into your Kraken account
- Go to Settings → API
- Create a new API key with required permissions:
- Query funds
- Query open/closed orders
- Query ledger entries
- Create & cancel orders (for trading)
- Copy the API key and secret to your
.envfile
- Message @BotFather on Telegram
- Create a new bot with
/newbot - Copy the bot token to your
.envfile - Get your chat ID by messaging @userinfobot
The bot includes comprehensive error handling:
- Network Issues: Automatic retry with exponential backoff
- API Errors: Detailed error logging and user notification
- Invalid Commands: Graceful error responses
- State Recovery: Automatic state restoration after crashes
Configure logging levels via the RUST_LOG environment variable:
# Debug level (verbose)
RUST_LOG=debug cargo run
# Info level (default)
RUST_LOG=info cargo run
# Warn level (minimal)
RUST_LOG=warn cargo run- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Format code:
cargo +nightly fmt - Run tests:
cargo test - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This software is for educational and research purposes only. Trading cryptocurrencies involves substantial risk of loss and is not suitable for every investor. Past performance does not guarantee future results. Use at your own risk.
telegram-bot- Reusable Telegram bot framework crate- Kraken API Documentation
- Teloxide Documentation
If you encounter any issues or have questions:
- Check the existing Issues
- Create a new issue with detailed information
- Include relevant log output and configuration (sanitized)
Built with ❤️ and Rust 🦀