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.
PyQuotex uses the websockets (asynchronous) library to maintain high-performance connections with the Quotex server.
The core implementation is split between WebsocketClient and QuotexAPI.
The connection is kept alive through a Heartbeat system that sends a “tick” message every 5 seconds, ensuring the server doesn’t close the session due to inactivity.
from pyquotex.global_value import WebsocketStatus
# Heartbeat implemented in QuotexAPI._on_open
async def heartbeat():
while self.state.status == WebsocketStatus.CONNECTED:
try:
await self.websocket.send('42["tick"]')
except Exception:
break
await asyncio.sleep(5)
PyQuotex offers several methods to subscribe to different types of streams:
def start_candles_stream(self, asset, period=0):
self.api.current_asset = asset
self.api.subscribe_realtime_candle(asset, period)
self.api.follow_candle(asset)
async def start_realtime_sentiment(self, asset, period=0):
self.start_candles_stream(asset, period)
while True:
if self.api.realtime_sentiment.get(asset):
return self.api.realtime_sentiment[asset]
await asyncio.sleep(0.2)
async def start_realtime_price(self, asset, period=0):
self.start_candles_stream(asset, period)
while True:
if self.api.realtime_price.get(asset):
return self.api.realtime_price
await asyncio.sleep(0.2)
The system supports the following types of streams:
PyQuotex utilizes an advanced WebSocket architecture to ensure commercial-grade stability and performance.
The connection is monitored by a dedicated supervisor (_websocket_supervisor) that performs automatic reconnections
with Exponential Backoff. If the socket drops, the system re-authenticates and reopens the connection without manual
intervention.
# The Supervisor manages the connection lifecycle automatically
await client.connect()
To maximize processing speed, we implemented a hashmap-based dispatch system (O(1)). Instead of long if/elif chains,
the system directly invokes the modular handler responsible for the event, drastically reducing execution latency.