0

I am tring to use the Metatrader Manager API to unarchive the user. I have the admin permission to do this process and I can unarchive users from the admin application. And the following is my code for the unarchive process,

public ClrWrapper Metatrader(string host, int login, string password, string apiPath)
{
    var param = new ConnectionParameters()
    {
        Server = host,
        Login = login,
        Password = password
    };
    return metatrader = new ClrWrapper(param, apiPath);
}

public void UnarchiveAccounts(int[] logins)
{
    StringBuilder builder = new StringBuilder();
    foreach(int login in logins)
    {

        if (login!=0)
        { builder.Append(login).Append(","); }

    }
    string request = builder.ToString();

    IList<BackupInfo> userInfo = metatrader.BackupInfoUsers(2);  
    IList<BackupInfo> orderInfo = metatrader.BackupInfoOrders(2);  

    IList<UserRecord> userRecords = new List<UserRecord>();
    List<TradeRecord> tradeRecords = new List<TradeRecord>();
    foreach (BackupInfo userInfoItem in userInfo)
    {
        if (userInfoItem.File.ToUpper().Contains("ARCHIVE"))
        {
            userRecords = userRecords.Concat(metatrader.BackupRequestUsers(userInfoItem.File, request)).ToList();

            if (userRecords.Count >= logins.Length)
            {
                break;
            }
        }

    }

    int userUnarchiveFlag = metatrader.BackupRestoreUsers(userRecords);
    string error = metatrader.ErrorDescription(userUnarchiveFlag);

    // restore trades
    foreach(BackupInfo orderInfoItem in orderInfo)
    {
        if(orderInfoItem.File.ToUpper().Contains("ARCHIVE"))
        {
            tradeRecords.AddRange(metatrader.BackupRequestOrders(orderInfoItem.File, request));
        }

    }

    IList<TradeRestoreResult> tradeRestore = metatrader.BackupRestoreOrders(tradeRecords);

}

I didn't use the pumping mode, the error code for BackupRestoreUser is 3, which means invalid paramater; the error code for BackupRestoreTrades is 2, which means common error. I've tried to solve this for hours but couldn't make any progress. I do appreciate any help from you guys.

Thank you!

tina
  • 31
  • 1
  • 6
  • Did you try to restore accounts from single file. What I suspect, you might have same account in different archives and that's what causing error. That's the first thing, and second try to restore 1-2 accounts, not all from the archieve, as far as I remember request have some limitations on it's length – Uriil Sep 20 '17 at 17:46
  • Hi, thank you for your reply, for testing I used only one login as the input but got the error above. And we finally solved this by changing the code we forked recently in the wrapper, the function BackupRestoreOrders didn't assign the length of the user list to the total and passed 0 to call the BackupRestoreUsers in C++, which made this "invalid parameter" error. – tina Sep 21 '17 at 02:22

0 Answers0