A comprehensive Telegram bot for trading crypto perpetual futures on the Aster Finance exchange. This bot provides a user-friendly interface for managing trades, positions, and account balances with advanced features like dynamic leverage detection and symbol validation.
- Features
- Prerequisites
- Installation
- Configuration
- Usage Guide
- API Reference
- Architecture
- Security
- Deployment
- Contributing
- License
- Automatic User Onboarding: Each user gets a unique BEP-20 wallet and Aster API keys
- Session Management: Secure, isolated trading environments for all users
- In-Memory Storage: User data stored in memory during bot session
- Interactive Trading Interface: Clean, button-based flow for all trading operations
- Dynamic Leverage Detection: Automatically fetches and validates leverage options for each asset
- Symbol Validation: Real-time testing of trading symbols to ensure compatibility
- Smart Error Handling: Comprehensive error messages and user guidance
- Intuitive Menu System: Easy-to-use button-based navigation
- Real-time Market Data: Live price feeds and market information
- Position Management: Complete position tracking and management
- Balance Monitoring: Real-time account balance updates
- Symbol Support Testing: Automatic validation of 100+ trading symbols
- Leverage Optimization: Smart leverage detection and adjustment
- Error Recovery: Robust error handling and user guidance
- Performance Optimization: Fast execution with minimal latency
Before you begin, ensure you have the following installed:
- Node.js (v18.x or later)
- npm (comes with Node.js)
- Git (for cloning the repository)
- Telegram Account (for bot interaction)
git clone <your-repository-url>
cd asterdexbotnpm installCreate a .env file in the project root:
touch .envAdd your configuration:
# Telegram Bot Configuration
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here-
Create a Bot:
- Open Telegram and search for
@BotFather - Send
/newbotand follow the prompts - Copy the bot token provided
- Open Telegram and search for
-
Add Token to Environment:
TELEGRAM_BOT_TOKEN=1234567890:ABCdefGHIjklMNOpqrsTUVwxyz
npm run devnpm startdocker build -t asterdexbot .
docker run -d --name asterdexbot --env-file .env asterdexbot- Start the Bot: Send
/startto initialize your account - Automatic Setup: The bot creates your wallet and API keys
- Begin Trading: Use the menu buttons or commands to start trading
/start- Initialize your account and create wallet/help- Show available commands and features/menu- Display the main trading menu
/long- Open a long position/short- Open a short position/close- Close existing positions/positions- View all open positions
/balance- Check your account balance/export- Export your wallet private key/transfer- Transfer funds between accounts
/markets- Browse available trading markets/price <symbol>- Get current price for a symbol
- Select Market: Choose from 100+ available trading pairs
- Set Parameters: Enter position size and leverage
- Confirm Trade: Review and confirm your trade
- Monitor Position: Track your position in real-time
- View Positions: Use
/positionsto see open trades - Select Position: Choose which position to close
- Confirm Close: Review and confirm the closure
The bot features an intuitive menu system:
π Main Menu
βββ π° Balance
βββ π Positions
βββ π Markets
βββ π Transfer
βββ π Export Key
βββ β Help
Initiates the trading flow for a specific symbol and side.
Parameters:
symbol(string): Trading pair symbol (e.g., 'BTCUSDT')side(string): 'long' or 'short'
Places a trading order with the specified parameters.
Parameters:
orderData(object): Order configurationsymbol(string): Trading pairside(string): 'long' or 'short'size(number): Position size in USDTleverage(number): Leverage multiplier
src/
βββ index.js # Main bot logic and command handlers
βββ asterdex.js # AsterDex API integration
βββ bnb-wallet.js # BEP-20 wallet utilities
- Handles all Telegram interactions
- Manages user sessions and state
- Coordinates trading operations
- Interfaces with AsterDex trading API
- Handles authentication and requests
- Manages order placement and position tracking
- Creates and manages BEP-20 wallets
- Handles message signing for API authentication
- Manages private key operations
- Session Isolation: Each user's data is completely isolated
- API Key Security: API keys are generated per user and stored in memory
- In-Memory Storage: User data stored securely in memory during bot session
- Environment Variables: All sensitive data stored in environment variables
- Input Validation: All user inputs are validated and sanitized
- Error Handling: Comprehensive error handling prevents data leaks
- Rate Limiting: Built-in rate limiting prevents abuse
- Data Persistence: Consider implementing database storage for production
- Key Management: Consider using a key management service
- Monitoring: Implement comprehensive logging and monitoring
- Session Management: Implement persistent session storage
- User Activity: Track user engagement and trading patterns
- Error Tracking: Comprehensive error logging and analysis
- Performance Metrics: Response times and system performance
- Symbol Support: Track which symbols are supported and their leverage limits
We welcome contributions! Please follow these steps:
- Fork the Repository: Create your own fork
- Create Feature Branch:
git checkout -b feature/amazing-feature - Commit Changes:
git commit -m 'Add amazing feature' - Push to Branch:
git push origin feature/amazing-feature - Open Pull Request: Submit your changes for review
- Code Style: Follow existing code patterns and conventions
- Testing: Add tests for new features
- Documentation: Update documentation for new features
- Security: Ensure all changes maintain security standards
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: Check this README and inline code comments
- Issues: Report bugs and request features via GitHub Issues
- Discussions: Join community discussions for questions and ideas
- Check if the bot token is correct
- Verify the bot is running and connected
- Check for error messages in the console
- Ensure sufficient balance for trades
- Check if the symbol is supported
- Verify leverage settings are valid
- Check if user session exists
- Verify API keys are properly generated
- Restart bot if sessions are corrupted
- Added comprehensive symbol validation
- Enhanced user interface with menu system
- Improved error handling and user guidance
- Added dynamic leverage detection
- Implemented interactive trading flow
- Initial release with basic trading functionality
- Multi-user architecture
- Basic position management
- Wallet creation and management
- Developer: [Your Name]
- Email: [your-email@example.com]
- GitHub: [your-github-username]
- Telegram: [@your-telegram-username]