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.
Esta documentación cubre los principales casos de uso y ejemplos de implementación de la biblioteca PyQuotex para interactuar con la plataforma Quotex.
from quotexapi.stable_api import Quotex
# Inicializar el cliente
client = Quotex(
email="tu@email.com",
password="tu_password",
lang="es" # Idioma por defecto
)
# Conectar al servidor
async def conectar():
check_connect, message = await client.connect()
if check_connect:
print("Conectado exitosamente")
balance = await client.get_balance()
print(f"Balance actual: {balance}")
client.close()
async def obtener_perfil():
check_connect, message = await client.connect()
if check_connect:
profile = await client.get_profile()
print(f"""
Usuario: {profile.nick_name}
Balance Demo: {profile.demo_balance}
Balance Real: {profile.live_balance}
País: {profile.country_name}
""")
client.close()
async def operar():
check_connect, message = await client.connect()
if check_connect:
# Parámetros de la operación
amount = 50 # Cantidad
asset = "EURUSD_otc" # Par de divisas
direction = "call" # call=subida, put=bajada
duration = 60 # Duración en segundos
# Verificar si el activo está disponible
asset_name, asset_data = await client.get_available_asset(asset, force_open=True)
if asset_data[2]: # Verificar si el mercado está abierto
status, buy_info = await client.buy(amount, asset_name, direction, duration)
if status:
# Esperar resultado
win = await client.check_win(buy_info["id"])
profit = client.get_profit()
print(f"Resultado: {'Ganancia' if win else 'Pérdida'} de {profit}")
client.close()
async def monitorear_precios():
check_connect, message = await client.connect()
if check_connect:
asset = "EURUSD_otc"
# Iniciar stream de precios
await client.start_realtime_price(asset, 60)
# Monitorear continuamente
while True:
precios = await client.get_realtime_price(asset)
if precios:
ultimo_precio = precios[-1]
print(f"Tiempo: {ultimo_precio['time']} Precio: {ultimo_precio['price']}")
await asyncio.sleep(1)
async def conectar_con_reintentos(max_intentos=5):
intentos = 0
while intentos < max_intentos:
try:
check_connect, message = await client.connect()
if check_connect:
return True
intentos += 1
print(f"Reintentando conexión ({intentos}/{max_intentos})")
await asyncio.sleep(5)
except Exception as e:
print(f"Error de conexión: {e}")
intentos += 1
return False
class TradingBot:
def __init__(self, email, password):
self.client = Quotex(email=email, password=password)
self.connected = False
async def iniciar(self):
self.connected = await self.conectar_con_reintentos()
if self.connected:
await self.configurar_cuenta()
async def configurar_cuenta(self):
# Configurar modo demo por defecto
self.client.set_account_mode("PRACTICE")
async def cerrar(self):
self.client.close()
self.connected = False
import asyncio
from quotexapi.stable_api import Quotex
class SimpleBot:
def __init__(self):
self.client = Quotex(
email="tu@email.com",
password="tu_password"
)
self.running = False
async def iniciar(self):
check_connect, _ = await self.client.connect()
if check_connect:
self.running = True
await self.trading_loop()
async def trading_loop(self):
while self.running:
try:
# Obtener datos de mercado
sentiment = await self.client.get_realtime_sentiment("EURUSD_otc")
if sentiment.get("sentiment", {}).get("buy", 0) > 70:
# Ejecutar operación si el sentimiento es muy alcista
await self.ejecutar_operacion("EURUSD_otc", "call", 50, 60)
await asyncio.sleep(60) # Esperar 1 minuto
except Exception as e:
print(f"Error en el loop de trading: {e}")
await asyncio.sleep(5)
async def ejecutar_operacion(self, asset, direction, amount, duration):
status, buy_info = await self.client.buy(amount, asset, direction, duration)
if status:
resultado = await self.client.check_win(buy_info["id"])
print(f"Operación {'ganadora' if resultado else 'perdedora'}")
async def detener(self):
self.running = False
self.client.close()
# Uso del bot
async def main():
bot = SimpleBot()
await bot.iniciar()
if __name__ == "__main__":
asyncio.run(main())
import asyncio
import datetime
async def monitor_mercado():
client = Quotex(
email="tu@email.com",
password="tu_password"
)
check_connect, _ = await client.connect()
if check_connect:
activos = ["EURUSD", "GBPUSD", "USDJPY"]
while True:
for activo in activos:
try:
# Obtener datos del activo
precio = await client.get_realtime_price(activo)
sentiment = await client.get_realtime_sentiment(activo)
# Guardar o mostrar información
timestamp = datetime.datetime.now()
print(f"""
{timestamp} - {activo}:
Precio: {precio[-1]['price'] if precio else 'N/A'}
Sentimiento Compra: {sentiment.get('sentiment', {}).get('buy', 'N/A')}%
Sentimiento Venta: {sentiment.get('sentiment', {}).get('sell', 'N/A')}%
""")
except Exception as e:
print(f"Error monitoreando {activo}: {e}")
await asyncio.sleep(5) # Actualizar cada 5 segundos
if __name__ == "__main__":
asyncio.run(monitor_mercado())