MtApi5: composite GetPositions/GetOrders snapshots (one round-trip)#309
Open
biohazardxxx wants to merge 6 commits into
Open
MtApi5: composite GetPositions/GetOrders snapshots (one round-trip)#309biohazardxxx wants to merge 6 commits into
biohazardxxx wants to merge 6 commits into
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Replace the PositionsTotal/PositionGetTicket and OrdersTotal/OrderGetTicket per-property call sequences with a single round-trip each. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Loop PositionsTotal/PositionGetTicket and OrdersTotal/OrderGetTicket, serializing every property per element. Broker-provided strings are escaped at the call site since JSONString::toString() performs no escaping. 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
Reading positions/orders through the property API is an N+1 round-trip pattern:
PositionsTotal+PositionGetTicket(i)+ one RPC per property. With command latency dominated by the expert's wake-up cadence, reading 10 properties of 20 positions costs 200+ round-trips.This PR adds two composite snapshot commands that return everything in one round-trip:
List<Mt5Position>? GetPositions()List<Mt5Order>? GetOrders()New DTOs
Mt5Position(18 properties) andMt5Order(22 properties) cover the fullPOSITION_*/ORDER_*property surface (times incl. msc, prices, volumes, SL/TP, magic, state/reason/type enums, comment, external id).Implementation notes
MqlRateshouse pattern: settablelong MtTime*unix-seconds properties carry the wire value;DateTimeproperties are computed viaMt5TimeConverter(get-only, not serialized).PositionGetTicket(i)/OrderGetTicket(i); a ticket of 0 (element vanished betweenTotal()and selection — a live-trading race) skips the element rather than failing the snapshot.\n/\r/\t) sincejson.mqh'sJSONString.toString()performs no escaping. If escaping is later added tojson.mqh(see Fix invalid JSON from unescaped backslashes in MQL5 string serialization #294), these call sites must be reverted in the same change.Testing
MtApi5builds 0 warnings/0 errors; test client builds clean;MtApi5.mq5compilesResult: 0 errors, 0 warnings(recompiled.ex5included).long.MaxValuetickets).GetPositions()/GetOrders()return non-null empty lists on a flat account and matchPositionsTotal()/OrdersTotal(). The populated path was validated via the wire-replica tests only — no live positions were opened (test terminal ran with trading disabled).🤖 Generated with Claude Code