Skip to content

feat: Telegram bot for deploying on-chain trading agents#17

Open
JaeLeex wants to merge 1 commit intomainfrom
feat/telegram-bot
Open

feat: Telegram bot for deploying on-chain trading agents#17
JaeLeex wants to merge 1 commit intomainfrom
feat/telegram-bot

Conversation

@JaeLeex
Copy link
Copy Markdown
Contributor

@JaeLeex JaeLeex commented Mar 28, 2026

Summary

Adds a Telegram-native interface for deploying, monitoring, and controlling autonomous trading agents on Hyperliquid — like the Telegram wallet bot craze (Maestro, Banana Gun) but for agents instead of swaps.

  • New module tg_bot/ (12 files, 1787 lines) — full Telegram bot with conversation flows, inline keyboards, and real-time notifications
  • Zero modifications to existing trading logic — wraps existing TradingEngine, strategies, keystore, and HL adapter
  • All 1292 existing tests pass unchanged

User Flow

  1. /start → create or import wallet (encrypted keystore, private key message auto-deleted)
  2. /deploy → inline keyboard: pick from 18 strategies → instrument → risk preset (conservative/default/aggressive) → confirm
  3. Agent runs in background thread, pushes fills + PnL + risk alerts to chat (throttled)
  4. /status /pause /resume /stop /balance → full lifecycle control
  5. /apex → APEX multi-strategy orchestration mode

Architecture

  • NotifyingEngine subclasses TradingEngine, pushes events to asyncio.Queue
  • EngineBridge manages engine thread lifecycle from async Telegram context
  • Notifier reads queue, sends throttled messages (fills always-send, PnL every 5min)
  • Single-user auth with auto-detect on first /start, mainnet double-confirmation gate

Usage

pip install -e ".[telegram]"
export TELEGRAM_BOT_TOKEN=<from-botfather>
hl telegram start          # testnet
hl telegram start --mainnet

Railway: set RUN_MODE=telegram + TELEGRAM_BOT_TOKEN in env vars.

Files Changed

  • tg_bot/ — bot, auth, config, engine bridge, notifier, formatters, handlers (start, strategy, control, apex)
  • cli/commands/telegram_cmd.pyhl telegram start CLI command
  • cli/main.py — register telegram subcommand (2 lines)
  • pyproject.toml — add telegram optional dep group, include tg_bot* package
  • scripts/entrypoint.py — add telegram mode to Railway entrypoint
  • Dockerfile — install telegram dep

Test plan

  • pip install -e ".[telegram]" succeeds
  • hl telegram start exits with clear error if TELEGRAM_BOT_TOKEN not set
  • Set token, run bot, send /start in Telegram → wallet created
  • /deploy → strategy keyboard → instrument → preset → confirm → agent runs
  • Receive fill notifications in Telegram chat
  • /status shows live position + PnL
  • /pause/resume works
  • /stop → graceful shutdown with summary card
  • /apex starts APEX orchestrator, /apex_stop stops it
  • All 1292 existing tests still pass (pytest tests/ -x -q)
  • Railway deploy with RUN_MODE=telegram boots correctly

Telegram-native interface for deploying, monitoring, and controlling
autonomous trading agents on Hyperliquid — like wallet bots but for agents.

New module: tg_bot/ (12 files)
- /start: wallet create/import with encrypted keystore
- /deploy: strategy selection keyboard (18 strategies), instrument picker,
  risk presets (conservative/default/aggressive), mainnet double-confirm
- /status /pause /resume /stop /balance: agent lifecycle control
- /apex: multi-strategy APEX orchestration mode
- NotifyingEngine: TradingEngine subclass pushing fills, PnL, risk alerts
  to Telegram via async queue with throttling
- EngineBridge: thread-safe bridge (async bot <-> blocking engine thread)

CLI: `hl telegram start [--mainnet] [--dry-run]`
Deploy: RUN_MODE=telegram in Railway, Dockerfile installs telegram dep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant