Reading candles in real time is the foundation of almost any automation study on Quotex. Unlike downloading history (which is a single call), real time requires understanding how pyquotex opens the stream, how the current candle keeps forming tick by tick, and how to avoid the classic connection mistakes. This guide shows the practical path in Python — honestly, always on a demo account, and without promising easy profit.
Want the library, ready-to-use 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 a lot of people mix them up. 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.
Connecting and choosing the timeframe
pyquotex works asynchronously (asyncio). The timeframe is defined 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.
Reading candles in real time
To receive continuous updates, you subscribe to the asset and then read the candle buffer in a loop. The usual pattern is to start the stream once and, on each iteration, grab the most recent list of already-assembled candles.
Note the await asyncio.sleep(timeframe): it keeps the loop from spinning pointlessly before a new candle even exists. In study runs, you normally compare the previous candle’s close with the current one to detect when a candle has actually closed.
Detecting when a candle closes
Since 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.
Common mistakes (and how to avoid them)
Empty buffer in 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 candle once it has fully closed.
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 returns 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 learning. Binary options are extremely high risk and unofficial libraries can fail at any moment. Use the demo.
Is pyquotex official?
No. It is a community project built on the Quotex WebSocket. It can break whenever the platform changes the protocol.
Disclaimer: 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 investment advice, an offer or financial advice. Unofficial libraries may violate the platform’s terms of service and stop working without notice. Always test on a demo account before any real trade.
