PyQuotex

pyquotex is a Python library designed to easily integrate with the Quotex API, enabling automated trading operations. Fully open-source and licensed under MIT, the library provides features like order execution, balance checking, real-time market data collection, and more. Perfect for traders and developers looking to build efficient and customized solutions.

View the Project on GitHub cleitonleonel/pyquotex

Technical Documentation PyQuotex

1. Technical Aspects

1.1 Project Structure

The project follows a modular structure organized as follows:

πŸ“¦ pyquotex/
 ┣ πŸ“‚ docs/                    # Documentation
 ┣ πŸ“‚ examples/                # Usage examples
 ┃ ┣ πŸ“œ custom_config.py       # Custom configuration
 ┃ ┣ πŸ“œ monitoring_assets.py   # Asset monitoring
 ┃ ┣ πŸ“œ trade_bot.py          # Trading bot
 ┃ β”— πŸ“œ user_test.py          # User tests
 ┣ πŸ“‚ pyquotex/              # API Core
 ┃ ┣ πŸ“‚ network/              # Network modules (Authentication, Settings)
 ┃ ┃ ┣ πŸ“œ login.py
 ┃ ┃ ┣ πŸ“œ logout.py
 ┃ ┃ β”— πŸ“œ settings.py
 ┃ ┣ πŸ“‚ utils/                # Utilities
 ┃ ┣ πŸ“‚ ws/                   # WebSocket
 ┃ ┃ ┣ πŸ“‚ channels/          # WS channels
 ┃ ┃ β”— πŸ“‚ objects/           # WS objects
 ┃ ┣ πŸ“œ api.py               # Main API
 ┃ β”— πŸ“œ stable_api.py        # Stable API

1.2 API Architecture

The API is built on a client-server architecture using WebSocket as the main communication protocol. The main components are:

Core Components

WebSocket Channels

The API implements various WebSocket channels for different functionalities:

Data Processing

1.3 Session Management

The system implements sophisticated session handling including:

Authentication

async def authenticate(self):
    logger.info("Connecting User Account...")
    async with self.login as login:
        status, message = await login(
            self.username,
            self.password,
            self.user_data_dir
        )
    if status:
        self.state.SSID = self.session_data.get("token")
        self.is_logged = True
    return status, message

Session Persistence

Connection State

1.4 Security Considerations

Authentication and Authorization

Data Protection

# Unified SSL context for all network operations
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ssl_context.minimum_version = ssl.TLSVersion.TLSv1_2
ssl_context.maximum_version = ssl.TLSVersion.TLSv1_3
ssl_context.set_ciphers('ECDHE-ECDSA-AES128-GCM-SHA256:...')

Implemented Security Measures

  1. Exclusive use of TLS 1.2 and 1.3 with browser-like cipher suites
  2. SSL certificate verification with latest CA bundles
  3. Mitigation against JA3 fingerprinting by mimicking browser cipher order
  4. Full set of browser-like HTTP headers during WebSocket handshake
  5. Protection against man-in-the-middle attacks

Important Notes

  1. Rate Limiting: The API implements rate limits to prevent abuse:
    • Maximum reconnections
    • Delays between operations
    • Request limits per minute
  2. Error Handling: Robust error handling system:
    try:
        await self.connect()
    except Exception as e:
        logger.error(f"Connection error: {e}")
        await self.reconnect()
    
  3. Logging: Comprehensive logging system for debugging and monitoring:
    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s %(message)s'
    )
    

Usage Recommendations

  1. Configuration:
    • Use environment variables for credentials
    • Configure appropriate timeouts
    • Implement custom error handling
  2. Security:
    • Don’t store credentials in code
    • Keep dependencies updated
    • Use secure connections (SSL/TLS)
  3. Commercial Performance Optimizations:

Circular Buffers (Memory Management)

To prevent Memory Leaks during long-running execution, the API uses collections.deque with strict limits (maxlen). This ensures that real-time price history does not grow indefinitely.

Event-Driven Architecture

Technical indicator processing is now fully event-driven. The system only recalculates indicators when the candle_generated signal is received, drastically reducing CPU usage.

Persistent Connections

We use httpx.AsyncClient with connection pooling to speed up network requests and reduce overhead.