public async System.Threading.Tasks.Task RunFileAsync(string FilePathName)
        {
            using (StreamReader file = new StreamReader(File.Open(FilePathName, FileMode.Open)))
            {
                string cronTaskListJson = file.ReadToEnd();

                _cronTasks = JsonConvert.DeserializeObject <List <CronTask> >(cronTaskListJson);
                Framework.Log("Scheduling {0} tasks...", _cronTasks.Count);
            }

            foreach (var task in _cronTasks)
            {
                Framework.Log("Scheduled {0} for {1}", task.instruction.taskType, task.Expression.NextOccurrence().ToString());
            }

            while (!_abortFlag)
            {
                foreach (var task in _cronTasks)
                {
                    if (task.CheckIfTriggered())
                    {
                        Framework.Log("Running scheduled task {0}", task.instruction.taskType);
                        _taskHandler.AddTask(task.instruction);
                    }
                }

                await System.Threading.Tasks.Task.Delay(CHECK_INTERVAL);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            IBDTaskHandler taskHandler;

            if (args.Length < 3 || args[2] != "--noib")
            {
                var controller = new IBController();
                controller.Connect();

                taskHandler = new IBDTaskHandler(controller);
            }
            else
            {
                taskHandler = new IBDTaskHandler();
            }

            BaseDataStorage storage;

            string commandArg = (args.Length > 0) ? args[0] : "default";

            switch (commandArg)
            {
            case "runtaskfile":
                storage = RunTaskFile(taskHandler, args[1]);
                break;

            case "optionwithstock":
                storage = AddStockToOptions(taskHandler, args[1]);
                break;

            case "optiontasks":
                storage = BuildOptionDownloadTasks(taskHandler, args[1], args[2]);
                break;

            case "importcsv":
                storage = ImportCsv(taskHandler, args[1]);
                break;

            case "downloadoptions":
                string secType = (args.Length > 2) ? args[3] : "STK";
                storage = DownloadOptions(taskHandler, args[1], secType);
                break;

            case "cronfile":
                storage = CronFile(taskHandler, args[1]);
                break;

            default:
                throw new Exception("No commands specified! Try runtaskfile, optionwithstock, optiontasks, importcsv, downloadoptions, cronfile");
            }

            taskHandler.BeginAsync().Wait();
            storage.FlushAsync().Wait();

            Framework.Log("Processing complete.");
#if DEBUG
            Console.ReadLine();
#endif
        }
Example #3
0
        public static SettingsData ParseConfig(string FilePathName)
        {
            var settingsData = new SettingsData();

            if (File.Exists(FilePathName))
            {
                using (StreamReader jsonFile = new StreamReader(File.OpenRead(FilePathName)))
                {
                    settingsData._SettingsData = JsonConvert.DeserializeObject <Dictionary <string, string> >(jsonFile.ReadToEnd());
                }

                Framework.Log("Loaded settings from " + FilePathName);
            }

            return(settingsData);
        }
Example #4
0
        static BaseDataStorage RunTaskFile(IBDTaskHandler TaskHandler, string FilePathName)
        {
            using (StreamReader file = new StreamReader(File.Open(FilePathName, FileMode.Open)))
            {
                string taskListJson = file.ReadToEnd();

                var tasks = JsonConvert.DeserializeObject <List <IBDTaskInstruction> >(taskListJson);
                Framework.Log("Preparing {0} tasks...", tasks.Count);

                foreach (var task in tasks)
                {
                    //taskHandler.AddTask(new IBDTaskInstruction("DownloadOptionHistoricalData") { ConId = 308142771 });
                    TaskHandler.AddTask(task);
                }
            }

            //var storage = new ElasticsearchStorage(new DataStorage.Processors.StockOptionQuoteProcessor());
            var storage = new ElasticsearchStorage(new DataStorage.Processors.DirectProcessor());

            TaskHandler.OnTaskResult += storage.ProcessTaskResult;

            return(storage);
        }
Example #5
0
 private void HandleMessage(ConnectionStatusMessage m)
 {
     this.IsConnected = m.IsConnected;
     Framework.Log(this, "Connected to IBGateway:" + m.IsConnected);
 }