Download csv File from http://abcx.com/and save or replace it in \MQL5\Files folder

 

Hi All,

Kindly let me know if it is possible to write an MQL5 code to automate this task.

A. Download csv File from http://abcx.com

B. Save or replace it in \MQL5\Files folder

I have tried with #import "shell32.dll" and #import "wininet.dll" but seems not able code them to work properly.

Any working code example is appreciated. Thank you.

 

Just add the url to the options and use webrequest()

 

Thanks for the reply. I checked few codes available on internet, but not able to apply them for my work. Appreciate if any example code can be posted here which are doing file download and saving to meta trader folder. Thanks.

 
void OnStart()
  {
   string cookie=NULL,headers;
   char post[],result[];
   int res;
//--- to enable access to the server, you should add URL "https://www.google.com/finance"
//--- in the list of allowed URLs (Main Menu->Tools->Options, tab "Expert Advisors"):
   string google_url="https://www.google.com/finance";
//--- Reset the last error code
   ResetLastError();
//--- Loading a html page from Google Finance
   int timeout=5000; //--- Timeout below 1000 (1 sec.) is not enough for slow Internet connection
   res=WebRequest("GET",google_url,cookie,NULL,timeout,post,0,result,headers);
//--- Checking errors
   if(res==-1)
     {
      Print("Error in WebRequest. Error code  =",GetLastError());
      //--- Perhaps the URL is not listed, display a message about the necessity to add the address
      MessageBox("Add the address '"+google_url+"' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION);
     }
   else
     {
      //--- Load successfully
      PrintFormat("The file has been successfully loaded, File size =%d bytes.",ArraySize(result));
      //--- Save the data to a file
      int filehandle=FileOpen("GoogleFinance.htm",FILE_WRITE|FILE_BIN);
      //--- Checking errors
      if(filehandle!=INVALID_HANDLE)
        {
         //--- Save the contents of the result[] array to a file
         FileWriteArray(filehandle,result,0,ArraySize(result));
         //--- Close the file
         FileClose(filehandle);
        }
      else Print("Error in FileOpen. Error code=",GetLastError());
     }
  }
 
Marco vd Heijden:

Thanks for your code. it is run without any error for google site but when I change the address to "https://www.forexfactory.com/calendar.php" and I add this address in the list of allowed URLs on tab 'Expert Advisors' . I eneter two address one with http and other https and run the script but it print error 5203. It seem the webrequest function have problem with some address.My MQL4 version is Build 1090.

can you help me for this error?

 
Aliakbar Kavosi:

Thanks for your code. it is run without any error for google site but when I change the address to "https://www.forexfactory.com/calendar.php" and I add this address in the list of allowed URLs on tab 'Expert Advisors' . I eneter two address one with http and other https and run the script but it print error 5203. It seem the webrequest function have problem with some address.

can you help me for this error?

Forum on trading, automated trading systems and testing trading strategies

Resolving http POST webrequests of

Alain Verleyen, 2017.08.29 20:44

Actually this is not an mql issue.

You need to learn a bit how http requests are working. To use basic authentication, you have to use request headers.


Forum on trading, automated trading systems and testing trading strategies

WebRequest to download ForexFactory News

Tim Morris, 2017.03.07 23:09

The forexfactory.net URL works OK for me. It looks like they have blocked some user-agents on the .com URL. I guess they want to move the RSS traffic over to the .net URL. I got the .com URL to work by changing the user-agent.
void OnStart()
  {
   string cookie=NULL, headers;
   string reqheaders="User-Agent: Mozilla/4.0\r\n";
   char post[],result[];
   int res;
   string url="http://www.forexfactory.com/ffcal_week_this.xml";
   ResetLastError();
   int timeout=5000;
   res=WebRequest("GET",url,reqheaders,timeout,post,result,headers);
   if(res==-1)
     {
      Print("Error in WebRequest. Error code  =",GetLastError());
      //--- Perhaps the URL is not listed, display a message about the necessity to add the address
      MessageBox("Add the address '"+url+"' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION);
     }
   else
     {
      //--- Load successfully
      PrintFormat("The file has been successfully loaded, File size =%d bytes.",ArraySize(result));
      //--- Save the data to a file
      int filehandle=FileOpen("test.xml",FILE_WRITE|FILE_BIN);
      //--- Checking errors
      if(filehandle!=INVALID_HANDLE)
        {
         //--- Save the contents of the result[] array to a file
         FileWriteArray(filehandle,result,0,ArraySize(result));
         //--- Close the file
         FileClose(filehandle);
        }
      else Print("Error in FileOpen. Error code=",GetLastError());
     }
  }

Please do some searches before posting. Thanks.
 
Alain Verleyen:


Please do some searches before posting. Thanks.

Thanks Alain for your help,

I study these subject . It seem the webrequest function request from MQL5.com block from Forexfactory.com for all pages except xml page. This page don't have all information and I can not get NEWS out of current week and it is not good for an expert that need to back testing .

I use windows wininet.dll functions for download any address without any error. But the problem is that the MQL5 not permit to use external DLL in programs and I can not upgarate my program in market.

Can I send a dll file for this job to MQL5 for verify and confirmation and then use of them to my projects?

Can the MQL5 cooperate with Forexfactory.com for this problem ? or other way? I really don't know how must find a solution for this



 
Aliakbar Kavosi:

Thanks Alain for your help,

I study these subject . It seem the webrequest function request from MQL5.com block from Forexfactory.com for all pages except xml page. This page don't have all information and I can not get NEWS out of current week and it is not good for an expert that need to back testing .

I use windows wininet.dll functions for download any address without any error. But the problem is that the MQL5 not permit to use external DLL in programs and I can not upgarate my program in market.

Can I send a dll file for this job to MQL5 for verify and confirmation and then use of them to my projects?

Can the MQL5 cooperate with Forexfactory.com for this problem ? or other way? I really don't know how must find a solution for this



Using DLLs is prohibited in any way, even using WebRequest is prohibited in some ways when publishing products on the market.

If you can browse the web resource by any browser, you should be able to do that with WebRequest too. So try simulating browser behavior with WebRequest.
 
Aliakbar Kavosi:

Thanks Alain for your help,

I study these subject . It seem the webrequest function request from MQL5.com block from Forexfactory.com for all pages except xml page. This page don't have all information and I can not get NEWS out of current week and it is not good for an expert that need to back testing .

I use windows wininet.dll functions for download any address without any error. But the problem is that the MQL5 not permit to use external DLL in programs and I can not upgarate my program in market.

Can I send a dll file for this job to MQL5 for verify and confirmation and then use of them to my projects?

Can the MQL5 cooperate with Forexfactory.com for this problem ? or other way? I really don't know how must find a solution for this



There is nothing special with WebRequest(), it's just a wrapper around WinAPI. You may have to change some headers (like user agent, see above post).

Show your code if you need coding help.

 

Your question was:

Download csv File from http://abcx.com/and save or replace it in \MQL5\Files folder

Webrequest does this.

Then all of a sudden you start to talk about:

https://www.forexfactory.com/calendar.php

This is not an csv file.

How are you planning to save a php file?

Of course this does not work.

You can save html files binary files csv files txt files and etc

Reason: