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
Is there any way to get history for trading account from any MT server in C# without MT terminal?
What we have:
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
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);