19 using System.Collections.Generic;
28 private readonly
string _market;
31 private readonly Dictionary<Symbol, SymbolProperties> _symbolPropertiesMap;
34 private readonly Dictionary<SecurityType, Dictionary<string, Symbol>> _symbolMap;
44 var symbolPropertiesList =
48 .Where(x => !
string.IsNullOrWhiteSpace(x.Value.MarketTicker))
51 _symbolPropertiesMap =
54 x =>
Symbol.
Create(x.Key.Symbol, x.Key.SecurityType, x.Key.Market),
58 foreach (var group
in _symbolPropertiesMap.GroupBy(x => x.Key.SecurityType))
60 _symbolMap[group.Key] = group.ToDictionary(
61 x => x.Value.MarketTicker,
73 if (symbol ==
null ||
string.IsNullOrWhiteSpace(symbol.
Value))
75 throw new ArgumentException($
"Invalid symbol: {(symbol == null ? "null" : symbol.Value)}");
80 throw new ArgumentException($
"Invalid market: {symbol.ID.Market}");
84 if (!_symbolPropertiesMap.TryGetValue(symbol, out symbolProperties) )
86 throw new ArgumentException($
"Unknown symbol: {symbol.Value}/{symbol.SecurityType}/{symbol.ID.Market}");
89 if (
string.IsNullOrWhiteSpace(symbolProperties.MarketTicker))
91 throw new ArgumentException($
"MarketTicker not found in database for symbol: {symbol.Value}");
94 return symbolProperties.MarketTicker;
109 if (
string.IsNullOrWhiteSpace(brokerageSymbol))
111 throw new ArgumentException($
"Invalid brokerage symbol: {brokerageSymbol}");
114 if (market != _market)
116 throw new ArgumentException($
"Invalid market: {market}");
119 if (!_symbolMap.TryGetValue(securityType, out var symbols))
121 throw new ArgumentException($
"Unknown brokerage security type: {securityType}");
124 if (!symbols.TryGetValue(brokerageSymbol, out var symbol))
126 throw new ArgumentException($
"Unknown brokerage symbol: {brokerageSymbol}");
139 return !
string.IsNullOrWhiteSpace(symbol?.Value) && _symbolPropertiesMap.ContainsKey(symbol);
149 if (
string.IsNullOrWhiteSpace(brokerageSymbol))
151 throw new ArgumentException($
"Invalid brokerage symbol: {brokerageSymbol}");
154 var result = _symbolMap.Select(kvp =>
156 kvp.Value.TryGetValue(brokerageSymbol, out var symbol);
158 }).Where(symbol => symbol !=
null).ToList();
160 if (result.Count == 0)
162 throw new ArgumentException($
"Unknown brokerage symbol: {brokerageSymbol}");
164 if (result.Count > 1)
166 throw new ArgumentException($
"Found multiple brokerage symbols: {string.Join(",
", result)}");
169 return result[0].SecurityType;
179 if (
string.IsNullOrWhiteSpace(brokerageSymbol))
184 return _symbolMap.Any(kvp => kvp.Value.ContainsKey(brokerageSymbol));