MQL4CSharp
MQL4CSharp copied to clipboard
Race condition / delay when executing commands via REST in MQL4CSharp
Hi @jason0598647 đź‘‹
Thanks for putting together MQL4CSharp — it’s a very promising bridge between C# and MT4. I ran into an issue that might be a bug (or might need documentation clarification).
Environment:
- Repository: jason0598647/MQL4CSharp :contentReference[oaicite:0]{index=0}
- Version: latest commit on
master - MT4 Build: (I used build 1420)
- OS: Windows 10 x64
- .NET version: .NET 6 (or .NET Core)
Issue: When sending commands from the C# side via the REST API (for example, createOrder, modifyOrder, etc.), there is sometimes a noticeable delay before MT4 executes the command, or in certain cases the command is missed entirely. This appears especially under heavier load (many requests in a short time).
Expected Behavior:
- REST commands should be reliably received and executed by MT4 with minimal delay.
- Even under multiple sequential requests, there should be no dropped commands.
- Any queueing or polling behavior should preserve command order.
Actual Behavior:
- Some commands take longer than expected (e.g. REST request returns success, but MT4 doesn’t execute until later).
- Occasionally a command “vanishes” — the REST call succeeds (no error) but there’s no corresponding action in MT4.
- Logging shows polling in
onTimer()oronTick()catches commands, but sometimes misses or skips when load is high.
Code / Repro Steps:
// C# side
// Using REST -> send 5 “createOrder” commands in quick succession
for (int i = 0; i < 5; i++)
{
var result = await client.PostAsync("/order/create", new OrderRequest { Symbol = "EURUSD", Side = "Buy", Volume = 0.1, Price = 1.1000 + i * 0.0001 });
Console.WriteLine($"Sent order {i}: {await result.Content.ReadAsStringAsync()}");
}
// Then check in MT4 whether 5 orders are opened — sometimes only 3 or 4 appear.
// MT4 expert logs show lines like:
// “Command waiting”
// “Parsing command”
// "[…] executed"
// Missing some “executed” logs corresponding to sent orders.