Asynchronous WebRequest with no DLL

 

Hi,

I strongly believe that's not possible, but let me ask it anyway:

There's any way to make an asynchronous WebRequest with no DLLs use at all?

I need to grab some large data from a website but can't afford losing ticks in the meanwhile.

Thanks!

 
Henrique Vilela:

Hi,

I strongly believe that's not possible, but let me ask it anyway:

There's any way to make an asynchronous WebRequest with no DLLs use at all?

I need to grab some large data from a website but can't afford losing ticks in the meanwhile.

Thanks!

What if you ran the synchronous WebRequest() MQL5 function in a second EA on a different chart?

If the first EA needs to know when the file is there, it could use FileIsExist(), or monitor the file size. Or, you could probably fashion some sort of signaling from EA #2 to EA #1 using terminal global variables.

 
Henrique Vilela:

Hi,

I strongly believe that's not possible, but let me ask it anyway:

There's any way to make an asynchronous WebRequest with no DLLs use at all?

I need to grab some large data from a website but can't afford losing ticks in the meanwhile.

Thanks!

My advice is using an indicator for grabbing the data, process it and save it locally or in a global variable. Then the EA can read the file if needed or get the result from a global variable.

 
Fernando Morales:

My advice is using an indicator for grabbing the data, process it and save it locally or in a global variable. Then the EA can read the file if needed or get the result from a global variable.

Impossible. Indicators are not allowed to use WebRequest.

 

Anthony is on the right track. 


  1. Make a WebWorker EA that receives JSON requests via the OnChartEvent sent from EventChartCustom in the other EA.
  2. Formulate a request using the JSON serializer and pass in the sparam. 
  3. WebWorker deserializes the request and does WebRequests stuff. 
  4. WebWorker serializes the response and sends the JSON string back to the caller.

So it might look like:


{
   "type": "request",
   "url": "https://www.mql5.com",
   "verb": "GET",
   "params":{
      "q": "articles",
      "limit": 50
   },
   "headers":{
      "Content-Type": "application/json"
   }
}
   
{
   "type": "response",
   "url": "https://www.mql5.com",
   "response_body": "{\"data\":20}",
   "response_headers":{
      "Content-Type": "application/json"
   }
}
 
nicholi shen:

Anthony is on the right track. 


  1. Make a WebWorker EA that receives JSON requests via the OnChartEvent sent from EventChartCustom in the other EA.
  2. Formulate a request using the JSON serializer and pass in the sparam. 
  3. WebWorker deserializes the request and does WebRequests stuff. 
  4. WebWorker serializes the response and sends the JSON string back to the caller.

So it might look like:


Do you know if there is any limit on the sparam (string) length of EventChartCustom() ?
 
Alain Verleyen:
Do you know if there is any limit on the sparam (string) length of EventChartCustom() ?

Great question, and yes. 159 chars. So if you need to transmit a larger message you can just pass a reference to the file instead. Here is a working skeleton of the concept in action. 


enum XMODE{ XWORKER, XBOSS, XUNINIT};
#define XPING_REQ 100
#define XPING_RES 101
#define XSEND 102
#define XECHO 103

XMODE    g_mode = XUNINIT;
long     g_worker_chart_id = -1;
int      g_max_len = 0;
string   g_test_string = "*";
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   for(long ch=ChartFirst(); ch >=0; ch=ChartNext(ch))
      EventChartCustom(ch, XPING_REQ, ChartID(), 0.0, "");
   EventSetTimer(1);
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   EventKillTimer();
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick(){}
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
{
   switch(g_mode){
      case XUNINIT:
         g_mode = XWORKER;
      case XWORKER:
         Comment("I am a worker bot");
         break;
      default:
         Comment("I am a boss bot");
         EventChartCustom(g_worker_chart_id, XSEND, ChartID(), 0.0, g_test_string);
         break;
   }
   EventKillTimer();
}
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   switch(id){
      case CHARTEVENT_CUSTOM+XPING_REQ:{
         if(g_mode == XWORKER)
            EventChartCustom(lparam, XPING_RES, ChartID(), 0.0, "worker");
         break;
      }
      case CHARTEVENT_CUSTOM+XPING_RES:{
         if(sparam == "worker"){
            g_mode = XBOSS;
            g_worker_chart_id = lparam;
         }
         break;
      }
      case CHARTEVENT_CUSTOM+XSEND:{
         EventChartCustom(lparam, XECHO, ChartID(), dparam, sparam);
         break;
      } 
      case CHARTEVENT_CUSTOM+XECHO:{
         int len = StringLen(sparam);
         if(len > g_max_len){
            g_test_string += "*";
            g_max_len = len;
            Comment("Max len = ", g_max_len);
            EventChartCustom(g_worker_chart_id, XSEND, ChartID(), 0.0, g_test_string);
         }else{
            Comment("FINAL MAX LEN = ", len);
         }
         break;
      }
   }
}
//+------------------------------------------------------------------+
 
nicholi shen:

Great question, and yes. 159 chars. So if you need to transmit a larger message you can just pass a reference to the file instead. Here is a working skeleton of the concept in action. 


Thanks for the information.
 
Alain Verleyen:
Thanks for the information.

You're welcome.

Reason: