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
 ┣ πŸ“‚ quotexapi/              # API Core
 ┃ ┣ πŸ“‚ http/                 # HTTP modules
 ┃ ┃ ┣ πŸ“œ 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):
    status, message = await self.login(
        self.username,
        self.password,
        self.user_data_dir
    )
    if status:
        global_value.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

ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ssl_context.options |= ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1 | ssl.OP_NO_TLSv1_2
ssl_context.minimum_version = ssl.TLSVersion.TLSv1_3

Implemented Security Measures

  1. Exclusive use of TLS 1.3
  2. SSL certificate verification
  3. Protection against man-in-the-middle attacks
  4. Rate limiting to prevent API abuse
  5. Input data validation

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. Performance:
    • Implement caching when possible
    • Handle reconnections efficiently
    • Monitor resource usage