Skip to content

MtApi5: pending order management (BuyLimit/SellLimit/BuyStop/SellStop, OrderModify, OrderDelete)#305

Open
biohazardxxx wants to merge 5 commits into
vdemydiuk:devfrom
biohazardxxx:feat/mql5-pending-orders
Open

MtApi5: pending order management (BuyLimit/SellLimit/BuyStop/SellStop, OrderModify, OrderDelete)#305
biohazardxxx wants to merge 5 commits into
vdemydiuk:devfrom
biohazardxxx:feat/mql5-pending-orders

Conversation

@biohazardxxx

Copy link
Copy Markdown

Summary

Adds pending order management to the MtApi5 connector. The existing CTrade wrappers (Buy/Sell) only cover market orders — there was no way to place, modify or delete pending orders from the .NET client. This adds the remaining CTrade order methods end-to-end (C# client → EA handler → recompiled .ex5):

  • bool BuyLimit(out MqlTradeResult? result, double volume, double price, string? symbol = null, double sl = 0.0, double tp = 0.0, ENUM_ORDER_TYPE_TIME typeTime = ORDER_TIME_GTC, DateTime? expiration = null, string? comment = null)
  • bool SellLimit(...), bool BuyStop(...), bool SellStop(...) — same signature as BuyLimit
  • bool OrderModify(out MqlTradeResult? result, ulong ticket, double price, double sl, double tp, ENUM_ORDER_TYPE_TIME typeTime = ORDER_TIME_GTC, DateTime? expiration = null, double stoplimit = 0.0)
  • bool OrderDelete(out MqlTradeResult? result, ulong ticket)

Implementation notes

  • Command ids 320–325 (BuyLimitOrderDelete), matching the ADD_EXECUTOR registrations in mq5/MtApi5.mq5. Ids 307–316 are left free for the calendar PR (MtApi5: expose MT5 economic calendar (Calendar* functions) #301), hence the intentional 317–319 gap.
  • Implementation mirrors the existing Buy/Sell pattern exactly: same RetVal + Result response body (MqlTradeResultToJson), consumed by the same FuncResult<MqlTradeResult> contract on the C# side.
  • The client sends TypeTime as int and Expiration as unix seconds via Mt5TimeConverter.ConvertToMtTime(DateTime?), which returns 0 for null — matching CTrade's expiration = 0 default. Symbol/Comment are omitted from the payload when null so the EA falls back to Symbol() / "", exactly like Buy/Sell.
  • EA handlers are verbatim copies of the Execute_Buy/Execute_Sell shape (GET_*_JSON_VALUE macros, CTrade instance, result via trade.Result()), with casts (ENUM_ORDER_TYPE_TIME)type_time / (datetime)expiration; tickets are read with GET_ULONG_JSON_VALUE, and OrderModify passes stoplimit as the last CTrade::OrderModify argument per its signature.
  • TestClient additions are kept minimal: a BuyLimit action (fetches the EURUSD tick via SymbolInfoTick and places a 0.1-lot limit 50 pips below bid) and an OrderDelete action that reuses the existing ticket textbox in the CTrade tab. The other methods have no dedicated buttons.
  • A post-implementation review traced the commands end-to-end (id match between Mt5CommandType.cs and the ADD_EXECUTOR registrations, case-sensitive JSON key match on both sides, response envelope identical to the existing Buy/Sell contract, ENUM_ORDER_TYPE_TIME values 0–3 matching MQL5, correct CTrade signatures) and found no defects.
  • Merge note: this branch is based on dev without the calendar changes, so the committed mq5/MtApi5.ex5 does not include calendar support. If MtApi5: expose MT5 economic calendar (Calendar* functions) #301 lands first, MtApi5.mq5 should be recompiled once after merging this branch.

Testing

  • MtApi5 and MtApi5TestClient build clean (Release, 0 errors; the TestClient's nullable warnings are pre-existing).
  • MtApi5.mq5 compiles via MetaEditor with "Result: 0 errors"; the freshly recompiled mq5/MtApi5.ex5 is committed.
  • The feature has not been runtime-tested against a live MT5 terminal — verification is the green .NET builds plus the clean MQL compile and the code trace above.

🤖 Generated with Claude Code

biohazardxxx and others added 5 commits July 4, 2026 00:00
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
BuyLimit, SellLimit, BuyStop, SellStop, OrderModify and OrderDelete
mirror the existing CTrade-based Buy/Sell methods; expiration is sent
as unix seconds via Mt5TimeConverter.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…20-325)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant