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 utiliza a biblioteca websocket-client
para estabelecer e manter conexões WebSocket com o servidor do Quotex. A implementação principal está na classe WebsocketClient
.
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 oferece vários métodos para se inscrever em diferentes tipos de 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)
O sistema suporta os seguintes tipos de streams:
PyQuotex implementa um sistema robusto de reconexão automática:
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("Reconectado com sucesso!")
break
else:
print("Erro na reconexão.")
attempt += 1
check_websocket_if_connect = None
check_websocket_if_error = False
check_rejected_connection = False