Commit Graph

62 Commits

Author SHA1 Message Date
Martin Molinero a92bee5bf1 Fix OnEndOfDay not fired
- Adding `IRealTimeHandler.OnSecurityChanged()` will be used to update
the `OnEndOfDay` security related scheduled events
- Adding `BaseRealTimeHandler.cs` to reduce code duplication in the
`Backtesting` and `LiveTrading` `RealTimeHandlers`
- Adding CSharp and Python regression tests
- Deprecating `OnEndOfDay()` callback because of two reasons, mainly
because Python does not support two methods with the same name, but also
because different assets have different market close times.
- `ScheduledEvents` set at the same time will now be deterministic
2019-06-20 17:35:28 -03:00
AlexCatarino 27d14d047f Fixes missing inner exception information in ScheduledEventException
When a `ScheduledEventException` was thrown, `IAlgorithm.RunTimeError` was not set as `ScheduledEventException` , but as `Exception` with the orginal exception message and no inner exception.
2018-04-13 19:23:45 +01:00
Martin-Molinero 994b1f44f6 saving current progress 2018-03-18 12:46:02 -07:00
Martin-Molinero 259a0ab8ff Fix exception thrown login vs plugin 2018-03-14 17:28:55 -07:00
Stefano Raggi 91ba63529b Remove Guid string from ScheduledEvent.Name
Fixes #1674
2018-03-07 21:33:33 +01:00
AlexCatarino 136ca90f6c Fixes message input in ScheduledEventException instance creation
Passes exception to Log.Error in RealTimeHandlers in order to include stack information
2018-02-20 17:39:03 +00:00
AlexCatarino af7b592dda Passes inner exception to ScheduleEvent exception
Without the inner exception, information on the user exception is lost. In python algorithm, the stack trace is completely lost.
Removes ScheduledEventExceptionMessage property as it is redundant to Message property inherited from parent class.
2018-02-19 19:11:55 +00:00
Stefano Raggi 20a325276e Fix scheduled event firing order in backtesting
When backtesting with multiple scheduled events, these were fired in unpredictable order, not respecting the expected sequence sorted by time.
2018-01-03 14:27:08 +01:00
Stefano Raggi f37d0cc962 Optimize loops for performance on cashbook and securities 2017-12-20 21:58:59 +01:00
Stefano Raggi c6aba7bfec Reduce full locking on ConcurrentDictionary objects
This PR is an attempt to reduce contention in concurrent dictionaries, replacing method calls using full locks with lock-free equivalents:

- dictionary.Count -> dictionary.Skip(0).Count()
- dictionary.Keys -> dictionary.Select(x => x.Key)
- dictionary.Values -> dictionary.Select(x => x.Value)

The most frequent usages of these methods are: CashBook, SecurityManager, UniverseManager and indirectly, SecurityPortfolioManager.

The reasons for this update are explained very clearly in this article:
https://arbel.net/2013/02/03/best-practices-for-using-concurrentdictionary/
2017-12-20 17:18:54 +01:00
Stefano Raggi b8ff1fa745 Fix initialization of IsActive in LiveTradingRealTimeHandler 2017-11-01 22:32:16 +01:00
Michael Handschuh 7068a5aeba Fix scheduled event scheduling
Scheduled events were seemingly only being submitted for internal feed
securities -- the opposite of what we're looking for.
2017-10-20 13:49:56 -04:00
Andrew 2c156ce04a Add schedule event exception logic to BacktestingRealTimeHandler
Catching the exception in BacktestingRealTimeHandler prevents unhandled errors in backtesting and provides more specific logging to make debugging easier for users
2017-09-25 11:04:13 -04:00
Andrew be986a5a8f End execution of Lean if an error in a scheduled event is thrown 2017-09-25 09:51:45 -04:00
Andrew eabd36966d Added ScheduledEventException
These changes fix a bug so that when an exception is thrown with the LiveTradingResultHandler, the error is handled and the next scheduled event can happen as scheduled.
2017-09-22 18:23:15 -04:00
Stefano Raggi 6a8bb27b44 Log TimeZone in LiveTradingRealTimeHandler.RefreshMarketHoursToday 2017-03-17 18:09:07 +01:00
Stefano Raggi 4149aba9d7 Fixed scheduled event firing time in backtesting
If backtesting, we need to check if there are realtime events in the past
which didn't fire because at the scheduled times there was no data (i.e. markets closed) and fire them with the correct date/time.
In live mode, no changes are needed.
2017-02-23 20:25:49 +01:00
Michael Handschuh 42465ffd52 Clean up IsInternalFeed usages 2016-04-12 19:06:49 -04:00
Michael Handschuh 70b170358e Turn debug logging on for regression
Also removes some redundant/duplicate logging
2016-04-07 04:11:53 -04:00
Michael Handschuh 3e434709ea Change IApi.MarketToday to IEnumerable<MarketHoursSegment> 2016-01-29 18:50:09 -05:00
Michael Handschuh 4eed7e02fd Change IApi.MarketToday to accept a symbol 2016-01-29 18:27:45 -05:00
Michael Handschuh f3cc448ad5 Update SecurityExchange.UpdateMarketHours to use segments 2016-01-29 18:12:57 -05:00
snugs be950e756a Log full errors/stack traces
Many places in the code used Log.Error(err.Message) or equivalent which
strips out all the really useful information, such as the stack trace
and inner exceptions. Using Log.Error(exception) is the correct way to
log an error as it will correctly write all the message details, also,
by passing the full Exception object we can improve the logging in this
one place and all call sites will automatically benefit from the improvements
2015-12-02 12:35:33 -05:00
snugs 7b6c82841f Initial implementation of SecurityIdentifier 2015-11-12 13:55:42 -05:00
snugs 8374b99e18 Don't fire EOD events for internal feeds 2015-09-28 13:28:09 -04:00
snugs c67ff638f4 Renames Symbol.SID to Symbol.Permtick
Coming soon we'll have a full SID system, so renames to make backwards compatibility easier
2015-09-20 23:14:53 -04:00
snugs e1938baafe Clean up using directives 2015-09-01 22:17:35 -04:00
snugs df79ce30c2 Adds the Symbol type
This includes updating all usages of symbol as a security identifier to use the new type.
The type includes a unique field, SID, as well as the current ticker's value. This allows
for consistent addressability while also allowing the ticker to evolve over time with the
mapping changes.

Effort was made to maintain compile and runtime backwards compatibility.
2015-09-01 22:17:10 -04:00
snugs 730430b1bb Adds scheduling feature
Adds the ScheduleManager which allows an algorithm to add/remove scheduled events
Check out the ScheduledEventsAlgorithm for syntax
ScheduledEvents are at their core an IEnumerator<DateTime> that defines the event times coupled with a callback
IDateRule defines dates for events
ITimeRule defines time(s) on a given date for events
2015-08-10 10:56:14 -04:00
snugs ffa2c948f9 Convert back from UTC for refresh date check 2015-08-08 12:35:07 -04:00
snugs 844a040be5 Initial impl of coarse universe selection
Adds concept of Subscription to contain everything a data feed needs in order to process  single data feed item
Moves preparation of all data to data feed thread, algo thread receives data in format it needs
QCAlgorithm.SetUniverse( func ) allows selection based on market/symbol/dollar volume/price
Remove laziness from Slice as optimization, no order by in real time handler
2015-08-06 17:52:23 -04:00
snugs 7fa9a4b1be Implements self re-scheduling events
A ScheduledEvent can be defined using an enumerator of event times and a callback
2015-08-05 13:13:08 -04:00
snugs aa0877be24 Fixes bug in live real time handler 2015-08-04 18:23:01 -04:00
snugs 011ac4b12c Try/catch on Run methods
In some cases we need to exit the applications, in others we just want to log.
For instance, if the transaction handler throws an unexpected exception then we
can't be confident in the state of our orders but if the live result handler fails,
the algo is still OK and consistent state, we just may not receive a packet for that time step
2015-08-02 23:54:31 -04:00
snugs a038f6cb89 Fixes tz bug in real time handler 2015-08-02 23:54:31 -04:00
snugs c853a4ddbd Adds some logging/error handling 2015-07-28 14:21:00 -04:00
snugs 27cd9b1fed Fixes bug in fire EOD events in live mode 2015-07-24 19:28:56 -04:00
snugs 6bd38ece77 Adds international/timezone support
Time sync:
	* Data feeds are required to time sync in UTC time
	* TimeSlice.Time is now in UTC

IAlgorithm
	* Time is now exclusively the algorithm's local time zone
	* Added UtcTime
	* SetDateTime( DateTime ) accepts a UTC time and is internally converted

SubscriptionDataConfig
	* Adds market and time zone as required ctor parameters

SecurityExchange
	* Now passes most calls directly through to SecurityExchangeHours class

SecurityExchangeHours
	* Holds market hours for each day of week (LocalMarketHours)
	* Talks in terms of local times in the SecurityExchangeHours.TimeZone time zone

Data/market-hours/
	* New data folder to hold market hour information
	* Includes market-hours-database.csv to hold market hours per market/symbol/security (see doc in file)
	* Includes holidays-usa.csv to hold holidays for 'usa' market
		+ The holiday files follow the pattern 'holidays-*.csv' where * is the market

TimeKeeper
	* Receives updates in UTC time
	* Passes that to LocalTimeKeeper's who lazily evaluate the time in their respective time zones
	* Eventually this can grow to be the sole source of time in the algorithm's scope

MISC:
	* Fixes exception thrown when exiting LiveTradingDataFeed
	* Fixes exception thrown when exiting FileSystemDataFeed
	* Fixes exception thrown when exiting StatusPing
	* Simplify FillForwardEnumerator logic with GetNextMarketOpen
	* Adds many time zones, see TimeZones.cs
2015-07-08 18:45:34 -04:00
QuantConnect cc3f0c76e1 Reduced logging from backtesting realtime handler 2015-06-29 11:55:25 -04:00
Jared 7e71f24f33 Merge pull request #124 from AnObfuscator/master
Fix time issue preventing OnEndOfDay() event from firing.
2015-06-25 18:57:38 -04:00
Jonathan Evans 84bfaf129c Fix time issue preventing OnEndOfDay() event from firing. Remove redundant ScanEvents() call. 2015-06-25 17:44:54 -05:00
snugs 0ef2be5bf8 Respect time from algo manager in live real time handler 2015-06-20 13:58:50 -04:00
snugs 4de2ec4070 Make Engine an instance
Updated all interfaces to accept dependencies via Initialize methods
2015-06-18 13:50:11 -04:00
snugs c1736571cc Load real time handlers via MEF configuration 2015-06-17 22:34:01 -04:00
QuantConnect fde0cbed3a Strip out block quote section header comments 2015-06-13 16:04:27 -04:00
snugs 89b6e98af8 Fixes warnings mostly relating to xml comments
Also cleans up some block comments

Via PR#72 - thanks @ammachado!
2015-05-13 10:56:47 -04:00
snugs 33f4046fb9 Several random fixes
Made ObjectActivator.Clone 4x faster
Updated deltaCharts in live trading results using order events
2015-04-30 15:31:57 -04:00
QuantConnect 8d28ff3f08 Slight changes to only create realtime events for day if the time hasn't passed yet 2015-04-30 14:46:07 -04:00
snugs d80b1733a9 Pre ib launch review 2015-04-24 19:12:16 -04:00
snugs 8b6e5fe826 Change json on MarketToday and improve default impl 2015-04-21 16:52:28 -04:00