/// <summary> /// Gets all possible combinations for the given parameters /// </summary> /// <param name="args">ctor arguments to create combinations with</param> /// <param name="conditionalParameters">contains info for the conditional parameters</param> /// <param name="conditionalIndex">index of conditional parameter to be used for iterations</param> private void GetAllIterations(object[] args, Tuple <int, string, string>[] conditionalParameters, int conditionalIndex) { try { // get index of parameter to be incremented int index = conditionalParameters[conditionalIndex].Item1; // Get end value for the parameter decimal endPoint; if (!decimal.TryParse(conditionalParameters[conditionalIndex].Item2, out endPoint)) { return; } // Get increment value to be used decimal increment; if (!decimal.TryParse(conditionalParameters[conditionalIndex].Item3, out increment)) { return; } // Get Orignal Value decimal orignalValue = Convert.ToDecimal(args[index]); // Iterate through all combinations for (decimal i = 0; ; i += increment) { // Modify parameter value var parameter = orignalValue + i; if (parameter > endPoint) { break; } // Convert string value to required format var value = LoadCustomStrategy.GetParametereValue(parameter.ToString(), _parmatersDetails[index].ParameterType.Name); // Update arguments array args[index] = value; // Check if the combination is already present if (!ValueAdded(args, _ctorArguments, index)) { // Add the updated arguments to local map _ctorArguments.Add(args.Clone() as object[]); // Get further iterations if if (conditionalIndex > 0) { GetAllIterations(args.Clone() as object[], conditionalParameters, conditionalIndex - 1); } } } } catch (Exception exception) { _asyncClassLogger.Error(exception, _type.FullName, "IterateParameters"); } }
/// <summary> /// Verifies the selected arguments to initialize the strategy /// </summary> /// <param name="selectedArgs">Constructor Arguments</param> private object[] VerfiySelectedArguments(object[] selectedArgs) { try { object[] ctrArgs = new object[selectedArgs.Length]; foreach (ParameterInfo parameterInfo in _parmatersInfo) { object value; // Convert string value to required format value = LoadCustomStrategy.GetParametereValue(selectedArgs[parameterInfo.Position].ToString(), parameterInfo.ParameterType.Name); if (value == null) { if (Logger.IsInfoEnabled) { Logger.Info("Parameter was not in the correct format. Rquired: " + parameterInfo.ParameterType.Name + " Provided value: " + selectedArgs[parameterInfo.Position], _type.FullName, "VerfiySelectedArguments"); } return(null); } // Add to value to arguments array ctrArgs[parameterInfo.Position] = value; } // Return verified arguments return(ctrArgs); } catch (Exception exception) { Logger.Error(exception, _type.FullName, "VerfiySelectedArguments"); return(null); } }
/// <summary> /// Verifies the arguments on selected index to initialize the strategy /// </summary> /// <param name="index">Index of the arguments to verify</param> private object[] VerfiySelectedArgumentsOnGivenIndex(int index) { try { string[] parameters; if (_selectedConstuctorParameters.TryGetValue(index, out parameters)) { object[] ctrArgs = new object[parameters.Length]; foreach (ParameterInfo parameterInfo in _parmatersInfo) { object value; // Convert string value to required format value = LoadCustomStrategy.GetParametereValue(parameters[parameterInfo.Position], parameterInfo.ParameterType.Name); if (value == null) { if (Logger.IsInfoEnabled) { Logger.Info("Parameter was not in the correct format. Rquired: " + parameterInfo.ParameterType.Name + " Provided value: " + parameters[parameterInfo.Position], _type.FullName, "VerfiySelectedArgumentsOnGivenIndex"); } return(null); } // Add to value to arguments array ctrArgs[parameterInfo.Position] = value; } // Return verified arguments return(ctrArgs); } if (Logger.IsInfoEnabled) { Logger.Info("Specified parameters could not be found.", _type.FullName, "VerfiySelectedParameterValues"); } return(null); } catch (Exception exception) { Logger.Error(exception, _type.FullName, "VerfiySelectedArgumentsOnGivenIndex"); return(null); } }
/// <summary> /// Get parameter values /// </summary> /// <param name="input"></param> /// <param name="type"></param> /// <returns></returns> public static object GetParametereValue(string input, string type) { return(LoadCustomStrategy.GetParametereValue(input, type)); }
static void Main(string[] args) { //IList<string> namesOfFiles = new List<string>(); //DateTime startTime = new DateTime(2013,8,25); //DateTime endTime = new DateTime(2013,8,30); //string specificFolder = @"C:\aurora\ATS\Saved Data"; //string providerName = "InteractiveBrokers"; //string[] directoryNames = new string[3]; //// Get possible directory path for bars created with BID Price //directoryNames[0] = specificFolder + "\\" + providerName + "\\" + "AAPL" + "\\Bar\\" + // TradeHubConstants.BarFormat.TIME + "\\" + TradeHubConstants.BarPriceType.BID; //// Get possible directory path for bars created with ASK Price //directoryNames[1] = specificFolder + "\\" + providerName + "\\" + "AAPL" + "\\Bar\\" + // TradeHubConstants.BarFormat.TIME + "\\" + TradeHubConstants.BarPriceType.ASK; //// Get possible directory path for bars created with LAST Price //directoryNames[2] = specificFolder + "\\" + providerName + "\\" + "AAPL" + "\\Bar\\" + // TradeHubConstants.BarFormat.TIME + "\\" + TradeHubConstants.BarPriceType.LAST; //// Traverse all possible directories //foreach (string directoryName in directoryNames) //{ // var directory = new DirectoryInfo(directoryName); // // Find required files if the path exists // if (directory.Exists) // { // // Find all possible subfolders in the given directory // IEnumerable<string> subFolders = directory.GetDirectories().Select(subDirectory => subDirectory.Name); // // Use all sub-directories to find files with required info // foreach (string subFolder in subFolders) // { // DateTime tempStartTime = new DateTime(startTime.Ticks); // while (tempStartTime.Date <= endTime.Date) // { // var filename = tempStartTime.ToString("yyyyMMdd") + ".txt"; // // Get the File paths of required date. // string[] path = Directory.GetFiles(directoryName + "\\" + subFolder, // filename, SearchOption.AllDirectories); // if (path.Any()) // { // namesOfFiles.Add(path[0]); // } // tempStartTime = tempStartTime.AddDays(1); // } // } // } //} //foreach (string namesOfFile in namesOfFiles) //{ // System.Console.WriteLine(namesOfFile); //} var strategyDetails = LoadCustomStrategy.GetConstructorDetails("TradeHub.StrategyRunner.SampleStrategy.dll"); if (strategyDetails != null) { var strategyType = strategyDetails.Item1; var ctorDetails = strategyDetails.Item2; object[] ctrArgs = new object[ctorDetails.Length]; foreach (ParameterInfo parameterInfo in ctorDetails) { object value; do { System.Console.WriteLine("Enter " + parameterInfo.ParameterType.Name + " value for: " + parameterInfo.Name); var input = System.Console.ReadLine(); value = LoadCustomStrategy.GetParametereValue(input, parameterInfo.ParameterType.Name); } while (value == null); ctrArgs[parameterInfo.Position] = value; } LoadCustomStrategy.CreateStrategyInstance(strategyType, ctrArgs); } while (true) { } }