Streaming MQL5 Trade Events to HTTP with Queuing and Retry
Summary
This article explains how an MQL5 Expert Advisor can send trade events to a local HTTP server through WinINet. OnTradeTransaction serializes opens and closes as JSON and places them in an in-memory queue; a timer callback attempts delivery separately so network delays do not hold up the trade callback. The WinINet session is reused, while connection and request handles are created for each POST and closed afterward.
The design uses queue peeking so a failed delivery leaves the event pending for retry. Logging distinguishes the first failure, trades queued during an outage, and the first successful delivery after recovery. The article describes a Python receiver and reports a test script with assertions for JSON escaping, queue overflow, and an HTTP round trip. It is an implementation example, not a trading strategy or evidence of trading performance. WinINet calls remain synchronous within the timer callback; the queue is lost if the EA restarts, and the described JSON escaping does not cover non-ASCII characters.
Key ideas
- Queue trade-event payloads in OnTradeTransaction and perform network delivery from a separate timer callback.
- Reuse the WinINet session handle and open fresh connection and request handles for each POST.
- Retain the front queue item until the server confirms a successful response, then remove it.
- Suppress repeated outage errors while reporting queued activity and a recovery summary.
- The in-memory queue does not survive EA restarts, and network calls still block the timer callback.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.