/// <summary> /// Gets a <see cref="FactorFile"/> instance for the specified symbol, or null if not found /// </summary> /// <param name="symbol">The security's symbol whose factor file we seek</param> /// <returns>The resolved factor file, or null if not found</returns> public IFactorProvider Get(Symbol symbol) { symbol = symbol.GetFactorFileSymbol(); IFactorProvider factorFile; if (_cache.TryGetValue(symbol, out factorFile)) { return(factorFile); } // we first need to resolve the map file to get a permtick, that's how the factor files are stored var mapFileResolver = _mapFileProvider.Get(AuxiliaryDataKey.Create(symbol)); if (mapFileResolver == null) { return(GetFactorFile(symbol, symbol.Value)); } var mapFile = mapFileResolver.ResolveMapFile(symbol); if (mapFile.IsNullOrEmpty()) { return(GetFactorFile(symbol, symbol.Value)); } return(GetFactorFile(symbol, mapFile.Permtick)); }
/// <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="mapFileProvider">The map file provider</param> /// <param name="dataConfig">The configuration to fetch the map file for</param> /// <returns>The mapping file to use</returns> public static MapFile ResolveMapFile(this IMapFileProvider mapFileProvider, SubscriptionDataConfig dataConfig) { var resolver = MapFileResolver.Empty; if (dataConfig.TickerShouldBeMapped()) { resolver = mapFileProvider.Get(AuxiliaryDataKey.Create(dataConfig.Symbol)); } return(resolver.ResolveMapFile(dataConfig.Symbol, dataConfig.Type.Name, dataConfig.DataMappingMode)); }
/// <summary> /// Gets the primary exchange for a given security identifier /// </summary> /// <param name="securityIdentifier">The security identifier to get the primary exchange for</param> /// <returns>Returns the primary exchange or null if not found</returns> public Exchange GetPrimaryExchange(SecurityIdentifier securityIdentifier) { Exchange primaryExchange; if (!_primaryExchangeBySid.TryGetValue(securityIdentifier, out primaryExchange)) { var mapFile = _mapFileProvider.Get(AuxiliaryDataKey.Create(securityIdentifier)) .ResolveMapFile(securityIdentifier.Symbol, securityIdentifier.Date); if (mapFile != null && mapFile.Any()) { primaryExchange = mapFile.Last().PrimaryExchange; } _primaryExchangeBySid[securityIdentifier] = primaryExchange; } return(primaryExchange); }
/// <summary> /// Gets a <see cref="FactorFile"/> instance for the specified symbol, or null if not found /// </summary> /// <param name="symbol">The security's symbol whose factor file we seek</param> /// <returns>The resolved factor file, or null if not found</returns> public IFactorProvider Get(Symbol symbol) { symbol = symbol.GetFactorFileSymbol(); var key = AuxiliaryDataKey.Create(symbol); lock (_lock) { if (!_seededMarket.ContainsKey(key)) { HydrateFactorFileFromLatestZip(key); _seededMarket[key] = true; } IFactorProvider factorFile; if (!_factorFiles.TryGetValue(symbol, out factorFile)) { // Could not find factor file for symbol Log.Error($"LocalZipFactorFileProvider.Get({symbol}): No factor file found."); _factorFiles[symbol] = factorFile = symbol.GetEmptyFactorFile(); } return(factorFile); } }