/// <summary>
        /// Initializes necessary fields and parameters
        /// </summary>
        /// <param name="strategyType">User Strategy Type</param>
        /// <param name="ctorArguments">Constructor arguments to initialize strategy</param>
        private void Initialize(Type strategyType, object[] ctorArguments)
        {
            _manualReset = new ManualResetEvent(false);
            _logger      = new AsyncClassLogger("StrategyExecutorGeneticAlgo");

            // Save Strategy Type
            _strategyType = strategyType;

            //Save Arguments
            _ctorArguments = ctorArguments;

            // Set Logging levels
            _logger.SetLoggingLevel();

            // Get new strategy instance
            var strategyInstance = LoadCustomStrategy.CreateStrategyInstance(_strategyType, _ctorArguments);

            if (strategyInstance != null)
            {
                // Cast to TradeHubStrategy Instance
                _tradeHubStrategy = strategyInstance as TradeHubStrategy;

                InitializeStrategyListeners();
                OverrideMarketRequestCalls();
                OverrideOrderRequestCalls();
            }
        }
Пример #2
0
        /// <summary>
        /// Starts custom strategy execution
        /// </summary>
        public void ExecuteStrategy()
        {
            try
            {
                // Verify Strategy Instance
                if (_tradeHubStrategy == null)
                {
                    //create DB strategy
                    Strategy strategy = new Strategy();
                    strategy.Name          = _strategyType.Name;
                    strategy.StartDateTime = DateTime.Now;

                    // Get new strategy instance
                    var strategyInstance = LoadCustomStrategy.CreateStrategyInstance(_strategyType, CtorArguments);

                    if (strategyInstance != null)
                    {
                        // Cast to TradeHubStrategy Instance
                        _tradeHubStrategy = strategyInstance as TradeHubStrategy;
                    }

                    if (_tradeHubStrategy == null)
                    {
                        if (_asyncClassLogger.IsInfoEnabled)
                        {
                            _asyncClassLogger.Info("Unable to initialize Custom Strategy: " + _strategyType.FullName, _type.FullName, "ExecuteStrategy");
                        }

                        // Skip execution of further actions
                        return;
                    }

                    // Set Strategy Name
                    _tradeHubStrategy.StrategyName = LoadCustomStrategy.GetCustomClassSummary(_strategyType);

                    // Register Events
                    _tradeHubStrategy.OnStrategyStatusChanged += OnStrategyStatusChanged;
                    _tradeHubStrategy.OnNewExecutionReceived  += OnNewExecutionReceived;
                }

                if (_asyncClassLogger.IsInfoEnabled)
                {
                    _asyncClassLogger.Info("Executing user strategy: " + _strategyType.FullName, _type.FullName, "ExecuteStrategy");
                }

                //Overriding if running on simulated exchange
                ManageBackTestingStrategy();

                // Start Executing the strategy
                _tradeHubStrategy.Run();
            }
            catch (Exception exception)
            {
                _asyncClassLogger.Error(exception, _type.FullName, "ExecuteStrategy");
            }
        }
Пример #3
0
 /// <summary>
 /// Create instance of strategy
 /// </summary>
 /// <param name="type"></param>
 /// <param name="ctrArgs"></param>
 /// <returns></returns>
 public static object CreateStrategyInstance(Type type, object[] ctrArgs)
 {
     return(LoadCustomStrategy.CreateStrategyInstance(type, ctrArgs));
 }
Пример #4
0
        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)
            {
            }
        }