//+------------------------------------------------------------------+ //| SwarmConnector.mq5 | //| SWARM Autonomous Trading Orchestrator EA | //| https://101.32.244.251.nip.io | //+------------------------------------------------------------------+ #property copyright "SWARM Autonomous Orchestrator" #property link "https://101.32.244.251.nip.io" #property version "5.00" #property strict input string InpApiKey = ""; // SWARM API Key input string InpServerUrl = "https://101.32.244.251.nip.io";// Server URL input int InpIntervalSec= 30; // Telemetry Heartbeat (detik) datetime g_last_hb = 0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { if(StringLen(InpApiKey) == 0) { Alert("SWARM Error: API Key wajib diisi dari menu Settings di dashboard."); return(INIT_PARAMETERS_INCORRECT); } EventSetTimer(InpIntervalSec); Print("SWARM Connector EA initialized. Streaming telemetry every ", InpIntervalSec, " seconds."); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { EventKillTimer(); Print("SWARM Connector EA deinitialized."); } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { SendHeartbeat(); } //+------------------------------------------------------------------+ //| Send Heartbeat via WebRequest | //+------------------------------------------------------------------+ void SendHeartbeat() { string url = InpServerUrl + "/api/ingest/heartbeat"; string cookie = NULL, headers; char post[], result[]; headers = "Content-Type: application/json\r\nAuthorization: Bearer " + InpApiKey + "\r\n"; bool is_demo = (AccountInfoInteger(ACCOUNT_TRADE_MODE) == ACCOUNT_TRADE_MODE_DEMO); string broker = AccountInfoString(ACCOUNT_COMPANY); string srv = AccountInfoString(ACCOUNT_SERVER); string json = StringFormat("{\"broker_name\":\"%s\",\"is_demo\":%s,\"server_hint\":\"%s\"}", broker, is_demo ? "true" : "false", srv); StringToCharArray(json, post, 0, WHOLE_ARRAY, CP_UTF8); ResetLastError(); int res = WebRequest("POST", url, headers, 5000, post, result, headers); if(res == 200) { g_last_hb = TimeCurrent(); } else { PrintFormat("SWARM WebRequest failed, code=%d, err=%d", res, GetLastError()); } } //+------------------------------------------------------------------+