This project is used to monitor position changes and asset status of multiple cryptocurrency exchanges including Binance, Bybit, and Gate.io. The system supports both main accounts and sub-accounts, with notifications through Feishu or Telegram. The system monitors account position changes in real-time, sends immediate notifications for opening and closing positions, and sends daily account total asset reports at fixed times.
- Multi-Exchange Support: Supports Binance, Bybit, and Gate.io exchanges
- Multi-Account Monitoring: Supports simultaneous monitoring of main accounts and sub-accounts
- Real-time Position Monitoring: Monitors futures account position changes in real-time
- Automatic Position Detection: Automatically identifies opening and closing positions
- Daily Scheduled Reports: Sends daily account total asset reports at fixed times
- Report Storage: Automatically stores daily reports locally
- Multiple Notification Channels: Supports Feishu and Telegram notifications
- Telegram Interactive Features: Supports Telegram query functionality and command interactions
- Customizable Monitoring: Configurable monitoring intervals and report times
- Error Handling: Automatic retry and error notifications
- Position Duration Statistics: Tracks and displays position holding duration
- Profit/Loss Calculation: Calculates and displays profit/loss and return rates
- Sorted Position Display: Displays positions sorted by profit/loss
- Multi-Account Asset Summary: Provides comprehensive asset statistics across all accounts
- Timezone Support: All times displayed in Eastern Time (ET) with automatic DST conversion
- Main account and sub-account support
- Real-time position monitoring
- Comprehensive balance and PnL tracking
- Main account and sub-account support
- Position change detection
- Asset balance monitoring
- Main account and sub-account support
- Swap contract monitoring
- Real-time position tracking
-
New Position Notifications:
- Account type (Main Account/Sub Account)
- Currency and trading pair
- Position direction (Long/Short)
- Opening price
- Position size
- Margin used
- Opening time (Eastern Time)
-
Closing Position Notifications:
- Account type (Main Account/Sub Account)
- Currency and trading pair
- Position direction
- Opening and closing prices
- Position size
- Profit/loss amount and return rate
- Position duration (days/hours/minutes)
- Closing time (Eastern Time)
- Account Overview:
- Total assets for each account (USDT/USDC)
- Portfolio total assets
- Available balance for each account
- Margin occupied for each account
- Unrealized PnL for each account
- Position Details (sorted by account and PnL):
- Account type
- Trading pair
- Position direction
- Unrealized PnL
- Return rate percentage
- Python 3.8+
- ccxt >= 2.0.0
- requests >= 2.26.0
- schedule >= 1.1.0
- python-dotenv >= 0.19.0
- pytz >= 2021.1
- python-telegram-bot==20.8
If deploying on a server:
# Download miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
# Add execution permissions
chmod +x Miniconda3-latest-Linux-x86_64.sh
# Install miniconda
./Miniconda3-latest-Linux-x86_64.sh
# Update bashrc
source ~/.bashrc
# Install screen (if not installed)
yum install screen -y
# Create screen session
screen -S exchange_monitor
# Exit screen session
# ctrl + a + d
# Reconnect session
screen -r exchange_monitor
- Clone project locally
- Create virtual environment
conda create -n exchange_monitor
conda activate exchange_monitor
conda install pip
# View environments
# conda env list
# Exit environment
# conda deactivate
# Remove environment
# conda env remove -n exchange_monitor
- Install dependencies:
pip install -r requirements.txt
- Configure environment variables:
- Copy
env.example
to.env
- Fill in the following configurations:
- Copy
# Binance API Configuration
BINANCE_API_KEY=your_binance_main_api_key
BINANCE_API_SECRET=your_binance_main_api_secret
SUB_ACCOUNT_API_KEY=your_binance_sub_api_key
SUB_ACCOUNT_API_SECRET=your_binance_sub_api_secret
# Bybit API Configuration
BYBIT_API_KEY=your_bybit_main_api_key
BYBIT_API_SECRET=your_bybit_main_api_secret
BYBIT_SUB_API_KEY=your_bybit_sub_api_key
BYBIT_SUB_API_SECRET=your_bybit_sub_api_secret
# Gate.io API Configuration
GATEIO_API_KEY=your_gateio_main_api_key
GATEIO_API_SECRET=your_gateio_main_api_secret
GATEIO_SUB_API_KEY=your_gateio_sub_api_key
GATEIO_SUB_API_SECRET=your_gateio_sub_api_secret
# Enable/disable accounts (true/false)
ENABLE_BINANCE_MAIN=true
ENABLE_BINANCE_SUB=true
ENABLE_BYBIT_MAIN=true
ENABLE_BYBIT_SUB=false
ENABLE_GATEIO_MAIN=true
ENABLE_GATEIO_SUB=false
# Notification settings
NOTIFICATION_TYPE=TELEGRAM # or FEISHU
NOTIFY_INTERVAL=30 # monitoring interval in seconds
DAILY_REPORT_TIME=09:00 # daily report time (HH:MM)
# Feishu configuration
FEISHU_WEBHOOK_URL=your_feishu_webhook_url
# Telegram configuration
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
TELEGRAM_CHAT_ID=your_telegram_chat_id
- Clone project locally
- Configure environment variables:
- Copy
env.example
to.env
and fill in the configurations (same as direct deployment above)
- Copy
- Build and start containers using docker-compose:
# Build and start in background
docker-compose up -d
# View logs
docker-compose logs -f
# Stop service
docker-compose down
# Restart service
docker-compose restart
- After ensuring correct configuration, run the main program:
python main.py
- After program startup:
- Immediately sends an account report
- Monitors position changes according to set interval
- Sends daily report at specified time
The system supports multiple notification channels:
- Send notifications through Feishu bot Webhook
- Support rich text format
- Real-time position change notifications
- Daily account reports
- Send notifications through Telegram Bot
- Support real-time query functionality
- Support command interactions
- Support message formatting with buttons
- Interactive account overview and position queries
Configuration method:
-
Users need to configure in .env file:
- TELEGRAM_BOT_TOKEN: Bot token obtained from @BotFather
- TELEGRAM_CHAT_ID: Target chat ID
- NOTIFICATION_TYPE: Choose 'FEISHU' or 'TELEGRAM'
-
When configured as TELEGRAM:
- All notifications will be sent through Telegram bot
- Interactive buttons for account queries
- Command-based interactions for real-time data
- Binance: Full futures trading support with comprehensive position tracking
- Bybit: Complete position monitoring with balance and PnL tracking
- Gate.io: Swap contract monitoring with real-time position updates
- All time displays use Eastern Time (ET)
- Automatic daylight saving time conversion
- Automatic retry for API call failures
- Automatic reconnection for network exceptions
- Critical error logging
- Real-time notification for exceptions
- Scheduler exception auto-recovery
- Use ccxt library to ensure API call rate limits
- Reasonable monitoring interval settings
- Efficient data structures for storing historical positions
- Multi-account concurrent monitoring optimization
- Automatic system connection status detection
- Immediate notification on disconnection
- Automatic reconnection mechanism
- Recovery notification after successful reconnection
- Warning for multiple reconnection failures
- Configurable reconnection interval and maximum retry attempts
- Daily reports automatically saved to local directory
- Historical report access
- Structured report format for easy analysis
├── main.py # Main application entry point
├── config.py # Configuration management
├── scheduler.py # Task scheduling system
├── binance_client.py # Binance exchange client
├── bybit_client.py # Bybit exchange client
├── gateio_client.py # Gate.io exchange client
├── services/
│ ├── feishu_service.py # Feishu notification service
│ └── telegram_service.py # Telegram notification service
├── 每日报告/ # Daily reports storage
├── requirements.txt # Python dependencies
├── docker-compose.yml # Docker deployment configuration
├── Dockerfile # Docker image definition
└── README files # Documentation
- Support more sub-account monitoring
- Add chart display functionality
- Support custom notification templates
- Add account portfolio analysis functionality
- Add more notification channels (like WeCom, Discord, etc.)
- Web-based management interface
- Enhanced error reporting and monitoring
- Add unit tests
- Optimize error retry mechanism
- Add data persistence storage
- Optimize multi-account concurrent monitoring
- Add performance metrics and monitoring
- Implement rate limiting and API quota management
MIT License