Loading…

REST Client Toolkit

A bare WebRequest() call scattered across an EA's call sites ends up rebuilding the same header assembly and status-code branching over and over, and "did this fail because the network is down or because the server rejected the request" usually gets collapsed into one boolean - which makes retry logic guess wrong about what actually happened. This header gives every call the same shape. RtcCreateClient() builds a reusable client (base URL, default headers, timeout); RtcWithBearerToken() and RtcWithApiKeyHeader() attach authentication once so every call made through that client carries it automatically. RtcGet/RtcPost/RtcPut/ RtcDelete() are thin, consistent wrappers over one shared RtcRequest() core. Every response comes back as an RtcResponse carrying the real HTTP status, the body, and an ENUM_RTC_ERROR_CLASS that distinguishes a WebRequest-level transport failure (network down, host not whitelisted) from a 4xx client error, a 429 rate limit specifically, and a 5xx server error - four genuinely different situations that call for four different responses (fail fast, fix the request, back off, or retry), not one collapsed "it didn't work" flag. RtcWalkPaginated() automates the common offset/limit pagination convention: it substitutes {offset}/{limit} tokens into a path template, fetches pages until one comes back shorter than the requested limit (the standard "you have reached the end" signal), and stops at a hard maxPages safety cap so a misbehaving API can never turn a pagination walk into an infinite loop. Notes and limitations - WebRequest() only reaches hosts the terminal has explicitly whitelisted; every call fails with error 4060 (surfaced here as RTC_ERR_TRANSPORT) until the host is added under Tools -> Options -> Expert Advisors. - RtcWithBearerToken/RtcWithApiKeyHeader take the client by reference (MQL4 requires struct parameters to be passed by reference) and mutate it in place as well as returning it - calling either without assigning the return value still updates the caller's client. - The JSON field readers (RtcExtractJsonInt) are a lightweight flat-body scanner, not a general JSON parser - correct for a top-level numeric field such as a pagination count, not for nested structures. - RtcWalkPaginated() only implements the offset/limit convention. APIs using a cursor/next-token style pagination need their own loop built from the same RtcGet() building block.

Script · MT5 · v1.0 · Free

About REST Client Toolkit

REST Client Toolkit is a script for MetaTrader 5. It has 1 setting, such as Test url. MQL source code included.

Files in the download: RestClientToolkit.mq5.mqh, RestClientToolkit.txt, RestClientToolkitDemo.ex5, RestClientToolkitDemo.mq5.

Settings

SettingDefaultWhat it does
Test urlpaste a whitelisted https://host base URL to test a live GET (leave blank to skip)

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria