{"action":"created","issue":{"url":"https://api.github.com/repos/QuantConnect/Lean/issues/137","labels_url":"https://api.github.com/repos/QuantConnect/Lean/issues/137/labels{/name}","comments_url":"https://api.github.com/repos/QuantConnect/Lean/issues/137/comments","events_url":"https://api.github.com/repos/QuantConnect/Lean/issues/137/events","html_url":"https://github.com/QuantConnect/Lean/issues/137","id":93379350,"number":137,"title":"Expose RealTimeEvent Handler to Algorithm","user":{"login":"jaredbroad","id":2243225,"avatar_url":"https://avatars.githubusercontent.com/u/2243225?v=3","gravatar_id":"","url":"https://api.github.com/users/jaredbroad","html_url":"https://github.com/jaredbroad","followers_url":"https://api.github.com/users/jaredbroad/followers","following_url":"https://api.github.com/users/jaredbroad/following{/other_user}","gists_url":"https://api.github.com/users/jaredbroad/gists{/gist_id}","starred_url":"https://api.github.com/users/jaredbroad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaredbroad/subscriptions","organizations_url":"https://api.github.com/users/jaredbroad/orgs","repos_url":"https://api.github.com/users/jaredbroad/repos","events_url":"https://api.github.com/users/jaredbroad/events{/privacy}","received_events_url":"https://api.github.com/users/jaredbroad/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-06T21:17:34Z","updated_at":"2015-07-07T00:59:49Z","closed_at":null,"body":"Added a method AddScheduledEvent which passes the events through to the RealTime handlers and can trigger events at specific times in the algorithm. \r\n\r\nEach day a setup function is called to determine the DateTime value for the event trigger. These setup functions could be made into a static helper (like Field.Close)\r\n\r\nThe RealTime handlers will need to be extended to handle multiple re-fire of the same events over a day:: or an intraday eventhandler will need to be copied for all the times its intended to be triggered.\r\n\r\nExample setup helpers could be:\r\n - Every 30mins on week days \r\n - Daily at 2pm\r\n - 20mins after market open\r\n\r\nSignature for the method:\r\nAddScheduledEvent(Func<DateTime, bool> dates, Func<DateTime, DateTime[]> times, Action callback)\r\n\r\nAdd helpers static class to QCAlgorithm:\r\nSchedule.Date.EveryWeekDay\r\nSchedule.Date.EveryDay\r\nSchedule.Dates.Specific(DayOfWeek)\r\nSchedule.Times.At(TimeSpan)\r\nSchedule.Times.Every(TimeSpan)\r\n\r\nSteps:\r\n1. Make QCAlgorithm API method, save schedule events to internal collection. Lock the collection after initialize with the _locked boolean.\r\n2. Update RealTimeEventHandlers to take collection of user events.\r\n3. Every time RealTimeEvents Setup date -- process the user functions to determine to add the scheduled event\r\n\r\n```\r\n//User facing API:\r\nAddScheduledEvent(Schedule.Dates, Schedule.Times, callback);\r\n\r\n//Example helper function implementations:\r\n            Func<DateTime, bool> dateFilter = dt =>\r\n            {\r\n                if (dt.DayOfWeek == DayOfWeek.Sunday || dt.DayOfWeek == DayOfWeek.Saturday)\r\n                {\r\n                    return false;\r\n                }\r\n                return true;\r\n            };\r\n\r\n            Func<DateTime, DateTime[]> realTimeEvent = dt =>\r\n            {\r\n                // every weekday at noon\r\n                return new []{dt.Date.AddHours(12)};\r\n            };\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/QuantConnect/Lean/issues/comments/119037907","html_url":"https://github.com/QuantConnect/Lean/issues/137#issuecomment-119037907","issue_url":"https://api.github.com/repos/QuantConnect/Lean/issues/137","id":119037907,"user":{"login":"naicigam","id":167381,"avatar_url":"https://avatars.githubusercontent.com/u/167381?v=3","gravatar_id":"","url":"https://api.github.com/users/naicigam","html_url":"https://github.com/naicigam","followers_url":"https://api.github.com/users/naicigam/followers","following_url":"https://api.github.com/users/naicigam/following{/other_user}","gists_url":"https://api.github.com/users/naicigam/gists{/gist_id}","starred_url":"https://api.github.com/users/naicigam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/naicigam/subscriptions","organizations_url":"https://api.github.com/users/naicigam/orgs","repos_url":"https://api.github.com/users/naicigam/repos","events_url":"https://api.github.com/users/naicigam/events{/privacy}","received_events_url":"https://api.github.com/users/naicigam/received_events","type":"User","site_admin":false},"created_at":"2015-07-07T00:59:49Z","updated_at":"2015-07-07T00:59:49Z","body":"Quartz.NET (http://www.quartz-scheduler.net/) implements a very flexible\nscheduler.\nIf we can't integrate it in Lean (I don't know what the rules are to\nintegrate third-party libraries), at least we can get some ideas on how to\nimplement it.\n\nOn Mon, Jul 6, 2015 at 6:17 PM, Jared <notifications@github.com> wrote:\n\n> Added a method AddScheduledEvent which passes the events through to the\n> RealTime handlers and can trigger events at specific times in the\n> algorithm.\n>\n> Each day a setup function is called to determine the DateTime value for\n> the event trigger. These setup functions could be made into a static helper\n> (like Field.Close)\n>\n> The RealTime handlers will need to be extended to handle multiple re-fire\n> of the same events over a day:: or an intraday eventhandler will need to be\n> copied for all the times its intended to be triggered.\n>\n> Example setup helpers could be:\n>\n>    - Every 30mins on week days\n>    - Daily at 2pm\n>    - 20mins after market open\n>\n> Signature for the method:\n> AddScheduledEvent(Func dates, Func times, Action callback)\n>\n> Add helpers static class to QCAlgorithm:\n> Schedule.Date.EveryWeekDay\n> Schedule.Date.EveryDay\n> Schedule.Dates.Specific(DayOfWeek)\n> Schedule.Times.At(TimeSpan)\n> Schedule.Times.Every(TimeSpan)\n>\n> Steps:\n> 1. Make QCAlgorithm API method, save schedule events to internal\n> collection. Lock the collection after initialize with the _locked boolean.\n> 2. Update RealTimeEventHandlers to take collection of user events.\n> 3. Every time RealTimeEvents Setup date -- process the user functions to\n> determine to add the scheduled event\n>\n> //User facing API:\n> AddScheduledEvent(Schedule.Dates, Schedule.Times, callback);\n>\n> //Example helper function implementations:\n>             Func<DateTime, bool> dateFilter = dt =>\n>             {\n>                 if (dt.DayOfWeek == DayOfWeek.Sunday || dt.DayOfWeek == DayOfWeek.Saturday)\n>                 {\n>                     return false;\n>                 }\n>                 return true;\n>             };\n>\n>             Func<DateTime, DateTime[]> realTimeEvent = dt =>\n>             {\n>                 // every weekday at noon\n>                 return new []{dt.Date.AddHours(12)};\n>             };\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/QuantConnect/Lean/issues/137>.\n>\n"}}