0

Is there any way to get history for trading account from any MT server in C# without MT terminal?

What we have:

  • Server IP address
  • Login (account number)
  • Password
user3666197
  • 1
  • 6
  • 50
  • 92
SYL
  • 337
  • 4
  • 16

2 Answers2

1

If you have manager account, you should use manager API to get it, you can create your own wrapper or use one of existing ones, for example MetaTrader4.Manager.Wrapper. For MT5 you can get official one from metaquotes.

If you have client account, there is no official way to get it, and you have to have MT4 terminal open, however, there are also some projects which might help you, ex. nj4x

Uriil
  • 11,948
  • 11
  • 47
  • 68
1

Actually yes you can get it directly as you mentioned without any APIs.
Simply you can send a socket to the MT4 server.
Here is the function from the official support website.

USERHISTORY - receiving of history of user's account.

Format:
USERHISTORY-login=_login_|password=_password_|from=_from_|to=_to_


Description:
The command is intended for receiving history of operations made within a given timeframe.

Parameters:
login - account number;
password - user's password;
from - the start of the requested timeframe in Unix timestamp format;
to - the end of the requested timeframe in Unix timestamp format.

Example:

// 1. Start Session.
$ptr=fsockopen('192.168.0.1',443);
// error check
if (!$ptr){
  echo "Connection error";
  exit;
}
// 2. Send request to MT4
fputs($ptr,"WUSERHISTORY-login=55555|password=55555|from=1117551473|to=1120143473\nQUIT\n");
// 3. Reading and processing server responses
while(!feof($ptr))
  {
   // read line of symbols
   $line=fgets($ptr,128); 
   // the symbol of the end of result transfer
   if($line=="end\r\n") break; 
   // process
   print $line; 
   $buf .= $line; 
  }
// 4. Session completion
  fclose($ptr);
user3666197
  • 1
  • 6
  • 50
  • 92
M.Hatoum
  • 69
  • 3
  • I tried translating the code to C# but it doesn't seem to work, it return 0 from server after sending this socket. Are there any changes since this post is written? What do you mean by "official support website"? I can't find any official information regarding MT4 socket documentation. Would you kindly help me find more information, your help is greatly appreciated. – Sisyphus Jul 09 '20 at 22:09