I have an error in the WebRequest section. Can anyone help me edit it
// Define your Telegram bot token and chat ID input string BotToken = "YOUR_BOT_TOKEN"; input string ChatID = "YOUR_CHAT_ID"; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { // Your trading logic and conditions go here // Send a push notification to Telegram string message = "Your message here"; SendTelegramMessage(message); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { // Deinitialization function } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { // Your trading logic and conditions go here } //+------------------------------------------------------------------+ // Function to send a message to Telegram void SendTelegramMessage(string text) { string url = "https://api.telegram.org/bot" + BotToken + "/sendMessage"; string postdata = "chat_id=" + ChatID + "&text=" + text; string headers = "Content-Type: application/x-www-form-urlencoded\r\n"; char result[]; char data[]; StringToCharArray(postdata,data,0,StringLen(postdata),CP_ACP); string result_headers=NULL; // Make an HTTP POST request to send the message int res = WebRequest("POST", url, headers,9000,data,result,result_headers); if (res > 0) { Print("Push notification sent successfully."); } else { Print("Error sending push notification. Error code: ", GetLastError()); } }
Try this
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
ok, thank you
Please reference the documentation — Documentation on MQL5: Network Functions / WebRequest
1. Sending simple requests of type "key=value" using the header Content-Type: application/x-www-form-urlencoded.
int WebRequest( const string method, // HTTP method const string url, // URL const string cookie, // cookie const string referer, // referer int timeout, // timeout const char &data[], // the array of the HTTP message body int data_size, // data[] array size in bytes char &result[], // an array containing server response data string &result_headers // headers of server response );2. Sending a request of any type specifying the custom set of headers for a more flexible interaction with various Web services.
int WebRequest( const string method, // HTTP method const string url, // URL const string headers, // headers int timeout, // timeout const char &data[], // the array of the HTTP message body char &result[], // an array containing server response data string &result_headers // headers of server response );
In your second code, you have 10 parameters, which does not match either version of the function shown above.
int res = WebRequest("POST", url, NULL, NULL, 0, post_data, 0, "", "", 0);
Hello i have a MQl5 code to conect a FastAPI an post some data, but when i try to compile always give me this error: 'WebRequest' - no one of the overloads can be applied to the function call MQL5++LM.mq5 219 11. There is a little version to test the request:
//+------------------------------------------------------------------+ //| TestWebRequestEA.mq5| //| Copyright 2024, TuNombre | //| https://tusitio.com | //+------------------------------------------------------------------+ #property strict // Parámetros de entrada input string testUrlPredict = "http://127.0.0.1:8000/predict"; // URL del endpoint /predict input string testUrlRegister = "http://127.0.0.1:8000/register"; // URL del endpoint /register //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { // Realizar una solicitud de prueba al iniciar el EA TestWebRequest(); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Función para realizar una solicitud WebRequest de prueba | //+------------------------------------------------------------------+ void TestWebRequest() { // Datos de prueba para /predict string predictDataStr = "{\"open\": 1.2345, \"high\": 1.2350, \"low\": 1.2330, \"close\": 1.2340, \"volume\": 1000, \"trix\": 0.5}"; char predictData[]; StringToCharArray(predictDataStr, predictData); string predictHeaders = "Content-Type: application/json"; string predictResponse; int predictRes = WebRequest("POST", testUrlPredict, predictHeaders, 5000, predictData, predictResponse); if(predictRes == 200) { Print("Respuesta exitosa de /predict: " + predictResponse); // Parsear la respuesta para obtener "probability" double probability = 0.0; int start = StringFind(predictResponse, ":"); int end = StringFind(predictResponse, "}"); if(start != -1 && end != -1 && end > start) { string probabilityStr = StringSubstr(predictResponse, start + 1, end - start - 1); probability = StringToDouble(probabilityStr); Print("Probabilidad obtenida: ", probability); } else { Print("Error: Formato de respuesta inesperado en /predict."); } // Datos de prueba para /register string registerDataStr = StringFormat( "{\"price\": %.5f, \"lotSize\": %.2f, \"takeProfit\": %.5f, \"stopLoss\": %.5f, \"prediccionML\": %.2f, \"resistencia\": %.5f, \"soporte\": %.5f, \"timestamp\": \"%s\"}", 1.2345, 0.1, 1.2400, 1.2300, probability, 1.2350, 1.2330, "2024-10-28 15:30" ); char registerData[]; StringToCharArray(registerDataStr, registerData); string registerHeaders = "Content-Type: application/json"; string registerResponse; int registerRes = WebRequest("POST", testUrlRegister, registerHeaders, 5000, registerData, registerResponse); if(registerRes == 200) { Print("Respuesta exitosa de /register: " + registerResponse); } else { Print("Error en WebRequest a /register. Código de respuesta: " + IntegerToString(registerRes)); } } else { Print("Error en WebRequest a /predict. Código de respuesta: " + IntegerToString(predictRes)); } }
Perhaps you should read the manual, or press F1 in the editor.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.
Your code | Documentation |
---|---|
int predictRes = WebRequest( "POST", testUrlPredict, predictHeaders, 5000, predictData, predictResponse ); | int WebRequest( const string method, // HTTP method const string url, // URL const string headers, // headers int timeout, // timeout const char &data[], // the array of the HTTP message body char &result[], // an array containing server response data string &result_headers // headers of server response ); |
int WebRequest( const string method, // HTTP method const string url, // URL const string headers, // headers int timeout, // timeout const char &data[], // the array of the HTTP message body char &result[], // an array containing server response data string &result_headers // headers of server response );
string jsonDataStr = "{}"; // your json string char jsonData[]; StringToCharArray(jsonDataStr, jsonData);good luck

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use