If you are looking for the IQ Option API in Python, the first honest truth is this: IQ Option does not have an 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 gray area 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 Python integration

Does IQ Option have an official API?

Not for the everyday trader. IQ Option offers integrations via partnerships/affiliates 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.

Practical consequence: since nothing is official, the broker can change the protocol, require a captcha, or block the account for automated use. Always use a demo account first and never risk money you cannot afford to lose.

Installing the library

The most active fork is usually pyiqoptionapi. The typical installation:

pip install pyiqoptionapi # alternative straight from the repository: pip install git+https://github.com/iqoptionapi/iqoptionapi.git

Connection and login

The entry point is the main class. The connect() method returns a (status, reason) tuple — always check the status before continuing:

from iqoptionapi.stable_api import IQ_Option import logging logging.basicConfig(level=logging.INFO) api = IQ_Option(“your_email”, “your_password”) status, reason = api.connect() if status: print(“Connected!”) else: print(“Failed:”, reason) # ALWAYS work on demo while testing: api.change_balance(“PRACTICE”) # or “REAL” print(“Balance:”, api.get_balance())

The main methods you will use

These are the most common methods in day-to-day use (names may vary between forks — check the version you installed):

Account and balance: connect(), check_connect(), change_balance("PRACTICE"/"REAL"), get_balance(), reset_practice_balance().
Quotes / candles: get_candles(asset, interval, amount, endtime), start_candles_stream(), get_realtime_candles(), stop_candles_stream().
Binary orders: buy(amount, asset, direction, expiration) 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)

asset = “EURUSD” # 10 one-minute candles up to now import time candles = api.get_candles(asset, 60, 10, time.time()) last = candles[-1] print(“Close:”, last[“close”]) # One-dollar binary order, CALL, 1-minute expiration direction = “call” # or “put” amount = 1 expiration = 1 check, order_id = api.buy(amount, asset, direction, expiration) if check: result, profit = api.check_win_v4(order_id) print(“Result:”, result, “Profit/Loss:”, profit) else: print(“Order rejected”)
Robustness tip: wrap calls in try/except and reconnect with check_connect(). The WebSocket drops often, 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:

Login fails even with the right password → captcha/2FA or anti-bot blocking.
Connection drops during long loops → missing reconnection and keep-alive.
get_candles comes back empty → the asset is closed at that time or the symbol name is wrong.
The 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 it carefully: 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 truly documented API, such as Deriv, or ready-made, already tested solutions.

FAQ

Is pyiqoptionapi safe? The code is open and auditable, but you hand it your e-mail and password. Use a dedicated password and, preferably, a demo account.

Can I get banned for using it? Yes. Automation usually violates 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. This content is educational, does not constitute investment advice, and unofficial libraries may violate the broker’s terms. Always test on a demo account before any real trade.

Similar Posts