Rust-based Telegram bot for automated spot-futures hedging on cryptocurrency exchanges (Bybit, optionally Bitget).
- Integration with Bybit API (and Bitget in later iterations)
- Secure configuration from file or environment variables
- Local all-in-one SQLite database (no external DB server)
- Commands via Telegram:
/status— check bot and API connection status/hedge <sum> <symbol> <volatility>%— execute hedging strategy/unhedge <sum> <symbol>— execute unhedging (reverse) strategy/stats 30//stats 180— average funding rate over last 30/180 days/cancel— cancel ongoing operation
- Modular architecture:
exchangemodule withExchangetrait for API operationshedgermodule with core hedging/unhedging logicnotifiermodule for Telegram command parsing and notificationsstoragemodule for SQLite (viasqlx) to persist logs, orders, sessionsutilsfor helper functions (rounding, fee calculations)loggersetup viatracingtelegrammodule to run the bot
- Robust handling of limit orders: automatic cancellation and repositioning if unfilled
- Real-time logs and updates in Telegram
- Rust toolchain (Rust 1.75+ or nightly)
cargobuild tool- SQLite3 installed
- Telegram bot token
- API key and secret from Bybit (and Bitget if used)
Bot reads settings from:
- File:
Config.toml(by default copied fromConfig.toml.example) - Env var:
HEDGER_CONFIGto override file path - Environment variables prefixed with
HEDGER__, e.g.HEDGER__TELEGRAM_TOKEN
bybit_api_key = "YOUR_BYBIT_API_KEY"
bybit_api_secret = "YOUR_BYBIT_API_SECRET"
sqlite_path = "data/hedgehog.db"
telegram_token = "YOUR_TELEGRAM_BOT_TOKEN"
default_volatility = 0.6 # 60%
offset_points = 10 # price offset for limit orders- Clone repository
git clone https://github.com/your-repo/Hedgehog.git cd Hedgehog
2. **Configure**
- Copy `Config.toml.example` to `Config.toml` and fill values, or
- Set `HEDGER_CONFIG` or individual `HEDGER__*` environment variables
3. **Migrate database**
```bash
make migrate DB_PATH=data/hedgehog.db
- Build
make build
5. **Run**
```bash
make run
Bot will print Bybit API OK on successful startup.
Open Telegram and send commands:
| Command | Description |
|---|---|
/status |
Check bot & API status |
/hedge 1000 USDT MNT 60 |
Hedge 1000 USDT on MNT with 60% volatility |
/unhedge 500 USDT MNT |
Reverse hedge for 500 USDT on MNT |
/stats 30 |
Avg funding rate last 30 days |
/cancel |
Cancel ongoing operation |