A Django-based custodial wallet service with Telegram authentication and a terminal UI interface.
All onchain operations in this project run on TON (The Open Network).
- Backend: Django REST API (
walletapp) - TUI: Textual-based terminal interface (
tui/) - Bot: Telegram bot for authentication (
bot/)
# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt# Run migrations (first time only)
python manage.py migrate
# Start Django server
python manage.py runserver 0.0.0.0:8000The API will be available at http://localhost:8000
source .venv/bin/activate
export TELEGRAM_BOT_TOKEN="your-bot-token"
export BACKEND_URL="http://localhost:8000"
python -m bot.telegram_botThe bot handles /start commands for Telegram Login Widget authentication.
source .venv/bin/activate
python -m tuiThe TUI will connect to http://localhost:8000 by default. To use a different URL:
python -m tui --url http://your-server:8000To bypass Telegram login with an existing session token:
python -m tui --url http://localhost:8000 --token <session_token>source .venv/bin/activate
# Run all tests
python manage.py test wallet.tests
python -m pytest tui/tests/ bot/tests/ -vHealth & Info:
GET /health- Health checkGET /bot/info- Get bot info (username, first_name, login URL)
Authentication:
POST /auth/telegram- Authenticate with Telegram user IDPOST /auth/telegram/widget- Telegram Login Widget verificationPOST /auth/pending- Create pending auth tokenGET /auth/pending/<token>- Check pending auth statusPOST /auth/complete- Complete pending auth (called by bot)GET /auth/session/<token>- Validate session
Wallet (requires auth):
GET /test/balance- Get wallet balance with PnLGET /test/address- Get deterministic test addressPOST /test/deposit- Deposit USDtPOST /test/withdraw- Withdraw USDtPOST /test/transfer- Transfer to another user
Trading (requires auth):
GET /test/assets- List all supported assetsGET /test/asset/<id>- Get asset detailGET /test/positions- Get open positionsPOST /test/buy- Place buy orderPOST /test/sell- Place sell orderGET /test/orders- Get order historyGET /test/order/<id>- Get specific orderGET /test/prices- Get all asset prices
AI Agents (requires auth):
GET /test/agents- Get AI agents infoPOST /test/agents/select- Select active agentsGET /test/agents/allocation- Get agent allocationPOST /test/agents/allocation- Update allocationGET /test/agents/reasoning?asset_id=X- Get agent reasoning
Advisors (requires auth):
GET /advisors/list- List configured adviser personasGET /advisors/preferences- Get selected advisers + risk profilePOST /advisors/preferences- Update selected advisers + risk profilePOST /advisors/start- Get initial buy plan for deposit amountGET /advisors/analysis- Get asset analysisPOST /advisors/recommendations- Get portfolio/cash recommendations
Portfolio (requires auth):
GET /test/portfolio- Get portfolio summaryPOST /test/rebalance- Get rebalancing actionsGET /test/risk- Get risk assessment
Onchain (TON, requires auth):
POST /onchain/wallet/create- Create onchain wallet for userPOST /onchain/deploy- Deploy onchain wallet contractGET /onchain/address- Get user TON wallet addressGET /onchain/balance- Get onchain balances and positionsPOST /onchain/withdraw- Withdraw funds onchainPOST /onchain/buy- Execute buy order onchainPOST /onchain/sell- Execute sell order onchainGET /onchain/orders- List onchain ordersGET /onchain/order/<id>- Get onchain order details
- USDt (stablecoin)
- TSLAx, HOODx, AMZNx, NVDAx, COINx, GOOGLx, AAPLx, MSTRx (stock derivatives)
- Buy - Long-term growth agent
- Cover - Risk management agent
- Sell - Profit-taking agent
- Short - Momentum trading agent
- Hold - Balance-focused agent
Adviser personas are configured via code and exposed by /advisors/list. Per-user adviser selection and risk profile are stored in AgentPreference.
Adviser recommendations are converted into UI marks:
buy,buy_moreβ π’ Buysellβ π΄ Sellholdβ π‘ Hold
- Click "Login with Telegram" button
- TUI creates a pending auth token via backend
- A browser opens to Telegram bot with login URL
- User approves login in Telegram
- Bot notifies backend which stores the auth
- TUI polls backend for auth completion
- Dashboard displayed!
The main screen shows:
- Wallet balance (Cash, Equity, Total, PnL)
- Open positions table
- Available assets table
- Asset detail panel
| Key | Action |
|---|---|
q |
Quit |
r |
Refresh data |
b |
Buy selected asset |
s |
Sell selected asset |
d |
Deposit funds |
w |
Withdraw funds |
t |
Transfer funds |
enter |
Generate analytics for selected asset |
o |
View orders |
p |
View portfolio |
escape |
Back (on sub-screens) |
- π’ Buy - Green
- π΄ Sell - Red
- π‘ Hold - Yellow
- π΅ Cover - Cyan
- π£ Short - Magenta
dbablo/
βββ wallet/ # Django wallet app
β βββ views/ # API views (modular)
β β βββ auth.py # Authentication views
β β βββ bot.py # Bot info endpoint
β β βββ wallet.py # Balance, deposit, withdraw, transfer
β β βββ trading.py # Assets, positions, orders
β β βββ agents.py # AI agents
β β βββ portfolio.py # Portfolio, rebalance, risk
β βββ services/ # Business logic services
β β βββ authentication.py
β β βββ auth_sessions.py
β β βββ telegram_auth.py
β β βββ wallet_summary.py
β βββ models.py # Database models
β βββ constants.py # Constants and prices
β βββ tests/ # API tests
βββ tui/ # Terminal UI
β βββ screens/ # Textual screens
β β βββ login.py # Login screen
β β βββ dashboard.py # Main dashboard
β β βββ orders.py # Order history
β β βββ portfolio.py # Portfolio view
β β βββ rebalance.py # Rebalance recommendations
β βββ modals/ # Modal dialogs
β β βββ order.py # Buy/sell order
β β βββ transfer.py # Transfer funds
β β βββ deposit_withdraw.py
β β βββ agent_select.py
β βββ api.py # API client
β βββ app.py # Main app
β βββ session_store.py # Token persistence
βββ bot/ # Telegram bot
β βββ telegram_bot.py # Bot implementation
βββ config/ # Django settings
βββ README.md
- Create service in
wallet/services/ - Create view in
wallet/views/ - Add URL route in
wallet/urls.py - Add API method in
tui/api.py - Add tests
- Strict typing everywhere
- Class-based design
- Loguru for structured logging
- Max 400 lines per file
| Variable | Description | Default |
|---|---|---|
SECRET_KEY |
Django secret key | unsafe-dev-secret-key |
DEBUG |
Debug mode | False |
ALLOWED_HOSTS |
Allowed hosts | * |
TELEGRAM_BOT_TOKEN |
Bot token for auth | (required for bot) |
BACKEND_URL |
Backend URL for bot | http://localhost:8000 |
LOG_LEVEL |
Log level for loguru | INFO |
# Build
docker build -t dbablo:latest .
# Run
docker run --env-file .env -p 8000:8000 dbablo:latest