/// <summary> /// Downloads the financial advisor configuration /// </summary> /// <param name="client">The IB client</param> /// <returns>true if successfully completed</returns> public bool Load(InteractiveBrokersClient client) { var faResetEvent = new AutoResetEvent(false); var xmlGroups = string.Empty; var xmlProfiles = string.Empty; var xmlAliases = string.Empty; EventHandler <ReceiveFaEventArgs> handler = (sender, e) => { switch (e.FaDataType) { case Constants.FaAliases: xmlAliases = e.FaXmlData; break; case Constants.FaGroups: xmlGroups = e.FaXmlData; break; case Constants.FaProfiles: xmlProfiles = e.FaXmlData; break; } faResetEvent.Set(); }; client.ReceiveFa += handler; // request FA Aliases Log.Trace("InteractiveBrokersBrokerage.DownloadFinancialAdvisorConfiguration(): requesting FA Aliases"); client.ClientSocket.requestFA(Constants.FaAliases); if (!faResetEvent.WaitOne(2000)) { Log.Trace("InteractiveBrokersBrokerage.DownloadFinancialAdvisorConfiguration(): Download FA Aliases failed. Operation took longer than 2 seconds."); return(false); } // request FA Groups Log.Trace("InteractiveBrokersBrokerage.DownloadFinancialAdvisorConfiguration(): requesting FA Groups"); client.ClientSocket.requestFA(Constants.FaGroups); if (!faResetEvent.WaitOne(2000)) { Log.Trace("InteractiveBrokersBrokerage.DownloadFinancialAdvisorConfiguration(): Download FA Groups failed. Operation took longer than 2 seconds."); return(false); } // request FA Profiles Log.Trace("InteractiveBrokersBrokerage.DownloadFinancialAdvisorConfiguration(): requesting FA Profiles"); client.ClientSocket.requestFA(Constants.FaProfiles); if (!faResetEvent.WaitOne(2000)) { Log.Trace("InteractiveBrokersBrokerage.DownloadFinancialAdvisorConfiguration(): Download FA Profiles failed. Operation took longer than 2 seconds."); return(false); } client.ReceiveFa -= handler; // load FA configuration var serializer = new XmlSerializer(typeof(List <AccountAlias>), new XmlRootAttribute("ListOfAccountAliases")); using (var stringReader = new StringReader(xmlAliases)) { _accountAliases = (List <AccountAlias>)serializer.Deserialize(stringReader); Log.Trace("InteractiveBrokersBrokerage.DownloadFinancialAdvisorConfiguration(): FA Aliases found: " + _accountAliases.Count); } serializer = new XmlSerializer(typeof(List <Group>), new XmlRootAttribute("ListOfGroups")); using (var stringReader = new StringReader(xmlGroups)) { _accountGroups = (List <Group>)serializer.Deserialize(stringReader); Log.Trace("InteractiveBrokersBrokerage.DownloadFinancialAdvisorConfiguration(): FA Groups found: " + _accountGroups.Count); } serializer = new XmlSerializer(typeof(List <AllocationProfile>), new XmlRootAttribute("ListOfAllocationProfiles")); using (var stringReader = new StringReader(xmlProfiles)) { _allocationProfiles = (List <AllocationProfile>)serializer.Deserialize(stringReader); Log.Trace("InteractiveBrokersBrokerage.DownloadFinancialAdvisorConfiguration(): FA Profiles found: " + _allocationProfiles.Count); } // save the master account code var entry = _accountAliases.FirstOrDefault(x => InteractiveBrokersBrokerage.IsMasterAccount(x.Account)); if (entry == null) { throw new Exception("The Financial Advisor master account was not found."); } MasterAccount = entry.Account; return(true); }