MtApi5: pending order management (BuyLimit/SellLimit/BuyStop/SellStop, OrderModify, OrderDelete)#305
Open
biohazardxxx wants to merge 5 commits into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 remainingCTradeorder 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 asBuyLimitbool 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
BuyLimit…OrderDelete), matching theADD_EXECUTORregistrations inmq5/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.Buy/Sellpattern exactly: sameRetVal+Resultresponse body (MqlTradeResultToJson), consumed by the sameFuncResult<MqlTradeResult>contract on the C# side.TypeTimeas int andExpirationas unix seconds viaMt5TimeConverter.ConvertToMtTime(DateTime?), which returns 0 for null — matching CTrade'sexpiration = 0default.Symbol/Commentare omitted from the payload when null so the EA falls back toSymbol()/"", exactly likeBuy/Sell.Execute_Buy/Execute_Sellshape (GET_*_JSON_VALUEmacros,CTradeinstance, result viatrade.Result()), with casts(ENUM_ORDER_TYPE_TIME)type_time/(datetime)expiration; tickets are read withGET_ULONG_JSON_VALUE, andOrderModifypassesstoplimitas the lastCTrade::OrderModifyargument per its signature.BuyLimitaction (fetches the EURUSD tick viaSymbolInfoTickand places a 0.1-lot limit 50 pips below bid) and anOrderDeleteaction that reuses the existing ticket textbox in the CTrade tab. The other methods have no dedicated buttons.Mt5CommandType.csand theADD_EXECUTORregistrations, case-sensitive JSON key match on both sides, response envelope identical to the existing Buy/Sell contract,ENUM_ORDER_TYPE_TIMEvalues 0–3 matching MQL5, correctCTradesignatures) and found no defects.devwithout the calendar changes, so the committedmq5/MtApi5.ex5does not include calendar support. If MtApi5: expose MT5 economic calendar (Calendar* functions) #301 lands first,MtApi5.mq5should be recompiled once after merging this branch.Testing
MtApi5andMtApi5TestClientbuild clean (Release, 0 errors; the TestClient's nullable warnings are pre-existing).MtApi5.mq5compiles via MetaEditor with "Result: 0 errors"; the freshly recompiledmq5/MtApi5.ex5is committed.🤖 Generated with Claude Code