If you want to read IQ Option market data with Python, the get_candles method of the unofficial iqoptionapi library is the most common starting point. It lets you download historical candles for any asset and timeframe — the foundation for backtests, indicators and bots. In this no-nonsense guide we show the correct syntax, the parameters that usually confuse people (timestamp and candle size), a working example and the real risks of using an API that is not official.

Want the complete step-by-step for the IQ Option API in Python, with connection, candle and execution examples?

See the IQ Option API in Python guide →

What is get_candles?

The iqoptionapi is a community-maintained (unofficial) library that connects to IQ Option through the same WebSocket channels the browser uses. The get_candles method requests a batch of candles ending at a given moment in time, returning a list of dictionaries with the open, high, low, close, volume and the timestamps of each candle.

First things first: install the library and connect to the demo account (PRACTICE mode). Never test new code directly on your real account.

Syntax and parameters

The usual signature is get_candles(ativo, intervalo, quantidade, fim_em):

ativo — the pair, e.g. “EURUSD”
intervalo — candle size in seconds (60 = 1 min, 300 = 5 min)
quantidade — number of candles to return
fim_em — Unix timestamp of the most recent candle you want (usually time.time())

Working example

import time from iqoptionapi.stable_api import IQ_Option api = IQ_Option(“seu@email.com”, “sua_senha”) api.connect() api.change_balance(“PRACTICE”) # sempre demo para testar ativo = “EURUSD” intervalo = 60 # velas de 1 minuto quantidade = 100 # ultimas 100 velas fim = time.time() # ate agora velas = api.get_candles(ativo, intervalo, quantidade, fim) for v in velas[-3:]: # mostra as 3 ultimas print(“abertura:”, v[“open”], “fechamento:”, v[“close”], “max:”, v[“max”], “min:”, v[“min”])

Each item in the list carries the keys open, close, max, min, volume and the from/to times. For “real-time” candles, simply call get_candles in a loop with fim = time.time(), or use the continuous streams (start_candles_stream / get_realtime_candles) when you want updates without repolling.

Common errors

Empty list: usually the asset is closed (weekend or outside its trading hours — note that the timestamps are Unix/UTC, so convert to SAST, UTC+2, when checking sessions) or the name is wrong. Check open assets with get_all_open_time().

Inverted timestamp: fim_em must be the end of the period, not the start. For older history, subtract quantidade × intervalo.

Disconnection: the unofficial API drops frequently — implement reconnection and check api.check_connect() before each call.

Risks of using an unofficial API

IQ Option does not publish an official API for retail clients. The iqoptionapi reverse-engineers the website’s protocol, which means: it can stop working with any platform update, it may breach the terms of use and, with intense/automated usage, your account can be restricted. It is also worth remembering that IQ Option is an offshore broker with no FSCA authorisation in South Africa. Use it for study and backtesting responsibly, and never blindly trust signals generated by unaudited code.

FAQ

Does get_candles fetch real-time data?
It pulls a batch ending at the moment you specify. For continuous updates, use the streams (start_candles_stream / get_realtime_candles).

What is the minimum candle interval?
Normally 60 seconds (1 minute). Values like 5, 10 and 15 seconds depend on the asset and on availability on the platform.

Is iqoptionapi official?
No. It is a community project, with no support from IQ Option, and it can break at any time.

Can I backtest with this data?
Yes, by downloading historical candles in batches. Watch out for gaps and for the timestamp timezone (Unix/UTC — two hours behind SAST).

Disclaimer: binary options are extremely high-risk products and most retail traders lose money. In South Africa, offshore binary options brokers such as IQ Option are not authorised by the FSCA, so you have no local regulatory protection. This content is educational and technical, and does not constitute investment advice, an offer or financial advice. Unofficial APIs may breach the broker’s terms of use and stop working without notice. Always test on a demo account before trading real money and never risk rand you cannot afford to lose.

Similar Posts