A high-performance cryptocurrency exchange monitoring system that supports real-time price tracking across multiple exchanges.
- Multi-Exchange Support: Simultaneously monitor multiple cryptocurrency exchanges
- Real-time Price Monitoring: WebSocket-based real-time price updates
- Market Type Support: Support for spot, futures, and margin markets
- High Precision: Advanced price precision handling following CCXT standards
- Market Parameters: Comprehensive market information including:
- Minimum purchase amount
- Leverage range
- Trading fees (maker/taker)
- Price and amount precision
- Error Handling: Robust error handling and automatic reconnection
- Cross-Platform: Optimized for both Windows and Linux systems
- Performance Optimization: Utilizes uvloop on Linux and optimized event loops on Windows
- Data Validation: Comprehensive input validation and error checking
- Extensible Architecture: Easy to add new exchanges and features
Full documentation is available at hedging-quantification.readthedocs.io.
- Python 3.12.8
- ccxt
- asyncio
- See requirements.txt for full list
- Clone the repository:
git clone https://github.com/maodou7/Hedging_quantification.git
cd Hedging_quantification
- Create and activate environment:
Option 1 - Using Anaconda (Recommended):
# List all environments
conda env list
# Create a new environment with Python 3.12.8
conda create -n hedging python=3.12.8
# Activate the environment
conda activate hedging
# Deactivate the environment when done
conda deactivate
# Remove environment if needed
conda remove -n hedging --all
Option 2 - Using venv:
For Linux/macOS:
python -m venv venv
source venv/bin/activate
For Windows:
python -m venv venv
.\venv\Scripts\activate
- Install dependencies:
For Linux/macOS:
# Install system dependencies
sudo apt-get update
sudo apt-get install python3-dev build-essential
# Install Python dependencies
pip install --upgrade pip
pip install -r requirements.txt
# Install uvloop for better performance (Linux only)
pip install uvloop
For Windows:
pip install --upgrade pip
pip install -r requirements.txt
Edit Config/exchange_config.py
to configure:
- Exchanges to monitor
- Market types (spot/futures/margin)
- Quote currencies
- Market structure settings
Example configuration:
EXCHANGES = ['binance', 'bybit', 'okx']
MARKET_TYPES = {
'spot': True,
'future': True,
'margin': False
}
QUOTE_CURRENCIES = ['USDT', 'BTC']
Run the main program:
python main.py
The program will:
- Initialize exchange connections
- Find common trading pairs
- Start real-time price monitoring
- Output formatted JSON price data
Example output:
{
"exchange": "binance",
"type": "spot",
"symbol": "BTC/USDT",
"quote": "USDT",
"price": "45123.45",
"min_cost": "5.0",
"leverage": "1-100",
"fees": {
"taker": "0.001",
"maker": "0.001"
},
"precision": {
"price": 2,
"amount": 6
}
}
main.py
: Main program entry pointExchangeModules/
:exchange_instance.py
: Exchange connection managementmonitor_manager.py
: Price monitoring systemmarket_processor.py
: Market data processingcommon_symbols_finder.py
: Common trading pair detectionmarket_structure_fetcher.py
: Market structure handling
- Automatic event loop optimization:
- Linux: Uses
uvloop
for maximum performance (up to 2-4x faster than default) - Windows: Uses
WindowsSelectorEventLoopPolicy
for optimal performance
- Linux: Uses
- Efficient WebSocket connections with automatic reconnection
- Optimized data structures for quick lookups
- Memory-efficient data processing
- Concurrent exchange processing
- Connection pooling for REST API calls
- Real-time performance metrics
- Detailed logging with different levels
- WebSocket connection status monitoring
- Memory usage tracking
- Response time measurements
- Error rate monitoring
- Always use the virtual environment
- Regularly update dependencies
- Monitor system resources
- Back up configuration files
- Check logs regularly
- Keep API keys secure
- Use appropriate timeouts for API calls
Run the test suite:
pytest tests/
For coverage report:
coverage run -m pytest tests/
coverage report
This project uses Black for code formatting and follows PEP 8 guidelines. To format your code:
black .
We welcome contributions! Please see our Contributing Guidelines for details.
For security issues, please see our Security Policy.
See CHANGELOG.md for a list of changes.
This project is licensed under the MIT License - see the LICENSE file for details.