If you are looking for the IQ Option API in Python, the first honest truth is this: IQ Option has no official public API for automating retail accounts. Everything circulating on GitHub — including the popular pyiqoptionapi library (a maintained fork of the old iqoptionapi) — is reverse engineering of the WebSocket channel used by the website. It works, but it lives in a grey zone and can break with any broker update. This guide shows the real methods, with examples, and where the risks are.
Want to automate without fighting an unofficial library that breaks every week? See the ready-made alternative:
▶ See the IQ Option bot and integration in PythonDoes IQ Option have an official API?
Not for the everyday trader. IQ Option offers integrations via partnership/affiliate arrangements in some corporate cases, but it does not publish trading API documentation for individual accounts. That is why all automation depends on libraries that mimic the browser, connecting to the WebSocket endpoint wss://iqoption.com/echo/websocket and sending the same commands the website would send.
Installing the library
The most active fork is usually pyiqoptionapi. The typical installation:
Connection and login
The entry point is the main class. The connect() method returns a tuple (status, motivo) — always check the status before continuing:
Main methods you will use
These are the most common day-to-day methods (names can vary between forks — check your installed version):
connect(), check_connect(), change_balance("PRACTICE"/"REAL"), get_balance(), reset_practice_balance().
get_candles(ativo, intervalo, quantidade, fim), start_candles_stream(), get_realtime_candles(), stop_candles_stream().
buy(valor, ativo, direcao, expiracao) returns (check, id); track it with check_win_v4(id) or check_win_digital_v2(id) for digital options.
Example: read candles and send an order (on DEMO)
The example places a 1-dollar binary order (most IQ Option accounts are denominated in US dollars; if yours runs in rand, the same value of 1 applies in ZAR) with a 1-minute expiry.
try/except and reconnect with check_connect(). WebSocket drops frequently, and a loop without reconnection simply freezes.
Common errors (and why they happen)
Most problems are not bugs in your code, but changes on the broker’s side:
Connection drops in long loops → missing reconnection and keep-alive.
get_candles comes back empty → asset closed at that hour (check schedules against SAST/UTC+2) or an incorrect symbol name.
Library stops working out of nowhere → IQ Option updated the protocol; wait for a new fork.
Is automating IQ Option worth it?
For learning and testing ideas on demo, yes — it is a great laboratory. For trading real money, weigh this up: you depend on unofficial code that can break, and no automation turns binary options (a negative-sum game because of the payout) into guaranteed income. If your goal is stability, consider brokers with a properly documented API, such as Deriv, or ready-made solutions that have already been tested.
FAQ
Is pyiqoptionapi safe? The code is open and auditable, but you hand it your email and password. Use a unique password and, preferably, a demo account.
Can I get banned for using it? Yes. Automation generally breaches the terms of use. The broker can close the account.
Does it work with digital options? Yes, there are specific methods (buy_digital_spot, check_win_digital_v2), but they change more between versions.
Is there a more stable alternative? Deriv has an official, documented API. For IQ Option, ready-made solutions reduce the maintenance burden.
Disclaimer: binary options are extremely high-risk products and most retail traders lose money. IQ Option and similar offshore brokers are not authorised by the FSCA, so South African clients have no local regulatory protection. This content is educational, does not constitute investment advice, and unofficial libraries may breach the broker’s terms. Always test on a demo account before any real trade.
