Prechádzať zdrojové kódy

Ticket: 5133 Dynamic Message Format(Colon & Space)

Huzaifa-MQLDev 9 mesiacov pred
rodič
commit
7b9e51b858
2 zmenil súbory, kde vykonal 52 pridanie a 9 odobranie
  1. BIN
      blTelegramToMT4.ex4
  2. 52 9
      blTelegramToMT4.mq4

BIN
blTelegramToMT4.ex4


+ 52 - 9
blTelegramToMT4.mq4

@@ -34,7 +34,7 @@ input       double               lotSize               = 0.1;
 //| Expert initialization function                                   |
 //+------------------------------------------------------------------+
 // Global Variables
-string      url1      = "http://myapp.local";///"http://127.0.0.1";
+string      url1      = "http://127.0.0.1"; // "http://myapp.local";
 string      header    = "Content-Type: application/json\r\nAccept: application/json\r\n";
 
 string symbolChart[];
@@ -391,20 +391,29 @@ void message(string &result[], string message, int message_id)
             if((StringFind(result[i], "sl", 0) != -1))
               {
                string tempSl[];
+               StringReplace(result[i],":", " ");
                result[i] = trimString(result[i]);
+               result[i] = spaceRemove(result[i]);
                //Print(" Sl String: ", result[i]);
-               StringSplit(result[i], ':', tempSl);
+               StringSplit(result[i], ' ', tempSl);
                if(ArraySize(tempSl) >= 2)
                   sl = (double) tempSl[1];
                Print("Sl : ", sl);
               }
             if((StringFind(result[i], "tp", 0) != -1))
               {
-               // Print("Tp : ", result[i], " index is: ", i);
+               Print("Tp : ", result[i], " index is: ", i);
                string tempTp[];
+               StringReplace(result[i],":", " ");
                result[i] = trimString(result[i]);
-               StringSplit(result[i], ':', tempTp);
+               result[i] = spaceRemove(result[i]);
+               Print("Tp After String Replace : ", result[i], " index is: ", i);
+               StringSplit(result[i], ' ', tempTp);
                //double tp = (double) tempTp[1];
+               for(int j=0 ; j < ArraySize(tempTp); j++)
+                 {
+                  Print(" Data is: ", tempTp[j]);
+                 }
                if(ArraySize(tempTp) >= 2)
                   tp = (double) tempTp[1];
                Print("Tp : ", tp);
@@ -491,19 +500,53 @@ void addtoMessageStructure(int message_id,string message)
 string trimString(string inputt)
   {
 // Remove spaces from the left and right sides
-   int start = 0;
+   int startt = 0;
    int end = StringLen(inputt) - 1;
 
 // Find the first non-space character
-   while(start <= end && StringGetCharacter(inputt, start) == ' ')
-      start++;
+   while(startt <= end && StringGetCharacter(inputt, startt) == ' ')
+      startt++;
 
 // Find the last non-space character
-   while(end >= start && StringGetCharacter(inputt, end) == ' ')
+   while(end >= startt && StringGetCharacter(inputt, end) == ' ')
       end--;
 
 // Extract the substring without leading or trailing spaces
-   return StringSubstr(inputt, start, end - start + 1);
+   return StringSubstr(inputt, startt, end - startt + 1);
+  }
+//+------------------------------------------------------------------+
+//|                                                                  |
+//+------------------------------------------------------------------+
+string spaceRemove(string inputt)
+  {
+   int len = StringLen(inputt);
+   string out = "";
+   bool inSpace = false;
+
+   for(int i = 0; i < len; i++)
+     {
+      ushort ch = StringGetCharacter(inputt, i);
+      // treat space, tab, CR, LF as whitespace
+      bool isSpace = (ch == 32 || ch == 9 || ch == 10 || ch == 13);
+
+      if(isSpace)
+        {
+         // mark that we are inside a whitespace run, but don't append yet
+         inSpace = true;
+         continue;
+        }
+
+      // when we hit a non-space after whitespace, add a single space (if out not empty)
+      if(inSpace && StringLen(out) > 0)
+         out += " ";
+
+      // append the non-space character (use substr to preserve unicode chars)
+      out += StringSubstr(inputt, i, 1);
+
+      inSpace = false;
+     }
+
+   return(out);
   }
 //+------------------------------------------------------------------+
 //|                                                                  |