/// <summary> /// This is executed at the start of the application. /// It getts all Strategies in AlgoTraderStrategies namespace. /// It will hash the code and store it in the DB and return the usable strategies that can be used in trading /// </summary> /// <returns></returns> public static Dictionary <string, string> RefreshStrategyNamesAndIds() { Dictionary <string, string> result = new Dictionary <string, string>(); Type[] types = UC.GetTypesInNamespace(Assembly.GetExecutingAssembly(), "AT.AlgoTraderStrategies"); string baseStrategyText = UC.NormalizeSourceCode(File.ReadAllText(Global.Constants.BaseStrategyPath)); string baseStrategyMD5 = UC.MD5Hash(baseStrategyText); string baseStrategyId = baseStrategyMD5.Substring(baseStrategyMD5.Length - 6); for (int n = 0; n < types.Length; n++) { string strategyText = UC.NormalizeSourceCode(File.ReadAllText(Global.Constants.StrategiesFolder + types[n].Name + ".cs")); string strategyMD5 = UC.MD5Hash(strategyText); string strategyId = strategyMD5.Substring(strategyMD5.Length - 6) + baseStrategyId; result.Add(strategyId, types[n].Name); DBMethods.InsertStrategyName(strategyId, types[n].Name, UCDT.GetCurrentNanoUnix()); } return(result); }
public static string GetSubscribedStateChanges() { Dictionary <string, string> items = new Dictionary <string, string>(); if (Global.State.Subscriptions["schedulerRunning"].Subscribed && Global.State.Subscriptions["schedulerRunning"].IsReady()) { bool update = (Global.State.SchedulerTC.State == ThreadControlState.Running) != (bool)Global.State.Subscriptions["schedulerRunning"].State; if (update) { bool val = (Global.State.SchedulerTC.State == ThreadControlState.Running); Global.State.Subscriptions["schedulerRunning"].State = val; items.Add("schedulerRunning", UC.BoolToJSBool(val)); } } if (Global.State.Subscriptions["applicationStats"].Subscribed && Global.State.Subscriptions["applicationStats"].IsReady()) { items.Add("applicationStats", SerializerMethods.SerializeApplicationStats()); } if (Global.State.Subscriptions["threadControlTree"].Subscribed && Global.State.Subscriptions["threadControlTree"].IsReady()) { lock (Global.State.ThreadControlTreeLock) { long change = GetThreadControlTreeChangeValue(); if (change != (long)Global.State.Subscriptions["threadControlTree"].State) { Global.State.Subscriptions["threadControlTree"].State = change; items.Add("threadControlTree", SerializerMethods.SerializeThreadControlTree()); } } } // don't do this if we already have a threadControlTree if (Global.State.Subscriptions["threadControlState"].Subscribed && !items.ContainsKey("threadControlTree") && Global.State.Subscriptions["threadControlState"].IsReady()) { lock (Global.State.ThreadControlTreeLock) { string json = GetSerializedThreadControlChangedState(); string state = UC.MD5Hash(json); if (!string.IsNullOrWhiteSpace(json) && state != (string)Global.State.Subscriptions["threadControlState"].State) { Global.State.Subscriptions["threadControlState"].State = state; items.Add("threadControlState", json); } } } if (Global.State.Subscriptions["threadControlLog"].Subscribed && Global.State.Subscriptions["threadControlLog"].IsReady()) { Tools.LogObjects.Log log = RecursiveFindLogByThreadControlId(Global.State.SelectedThreadControlId, Global.State.ThreadControlTree); if (log != null && (log.ChangedSinceLastRead(Verbosity.Verbose) || Global.State.ThreadControlIdChanged)) { items.Add("threadControlLog", "\"" + System.Web.HttpUtility.JavaScriptStringEncode(log.Read(Verbosity.Verbose)) + "\""); } } Global.State.ThreadControlIdChanged = false; return(SerializerMethods.DictionarySerializedValuesToJSON(items)); }