Reading candles in real time is the foundation of almost any automation study on Quotex. Unlike downloading history (a single call), real time requires understanding how pyquotex opens the stream, how the current candle builds up tick by tick, and how to avoid the classic connection errors. This guide shows the practical path in Python — honestly, always on a demo account, and without promising easy profit.

Want the library, ready-made examples and the step-by-step installation guide?

See the pyquotex + Python guide →

Before you start: history vs. real time

They are two different things and many people confuse them. Candle history is a snapshot of the past: you request 100 closed candles and receive a ready-made list. Real time is a movie: you subscribe to an asset and start receiving continuous updates, including for the candle that is still open and changing with every tick.

Golden rule: never make a decision based on the current (open) candle. It keeps changing until it closes. Serious strategies only confirm with the previous candle already closed.

Connecting and choosing the timeframe

pyquotex works asynchronously (asyncio). The timeframe is set in seconds: 60 = M1, 300 = M5, 900 = M15, and so on. The example below connects, makes sure the demo account is being used and prepares to read an asset.

import asyncio from quotexapi.stable_api import Quotex async def main(): cliente = Quotex(email=”seu_email”, password=”sua_senha”) ok, motivo = await cliente.connect() print(“Conectado?”, ok, motivo) # SEMPRE conta de prática (demo) cliente.change_account(“PRACTICE”) print(“Saldo:”, await cliente.get_balance()) ativo = “EURUSD” timeframe = 60 # 60s = M1 # … leitura das velas abaixo asyncio.run(main())

Reading candles in real time

To receive continuous updates, you subscribe to the asset and then read the candle buffer in a loop. The pattern is to start the stream once and, on each iteration, grab the latest list of assembled candles.

# dentro de main(), após conectar: cliente.start_candles_stream(ativo, timeframe) await asyncio.sleep(timeframe) # espera formar ao menos 1 vela for _ in range(5): velas = cliente.get_realtime_candles(ativo, timeframe) if velas: ultima = list(velas.values())[-1] print(“open:”, ultima[“open”], “close:”, ultima[“close”], “ts:”, ultima[“time”]) await asyncio.sleep(timeframe)

Note the await asyncio.sleep(timeframe): it stops the loop from spinning pointlessly before a new candle even exists. In study workflows, you normally compare the previous candle’s close with the current one to detect when a candle has really closed.

Detecting when a candle closes

Because the open candle changes all the time, the trick is to store the timestamp of the last known candle and only act when it changes — the sign that the previous one has definitively closed.

ultimo_ts = None while True: velas = cliente.get_realtime_candles(ativo, timeframe) if velas: atual = list(velas.values())[-1] if ultimo_ts is not None and atual[“time”] != ultimo_ts: # a vela anterior acabou de fechar -> hora de avaliar print(“Vela fechada. Avaliar sinal agora.”) ultimo_ts = atual[“time”] await asyncio.sleep(1)

Common errors (and how to avoid them)

Empty buffer on the first iterations. The stream needs time to populate. Always check if velas: before accessing it and add an initial sleep.

Using the open candle as a signal. It swings until it closes. Only confirm with the previous, already-closed candle.

Not handling reconnection. WebSockets drop. Wrap the loop in try/except and reconnect; never assume the stream stayed alive all night.

Credentials in the code. Use environment variables. And run everything on a demo account while you study.

FAQ

What is the difference between get_candles and get_realtime_candles?
get_candles fetches closed history (a one-off call). get_realtime_candles reads the buffer of the stream you started with start_candles_stream, including the still-open candle.

How do I set M1, M5 or M15?
The timeframe is in seconds: 60 for M1, 300 for M5, 900 for M15. Only enable the timeframes you are going to use so you do not overload the connection.

Can I run it on a real account?
Technically yes, but we do not recommend it while you are studying. Binary options are extremely high risk and unofficial libraries can fail at any moment. Use demo.

Is pyquotex official?
No. It is a community project based on the Quotex WebSocket. It can break when the platform changes the protocol.

Related pyquotex guides

Warning: binary options are extremely high-risk products and can lead to the total loss of your capital. This content is educational and does not constitute an investment recommendation, an offer or financial advice. Unofficial libraries may violate the platform’s terms of use and stop working without notice. Always test on a demo account before any real trade.

Similar Posts