private void BuildManagers() { AccountManager = new AccountManager(APIWrapper); ManagedSecuritiesManager = new ManagedSecuritiesManager(APIWrapper); List <ManagedSecurity> activeUNLList; UNLManagerDic = new Dictionary <string, SimpleBaseLogic>(); using (var session = DBSessionFactory.Instance.OpenSession()) { activeUNLList = session.Query <ManagedSecurity>() .Where(contract => contract.IsActive && contract.OptionChain).ToList(); } foreach (var managedSecurity in activeUNLList) { var unlManager = new UNLManager(managedSecurity, APIWrapper, Distributer); UNLManagerDic.Add(managedSecurity.Symbol, unlManager); unlManager.PositionNeedToOptimized += UNLManagerOnPositionNeedToOptimized; } MarginManager = new MarginManager(); DbWriter = new DBWriter(Configurations.Application.DBWritePeriod); Distributer.SetManagers(UNLManagerDic, AccountManager, ManagedSecuritiesManager, DbWriter, MarginManager); //UIDataManager = new UIDataManager(); }
private void CalculateAllRequierdMargin() { foreach (var marginData in MarginDataDic.Values) { CalculateUNLRequierdMargin(marginData.Symbol); Distributer.Enqueue(marginData); } }
private void StartManagers() { AccountManager.Start(); ManagedSecuritiesManager.Start(); UNLManagerDic.Values.ForEach(mgr => mgr.Start()); DbWriter.Start(); Distributer.Start(); }
public void UpdateMaxMargin(List <ManagedSecurity> managedSecuritiesList) { foreach (var managedSecurity in managedSecuritiesList) { if (MarginDataDic.ContainsKey(managedSecurity.Symbol) == false) { continue; } var marginData = MarginDataDic[managedSecurity.Symbol]; if (marginData == null) { var ex = new ArgumentNullException(nameof(marginData)); Logger.Error($"There is no margin data for '{managedSecurity.Symbol}'!", ex); continue; } marginData.MarginMaxAllowed = managedSecurity.MarginMaxAllowed; Distributer.Enqueue(marginData); } }
/// <summary> /// Must be called once application is up by the main GUI object /// </summary> private void InitializeAppManager() { ConfigHandler configHandler = new ConfigHandler(); //Do the following just in case you want to create the configuration from scratch: WriteConfigurationFromScratch(configHandler); Configurations = configHandler.ReadConfig(); //var a = Configurations.Trading.UNLSymbolsListForTrading(); AllConfigurations.AllConfigurationsObject = Configurations; Distributer = new Distributer(); //Change the wrapper object according to the actual broker, //for now it's Interactive Broker. APIWrapper = new IBApiWrapper( Configurations.Application.DefaultHost, Configurations.Application.AppPort, Configurations.Application.AppClientId, Distributer, Configurations.Application.MainAccount); }