Beispiel #1
0
        public TVCSymbolResponse GetSymbolInfo(string symbol)
        {
            string result = TVCHttpGet(string.Format(TVC_URL_SYMBOLS, symbol));

            try
            {
                TVCSymbolResponse symbolResponse = JsonConvert.DeserializeObject <TVCSymbolResponse>(result);
                return(symbolResponse);
            }
            catch (Exception)
            {
            }

            return(null);
        }
Beispiel #2
0
        public string[] ConvertSymbolFormat(IEnumerable <string> symbols)
        {
            List <string> results      = new List <string>();
            List <string> symbolRemain = new List <string>();

            if (symbols != null && symbols.Count() > 0)
            {
                foreach (string symbol in symbols)
                {
                    if (symbol.Contains(":"))
                    {
                        results.Add(symbol);
                    }
                    else
                    {
                        symbolRemain.Add(symbol);
                    }
                }

                if (symbolRemain.Count > 0)
                {
                    List <string> symbolRemainTemp = new List <string>();
                    foreach (string symbol in symbolRemain)
                    {
                        TVCSymbolResponse response;
                        if (_SymbolToSymbolInfo.TryGetValue(symbol, out response))
                        {
                            if (!string.IsNullOrEmpty(response.exchange_traded))
                            {
                                results.Add(response.exchange_traded + ":" + symbol);
                            }
                            else
                            {
                                results.Add(symbol);
                            }
                        }
                        else
                        {
                            symbolRemainTemp.Add(symbol);
                        }
                    }

                    symbolRemain = symbolRemainTemp;
                }

                if (symbolRemain.Count > 0)
                {
                    List <string> symbolRemainTemp = new List <string>();
                    if (_getTVCSymbolsHandler != null)
                    {
                        Dictionary <string, TVCSymbolResponse> symbolToTVCSymbol = _getTVCSymbolsHandler(symbolRemain);
                        if (symbolToTVCSymbol != null)
                        {
                            foreach (string symbol in symbolRemain)
                            {
                                TVCSymbolResponse response;
                                if (symbolToTVCSymbol.TryGetValue(symbol, out response))
                                {
                                    _SymbolToSymbolInfo[symbol] = response;
                                    if (!string.IsNullOrEmpty(response.exchange_traded))
                                    {
                                        results.Add(response.exchange_traded + ":" + symbol);
                                    }
                                    else
                                    {
                                        results.Add(symbol);
                                    }
                                }
                                else
                                {
                                    symbolRemainTemp.Add(symbol);
                                }
                            }

                            symbolRemain = symbolRemainTemp;
                        }
                    }
                }

                if (symbolRemain.Count > 0)
                {
                    List <TVCSymbolResponse> newResponses = new List <TVCSymbolResponse>();
                    foreach (string symbol in symbolRemain)
                    {
                        TVCSymbolResponse response = GetSymbolInfo(symbol);

                        if (response != null && !string.IsNullOrEmpty(response.name))
                        {
                            newResponses.Add(response);
                            _SymbolToSymbolInfo[symbol] = response;
                            if (!string.IsNullOrEmpty(response.exchange_traded))
                            {
                                results.Add(response.exchange_traded + ":" + symbol);
                            }
                            else
                            {
                                results.Add(symbol);
                            }
                        }
                    }

                    _updateTVCSymbolesHandler?.Invoke(newResponses);
                }
            }

            return(results.ToArray());
        }