Merge pull request #3022 from AlexCatarino/feature-3007-calendar-consolidators

Implements Calendar (Weekly/Monthly) Consolidator
This commit is contained in:
Jared
2019-04-10 14:35:13 -07:00
committed by GitHub
16 changed files with 823 additions and 57 deletions
+38
View File
@@ -928,6 +928,44 @@ namespace QuantConnect.Algorithm
return Consolidate(symbol, period, null, handler.ConvertToDelegate<Action<BaseData>>());
}
/// <summary>
/// Registers the <paramref name="handler"/> to receive consolidated data for the specified symbol
/// </summary>
/// <param name="symbol">The symbol who's data is to be consolidated</param>
/// <param name="calendarType">The consolidation calendar type</param>
/// <param name="handler">Data handler receives new consolidated data when generated</param>
/// <returns>A new consolidator matching the requested parameters with the handler already registered</returns>
public IDataConsolidator Consolidate(Symbol symbol, Func<DateTime, CalendarInfo> calendarType, PyObject handler)
{
return Consolidate(symbol, calendarType, null, handler);
}
/// <summary>
/// Registers the <paramref name="handler"/> to receive consolidated data for the specified symbol
/// </summary>
/// <param name="symbol">The symbol who's data is to be consolidated</param>
/// <param name="calendarType">The consolidation calendar type</param>
/// <param name="tickType">The tick type of subscription used as data source for consolidator. Specify null to use first subscription found.</param>
/// <param name="handler">Data handler receives new consolidated data when generated</param>
/// <returns>A new consolidator matching the requested parameters with the handler already registered</returns>
private IDataConsolidator Consolidate(Symbol symbol, Func<DateTime, CalendarInfo> calendarType, TickType? tickType, PyObject handler)
{
// resolve consolidator input subscription
var type = GetSubscription(symbol, tickType).Type;
if (type == typeof(TradeBar))
{
return Consolidate(symbol, calendarType, tickType, handler.ConvertToDelegate<Action<TradeBar>>());
}
if (type == typeof(QuoteBar))
{
return Consolidate(symbol, calendarType, tickType, handler.ConvertToDelegate<Action<QuoteBar>>());
}
return Consolidate(symbol, calendarType, tickType, handler.ConvertToDelegate<Action<BaseData>>());
}
/// <summary>
/// Gets indicator base type
/// </summary>