Download MetaTrader 5

recover news from forex factory

To add comments, please log in or register
Patrick Chalindar
241
Patrick Chalindar  

Hi,

I wanted to know what address I have to use in a code for recover news from forexfactory. Until now i used this and it worked

<code>

string url="http://www.forexfactory.com/ffcal_week_this.xml";
ResetLastError();
int timeout=5000;
res=WebRequest("GET",url,cookie,NULL,timeout,post,0,result,headers);

int filehandle=FileOpen("news.htm",FILE_WRITE|FILE_BIN);
FileWriteArray(filehandle,result,0,ArraySize(result));
FileClose(filehandle);

</code>

From this I recovered a xml file but now I receive "forbidden"!

This code works, I think :), because if I change the adress and try with google finance, I recove datas.



Thanks in advance for your help.

Ps: sorry but I didn't find the tag code.

Stanislav Korotky
23359
Stanislav Korotky  

Look here.

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());
     }
  }

To add comments, please log in or register