24 using System.Collections.Generic;
36 private static readonly
object _lock =
new object();
38 private List<SecurityDefinition> _securityDefinitions;
40 private readonly
string _securitiesDefinitionKey;
50 _securitiesDefinitionKey = securitiesDefinitionKey ?? Path.Combine(
Globals.
GetDataFolderPath(
"symbol-properties"),
"security-database.csv");
55 _mapFileProvider.Initialize(_dataProvider);
71 if (
string.IsNullOrWhiteSpace(cusip))
76 return SecurityDefinitionToSymbol(
77 GetSecurityDefinitions().FirstOrDefault(x => x.CUSIP !=
null && x.CUSIP.Equals(cusip, StringComparison.InvariantCultureIgnoreCase)),
88 return SymbolToSecurityDefinition(symbol)?.
CUSIP;
104 if (
string.IsNullOrWhiteSpace(compositeFigi))
109 return SecurityDefinitionToSymbol(
110 GetSecurityDefinitions().FirstOrDefault(x => x.CompositeFIGI !=
null && x.CompositeFIGI.Equals(compositeFigi, StringComparison.InvariantCultureIgnoreCase)),
137 if (
string.IsNullOrWhiteSpace(sedol))
142 return SecurityDefinitionToSymbol(
143 GetSecurityDefinitions().FirstOrDefault(x => x.SEDOL !=
null && x.SEDOL.Equals(sedol, StringComparison.InvariantCultureIgnoreCase)),
154 return SymbolToSecurityDefinition(symbol)?.
SEDOL;
170 if (
string.IsNullOrWhiteSpace(isin))
175 return SecurityDefinitionToSymbol(
176 GetSecurityDefinitions().FirstOrDefault(x => x.ISIN !=
null && x.ISIN.Equals(isin, StringComparison.InvariantCultureIgnoreCase)),
187 return SymbolToSecurityDefinition(symbol)?.
ISIN;
197 return SymbolToSecurityDefinition(symbol)?.
CIK;
218 return GetSecurityDefinitions()
219 .Where(x => x.CIK !=
null && x.CIK == cik)
220 .Select(securityDefinition => SecurityDefinitionToSymbol(securityDefinition, tradingDate))
221 .Where(x => x !=
null)
236 if (securityDefinition ==
null)
245 var mapFile = mapFileResolver
250 var mappedTicker = mapFile?.GetMappedSymbol(tradingDate,
null);
254 mappedTicker ??= mapFile?
258 return string.IsNullOrWhiteSpace(mappedTicker)
266 private SecurityDefinition SymbolToSecurityDefinition(Symbol symbol)
273 return GetSecurityDefinitions().FirstOrDefault(x => x.SecurityIdentifier.Equals(symbol.ID));
279 private IEnumerable<SecurityDefinition> GetSecurityDefinitions()
283 if (_securityDefinitions ==
null && !SecurityDefinition.TryRead(_dataProvider, _securitiesDefinitionKey, out _securityDefinitions))
285 _securityDefinitions =
new List<SecurityDefinition>();
286 Log.
Error($
"SecurityDefinitionSymbolResolver(): No security definitions data loaded from file: {_securitiesDefinitionKey}");
290 return _securityDefinitions;
303 if (_securityDefinitionSymbolResolver ==
null)
309 return _securityDefinitionSymbolResolver;
321 _securityDefinitionSymbolResolver =
null;