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 websocket-client
library to establish and maintain WebSocket connections with the Quotex server. The main implementation is in the WebsocketClient
class.
self.wss = websocket.WebSocketApp(
self.api.wss_url,
on_message=self.on_message,
on_error=self.on_error,
on_close=self.on_close,
on_open=self.on_open,
on_ping=self.on_ping,
on_pong=self.on_pong,
header=self.headers
)
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 implements a robust automatic reconnection system:
async def connect(attempts=5):
check, reason = await client.connect()
if not check:
attempt = 0
while attempt <= attempts:
if not await client.check_connect():
check, reason = await client.connect()
if check:
print("Successfully reconnected!")
break
else:
print("Reconnection error.")
attempt += 1
check_websocket_if_connect = None
check_websocket_if_error = False
check_rejected_connection = False