Skip to content

MtApi5: expose SymbolInfoMarginRate#304

Open
biohazardxxx wants to merge 5 commits into
vdemydiuk:devfrom
biohazardxxx:feat/mql5-symbol-margin-rate
Open

MtApi5: expose SymbolInfoMarginRate#304
biohazardxxx wants to merge 5 commits into
vdemydiuk:devfrom
biohazardxxx:feat/mql5-symbol-margin-rate

Conversation

@biohazardxxx

Copy link
Copy Markdown

Summary

Exposes the MQL5 built-in SymbolInfoMarginRate() through the MtApi5 connector. The initial and maintenance margin rates for a symbol (which depend on order type and direction) were not reachable from the .NET client; this adds the function end-to-end (C# client → EA handler → recompiled .ex5 → TestClient action).

New method on MtApi5Client:

Command id Method
380 bool SymbolInfoMarginRate(string symbolName, ENUM_ORDER_TYPE orderType, out double initialMarginRate, out double maintenanceMarginRate)

Returns the native function's bool and writes the two rates to the out parameters.

Implementation notes

  • Command id 380 — intentionally leaves a gap after GetSymbols = 306: dev does not yet contain the calendar ids 307–316 proposed in MtApi5: expose MT5 economic calendar (Calendar* functions) #301, and 380 stays clear of any collision with them.
  • Mirrors the SymbolInfoSessionQuote (id 58) multi-value pattern. Wire format: request params {Symbol: string, OrderType: int}; response {RetVal: bool, Result: {Initial: double, Maintenance: double}}.
  • C# client — deserializes via SendCommand<FuncResult<Dictionary<string, double>>> and reads Initial/Maintenance with TryGetValue; on a null or malformed response the out params are set to 0 and the method returns false (same fallback idiom as SessionQuote's DateTime.MinValue). ENUM_ORDER_TYPE already existed in Mt5Enums.cs and serializes as an int under the default Newtonsoft settings, so no new enums or DTOs were needed.
  • MQL5 EA (mq5/MtApi5.mq5) — handler reads OrderType via GET_INT_JSON_VALUE, casts it to ENUM_ORDER_TYPE, initializes the two doubles to 0.0 before the call, and serializes the result via JSONNumber(double).
  • TestClient — one button exercising SymbolInfoMarginRate on EURUSD / ORDER_TYPE_BUY, next to the existing SessionQuote/SessionTrade buttons.
  • The diff is purely additive — no changes to existing behavior; files keep their existing CRLF line endings. A post-implementation review traced the command end-to-end (id match between Mt5CommandType.cs and the ADD_EXECUTOR registration, case-sensitive request-key match on both sides, response envelope exactly matching the FuncResult<Dictionary<string, double>> deserialization) and found no defects.

Testing

  • MtApi5 and MtApi5TestClient build clean in Release (the TestClient's 332 nullable warnings are pre-existing on dev, none in the added code).
  • MtApi5.mq5 compiles via MetaEditor with "Result: 0 errors"; the recompiled mq5/MtApi5.ex5 is committed.
  • Not runtime-tested against a live MT5 terminal — verification was build/compile-level plus the code trace above; no live round-trip was run.

🤖 Generated with Claude Code

biohazardxxx and others added 5 commits July 3, 2026 23:59
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>
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