MT5 Authentication Process Build Through PHP, Laravel

MQL5 Integración PHP

Tarea técnica

Currently we are already implemented this documented process, but the issue is going on whenever we are requesting, each time it’s creates a new connection and there’s approximate more then 50000 to 100000 request each day. So, we need to build a efficient authentication process, by which one connection will be build up and all other requests will be managed by that.


Here’s the reference links of their authentication documentation
https://support.metaquotes.net/en/docs/mt5/api/webapi_rest_authentication

And below one is for maintaining the connection
https://support.metaquotes.net/en/docs/mt5/api/webapi_pings 


We are seeking an experienced and skilled developer to join our team as an MT5 Server Authentication Developer. In this role, you will be responsible for implementing and maintaining the authentication process for our MetaTrader 5 (MT5) server. You will work closely with our development team to ensure a secure and efficient authentication process for our trading platform.


We are looking for:

  • Implement the authentication process for sending commands to the MT5 server.

  • Develop and integrate the necessary API endpoints (/api/auth/start, /api/auth/answer) for authentication.

  • Collaborate with the team to ensure seamless authentication across different stages of the process.

  • Generate and handle random sequences and hash passwords according to the provided algorithm.

  • Work on client-side and server-side authentication procedures.

  • Ensure maximum security and encryption for authentication and data exchange.

  • Maintain connection to the server by sending "ping" commands to prevent connection loss.

  • Implement connection status checks and handling of empty packets to maintain the connection.

  • Troubleshoot and resolve any issues related to authentication and connection maintenance.


Here's the codebase we followed in php

<?php
 
class CMT5Request
{
  private $m_curl=null;
  private $m_server="";
 
  public function Init($server)
  {
    $this->Shutdown();
    if($server==null)
      return(false);
    $this->m_curl=curl_init();
    if($this->m_curl==null)
      return(false);
    //---
    curl_setopt($this->m_curl,CURLOPT_SSL_VERIFYPEER,0); // comment out this line if you use self-signed certificates
    curl_setopt($this->m_curl,CURLOPT_MAXCONNECTS,1); // one connection is used
    curl_setopt($this->m_curl, CURLOPT_HTTPHEADER,array('Connection: Keep-Alive'));
    //---
    $this->m_server=$server;
    //---
    return(true);
  }
 
  public function Shutdown()
  {
    if($this->m_curl!=null)
        curl_close($this->m_curl);
    $this->m_curl=null;
  }
 
  public function Get($path)
  {
    if($this->m_curl==null)
      return(false);
    curl_setopt($this->m_curl,CURLOPT_POST,false);
    curl_setopt($this->m_curl,CURLOPT_URL,'https://'.$this->m_server.$path);
    curl_setopt($this->m_curl,CURLOPT_RETURNTRANSFER,true);
    $result=curl_exec($this->m_curl);
    if($result==false)
    {
      echo 'Curl GET error: '.curl_error($this->m_curl);
      return(false);
    }
    $code=curl_getinfo($this->m_curl,CURLINFO_HTTP_CODE);
    if($code!=200)
    {
      echo 'Curl GET code: '.$code;
      return(false);
    }
    return($result);
  }
 
  public function Post($path, $body)
  {
    if($this->m_curl==null)
      return(false);
    curl_setopt($this->m_curl,CURLOPT_POST,true);
    curl_setopt($this->m_curl,CURLOPT_URL, 'https://'.$this->m_server.$path);
    curl_setopt($this->m_curl,CURLOPT_POSTFIELDS,$body);
    curl_setopt($this->m_curl,CURLOPT_RETURNTRANSFER,true);
    $result=curl_exec($this->m_curl);
    if($result==false)
    {
      echo 'Curl POST error: '.curl_error($this->m_curl);
      return(false);
    }
    $code=curl_getinfo($this->m_curl,CURLINFO_HTTP_CODE);
    if($code!=200)
    {
      echo 'Curl POST code: '.$code;
      return(false);
    }
    return($result);
  }  
 
  public function Auth($login, $password, $build, $agent)
  {
    if($this->m_curl==null)
      return(false);    
    //--- send start
    $path='/api/auth/start?version='.$build.'&agent='.$agent.'&login='.$login.'&type=manager';
    $result=$this->Get($path);
    if($result==false)
      return(false);
    $auth_start_answer=json_decode($result);
    if((int)$auth_start_answer->retcode!=0)
    {
      echo 'Auth start error : '.$auth_start_answer.retcode;
      return(false);
    }
    //--- Getting code from the hex string
    $srv_rand=hex2bin($auth_start_answer->srv_rand);
    //--- Hash for the response
    $password_hash=md5(mb_convert_encoding($password,'utf-16le','utf-8'),true).'WebAPI';
    $srv_rand_answer=md5(md5($password_hash,true).$srv_rand);
    //--- Random string for the MetaTrader 5 server
    $cli_rand_buf=random_bytes(16);
    $cli_rand=bin2hex($cli_rand_buf);
    //--- Sending the response
    $path='/api/auth/answer?srv_rand_answer='.$srv_rand_answer.'&cli_rand='.$cli_rand;
    $result=$this->Get($path);
    if($result==false)
      return(false);
    $auth_answer_answer=json_decode($result);
    if((int)$auth_answer_answer->retcode!=0)
    {
      echo 'Auth answer error : '.$auth_answer_answer.retcode;
      return(false);
    }
    //--- Calculating a correct server response for the random client sequence
    $cli_rand_answer=md5(md5($password_hash,true).$cli_rand_buf);
    if($cli_rand_answer!=$auth_answer_answer->cli_rand_answer)
    {
      echo 'Auth answer error : invalid client answer';
      return(false);
    }
    //--- Everything is done
    return(true);
  }
}
 
