How to communicate with the xtb API?

 

I am trying to copy trades from my MT5 account to xStation account using the XTB API.
The Problem is that I don't understand how to communicate with API.

I have tried using socket but I am unable to send an HTTP request with given command arguments, so I need help doing that.

I would like to know if it is possible to communicate without the Socket.

I will appreciate all efforts to help

The code I am trying to use is below:

bool ExtTLS = true;
bool HTTPRecv(int socket,uint timeout)
  {
   char   rsp[];
   string result;
   uint   timeout_check=GetTickCount()+timeout;
//--- read data from sockets till they are still present but not longer than timeout
   do
     {
      uint len=SocketIsReadable(socket);
      if(len)
        {
         int rsp_len;
         //--- various reading commands depending on whether the connection is secure or not
         if(ExtTLS)
            rsp_len=SocketTlsRead(socket,rsp,len);
         else
            rsp_len=SocketRead(socket,rsp,len,timeout);
         //--- analyze the response
         if(rsp_len>0)
           {
            result+=CharArrayToString(rsp,0,rsp_len);
            //--- print only the response header
            int header_end=StringFind(result,"\r\n\r\n");
            if(header_end>0)
              {
               Print("HTTP answer header received:");
               Print(result);
               return(true);
              }
           }
        }
     }
   while(GetTickCount()<timeout_check && !IsStopped());
   return(false);
  }




//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool HTTPSend(int socket,string request)
  {
   char req[];
   int  len=StringToCharArray(request,req)-1;
   if(len<0)
      return(false);
//--- if secure TLS connection is used via the port 443
   if(ExtTLS)
      return(SocketTlsSend(socket,req,len)==len);
//--- if standard TCP connection is used
   return(SocketSend(socket,req,len)==len);
  }
//+------------------------------------------------------------------+
void OpenTrade()
  {
  
   string com = "{\"command\": \"logout\"}";
   string wsRequest = "POST / HTTP/1.1\r\nHost:xapi.xtb.com\r\n\r\n";
   int conn = SocketCreate();
   SocketConnect(conn,"wss://ws.xtb.com/demo",443,1000);
   Print(HTTPSend(conn,wsRequest));
   Print(HTTPRecv(conn,1000));
  }
//+------------------------------------------------------------------+
 
Saksham Solanki:

I am trying to copy trades from my MT5 account to xStation account using the XTB API.
The Problem is that I don't understand how to communicate with API.

I have tried using socket but I am unable to send an HTTP request with given command arguments, so I need help doing that.

I would like to know if it is possible to communicate without the Socket.

I will appreciate all efforts to help

The code I am trying to use is below:

Checking this API documentation, it's using a WebSocket through SSL, so you need to learn how to code that. It can't be done without a Socket in MQL.
 
Alain Verleyen #:
Checking this API documentation, it's using a WebSocket through SSL, so you need to learn how to code that. It can't be done without a Socket in MQL.

could you by any chance check the HTTPsend function, the requests sent return 500 server internal error for valid commands

 

Could you solve your problem friend?

 
Saksham Solanki:

I am trying to copy trades from my MT5 account to xStation account using the XTB API.
The Problem is that I don't understand how to communicate with API.

I have tried using socket but I am unable to send an HTTP request with given command arguments, so I need help doing that.

I would like to know if it is possible to communicate without the Socket.

I will appreciate all efforts to help

The code I am trying to use is below:

Hello. If you are interested in Copy utility from MT5 to xStation DM me