Skip to content

Commit

Permalink
Mapping Extensions will try get custom data from symbol (QuantConnect…
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Molinero authored Sep 3, 2021
1 parent 0e1e497 commit c3874bc
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Common/Data/Auxiliary/MappingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,33 @@ public static class MappingExtensions
public static MapFile ResolveMapFile(this MapFileResolver mapFileResolver,
Symbol symbol,
Type dataType)
{
return mapFileResolver.ResolveMapFile(symbol , dataType.Name);
}

/// <summary>
/// Helper method to resolve the mapping file to use.
/// </summary>
/// <remarks>This method is aware of the data type being added for <see cref="SecurityType.Base"/>
/// to the <see cref="SecurityIdentifier.Symbol"/> value</remarks>
/// <param name="mapFileResolver">The map file resolver</param>
/// <param name="symbol">The symbol that we want to map</param>
/// <param name="dataType">The string data type name if any</param>
/// <returns>The mapping file to use</returns>
public static MapFile ResolveMapFile(this MapFileResolver mapFileResolver,
Symbol symbol,
string dataType = null)
{
// Load the symbol and date to complete the mapFile checks in one statement
var symbolID = symbol.HasUnderlying ? symbol.Underlying.ID.Symbol : symbol.ID.Symbol;
var date = symbol.HasUnderlying ? symbol.Underlying.ID.Date : symbol.ID.Date;

if (dataType == null && symbol.SecurityType == SecurityType.Base)
{
symbol.ID.Symbol.TryGetCustomDataType(out dataType);
}
return mapFileResolver.ResolveMapFile(
symbol.SecurityType == SecurityType.Base ? symbolID.RemoveFromEnd($".{dataType.Name}") : symbolID,
symbol.SecurityType == SecurityType.Base && dataType != null ? symbolID.RemoveFromEnd($".{dataType}") : symbolID,
date);
}
}
Expand Down

0 comments on commit c3874bc

Please sign in to comment.