// Example of use
$request = new CMT5Request();
// Authenticate on the server using the Auth command
if($request->Init('my.broker.com:443') && $request->Auth(1000,"Password",1985,"WebManager"))
{
  // Let us request the symbol named TEST using the symbol_get command
  $result=$request->Get('/api/symbol/get?symbol=TEST');
  if($result!=false)
  {
    echo $result;
    $json=json_decode($result);
    if((int)$json->retcode==0)
    {
      $symbol=$json->answer;
      //--- Changing the description
      $symbol->Description='My Description';
      // Sending changes to the server using the symbol_add command
      $result=$request->Post('/api/symbol/add',json_encode($symbol));
      if($result!=false)
        echo $result;
    }
  }
}
$request->Shutdown();
?>


Han respondido

1
Desarrollador 1
Evaluación
(19)
Proyectos
26
27%
Arbitraje
3
0% / 100%
Caducado
2
8%
Libre
2
Desarrollador 2
Evaluación
(57)
Proyectos
72
22%
Arbitraje
13
46% / 15%
Caducado
5
7%
Libre
3
Desarrollador 3
Evaluación
(7)
Proyectos
12
42%
Arbitraje
1
0% / 0%
Caducado
0
Libre
4
Desarrollador 4
Evaluación
(13)
Proyectos
31
68%
Arbitraje
2
0% / 0%
Caducado
10
32%
Trabaja
5
Desarrollador 5
Evaluación
(7)
Proyectos
6
0%
Arbitraje
5
0% / 100%
Caducado
1
17%
Libre
Solicitudes similares
Hello, i need a good programmer; to code an EA to trade the most productive forex pairs (mainly 2 for the day, and 2 for the night+gold), the strategy is based on the use of one moving average and the rsi, thank you in advance
see trade open on every tick seconde ok forex pair us us30 if is current running at 40170.00 so open 2 trade buy stop and sell stop both in every tick pending order of buy stop will 40171.00 and sell stop pending order will be 40169.00 buy stop will open at 40171.00 and tp will be 40173.00 and SL will be 40169.50 ok if buy stop hit sell stop order automatically will be close now if sell stop order open at 40169.00 so
Looking for a programmer to code EA for Buy Stop/Sell Stop HFT Trading designed for Ger40 EA must be able to trade on live account and Dll must be used for EA speed slippage control and spread filter
i want a forex robot that will read chats and enter trades on its oown. i want it to be able to use all trading strategies and partterns. good risky manegmemt, i want it to forcuse on Gold and and all major forex pairs. i want it to use stop loses and take profits as the market might change direction anytime. i want to work on both mt5 and mt4
Saya memerlukan Expert Advisor berdasarkan sinyal AOX. Itu harus memiliki pemeriksaan dan penanganan kesalahan operasi perdagangan. Kriteria utama pembukaan dan posisi penutupan: ■ arah rata-rata bergerak ■ harga lebih tinggi dari bar sebelumnya. Lot perdagangan adalah parameter masukan
I need to automate the supertrend indicator on ctrader with partial tp and sl. I already have a sort of script (without tp and sl) but when I go to compile it gives me an error. would you be able to make it work by adding the partial tp and sl
Skarito98 30 - 100 USD
Always stay winning and survive....we all want a better life now this is a chance someone can take,to change their lives for the better.No one is supposed to suffer in this world,we create and invert new things and come up with ideas to solve situations we come across especially when it comes to finance. We all need better things in life and God want good things for us
I believe in Robotics as a major artificial intellect to function of growth of business.Therefore if you script there is a likelihood of bringing economies of scale.The retrospective of the dynamics of indulgence of work can be economics of scale
there I hope you're doing well I want to convert the tradingview indicator to make an indicator for mt5. And in that, I want to make an automatic robot on the base of the indicator. I have the pine script of that indicator
Need ea according to stochastic divergence (both hidden and regular) plus candlestick flip .. need for experinced developers to complete my order with 99percent accuracy. So bet for it the budged is fixed and other plugins will be added in the v2

Información sobre el proyecto

Presupuesto
100+ USD
Para el ejecutor
90 USD