public static void LoadAccounts() { string response = HTTPRequest(CarbonFX.TraderListURL); Console.WriteLine("Requesting Trader List from API: " + CarbonFX.TraderListURL); JObject json = JObject.Parse(response); Console.WriteLine("Server response: {0}", json["response"]); IList accounts = (IList)json["data"]["accounts"]; CarbonFX.AccountList = new List <TraderAccount>(); foreach (JToken account in accounts) { TraderAccount traderAccount = Newtonsoft.Json.JsonConvert.DeserializeObject <TraderAccount>(account.ToString()); CarbonFX.AccountList.Add(traderAccount); } Console.WriteLine("{0} Trader accounts loaded", CarbonFX.AccountList.Count); return; //Console.WriteLine("data: " + response) //dynamic accountObj = Newtonsoft.Json.JsonConvert.DeserializeObject(response); //Console.WriteLine("response: {0}", accountObj); /** * foreach(var name in accountObj.GetType().GetProperties()) * { * Console.WriteLine("{0}",name); * }**/ }
public static void Main(string[] args) { // //ConfigurationManager.AppSettings.Set("nj4x_activation_key", "271143354"); ConfigurationManager.AppSettings.Set("nj4x_activation_key", "1735263226"); LoadAccounts(); TraderAccount MasterTrader = new TraderAccount(); List <TraderAccount> SlaveAccounts = new List <TraderAccount>(); foreach (TraderAccount account in CarbonFX.AccountList) { string type = @""; switch (account.trader_type) { case TRADER_TYPE_SLAVE: type = "[slave]"; SlaveAccounts.Add(account); break; case TRADER_TYPE_MASTER: type = "[master]"; MasterTrader = account; break; } Console.WriteLine("Trader trader_name: " + account.trader_name + " " + type); } if (MasterTrader.trader_type == 1) { Console.WriteLine("Found master ID: " + MasterTrader.trader_id + " " + MasterTrader.trader_name); } Console.WriteLine("{0} slaves found", SlaveAccounts.Count); Console.WriteLine("Tap ENTER to start mirror trading.."); Console.ReadLine(); //System.Environment.Exit(1); try { Console.WriteLine("Starting mirror trading.."); //var master = new Master(MasterAccount, MasterPassword, MasterBroker); //var slave = new Copier(CopierAccount, CopierPassword, CopierBroker); Console.WriteLine("Creating master terminal.."); Console.WriteLine("[M]" + MasterTrader.trader_id.ToString() + " pw:" + MasterTrader.trader_master_pw + " server:" + MasterTrader.trader_server.ToString()); var master = new Master(MasterTrader.trader_id.ToString(), MasterTrader.trader_master_pw, MasterTrader.trader_server); Console.WriteLine("Master created.."); foreach (TraderAccount account in SlaveAccounts) { Console.WriteLine("Creating slave terminal for: " + account.trader_name + " on MT4 ID: " + account.trader_id); try { var slave = new Copier(account.trader_id.ToString(), account.trader_master_pw, account.trader_server); //slave.IsReconnect = true; Console.WriteLine("[M]" + MasterTrader.trader_id.ToString() + "->[S]" + account.trader_id.ToString()); master.AddSlave(slave); } catch (Exception e) { Console.WriteLine(e); } } // //master.AddSlave(slave); // while (true) { Thread.Sleep(100000); } } catch (Exception e) { Console.WriteLine(e); } }