Before you check a trade result, before you fetch candles, before anything else: you need to connect and log in to IQ Option. And that is exactly where most Python projects die. This honest guide shows you how to use the unofficial iqoptionapi library to connect, handle two-factor authentication, switch between the demo and real account, and fix the most common login errors in 2026.

Tired of fighting with login, sessions and SSL by hand?

See the full IQ Option API in Python reference →

The basics: install and instantiate

The iqoptionapi is a community-maintained library (the most widely used version is the iqoptionapi fork). The connection runs over WebSocket and the main object is the IQ_Option class, which takes your email and password:

from iqoptionapi.stable_api import IQ_Option import logging logging.basicConfig(level=logging.INFO) api = IQ_Option(“seu@email.com”, “sua_senha”) status, motivo = api.connect() if status: print(“Conectado com sucesso!”) else: print(“Erro ao conectar:”, motivo)
Warning: iqoptionapi is unofficial and reverse-engineered. IQ Option does not support it, may block accounts that use it, and can break the library with any platform update. Treat every project built on it as experimental and high risk.

Checking that you are still connected

The WebSocket connection drops frequently. So connecting once is not enough — check the connection state and reconnect whenever needed:

if not api.check_connect(): print(“Conexao caiu, reconectando…”) api.connect()

Demo account vs real account

This is the single most important line in your entire codebase. Use change_balance to make sure you are on the practice account before running any test:

api.change_balance(“PRACTICE”) # conta demo # api.change_balance(“REAL”) # conta real (cuidado!) saldo = api.get_balance() print(“Saldo atual:”, saldo)
Golden rule: hard-code PRACTICE for the whole of development. Only switch to REAL once the system is 100% tested — and even then, knowing you can lose real money, whether your balance is in dollars or in rand.

Logging in with two-factor authentication

If the account has 2FA enabled, connect() returns a reason asking for the code. The typical flow is to capture that return value and resend it with the code received by email/SMS. The exact mechanism varies by library version, so always inspect the contents of motivo before handling it.

Most common login errors

“Invalid credentials”: wrong email/password, or an account with 2FA that has not been handled.

SSL/WebSocket errors: usually an outdated dependency — update the lib and websocket-client.

Connects but freezes later: missing reconnection logic; wrap calls in try/except and revalidate with check_connect().

FAQ

Do I need a verified account to connect? You use the same credentials as the platform. The demo account already lets you test everything risk-free.

Is it safe to put my password in the code? Never leave credentials hard-coded in version-controlled files. Use environment variables or a .env file kept out of version control.

Can I get banned for using iqoptionapi? It is possible. Because it is unofficial, using it may breach the broker’s terms and result in your account being blocked.

Disclaimer: binary options and high-risk trading can lead to the total loss of your capital. For South African readers: IQ Option is an offshore broker and is not authorised by the FSCA, so you have no local regulatory protection or recourse. This content is strictly educational and does not constitute investment advice, an offer or financial advice. Unofficial libraries can stop working and may breach the broker’s terms of use. Always test on a demo account before any trade with real money.

Similar Posts