Esempio n. 1
0
        public TVCQuotesResponse GetQuotes(IEnumerable <string> symbols)
        {
            if (symbols != null && symbols.Count() > 0)
            {
                List <List <string> > symbolBatchList = new List <List <string> >();

                List <string> symbolList = symbols.ToList();

                while (symbolList.Count > 0)
                {
                    symbolBatchList.Add(symbolList.Take(200).ToList());
                    symbolList = symbolList.Skip(200).ToList();
                }

                TVCQuotesResponse totalQuotes = null;

                foreach (List <string> current in symbolBatchList)
                {
                    string[]          covertedSymbols = ConvertSymbolFormat(current);
                    string            joinedsymbols   = string.Join(",", covertedSymbols);
                    string            result          = TVCHttpGet(string.Format(TVC_URL_QUOTES, joinedsymbols));
                    TVCQuotesResponse quotes          = JsonConvert.DeserializeObject <TVCQuotesResponse>(result);
                    if (quotes != null && quotes.d != null)
                    {
                        if (totalQuotes == null)
                        {
                            totalQuotes = quotes;
                        }
                        else
                        {
                            totalQuotes.d.AddRange(quotes.d);
                        }
                    }
                }

                _updateTVCQuotesHandler?.Invoke(totalQuotes.d);

                return(totalQuotes);
            }

            return(null);
        }
Esempio n. 2
0
        public override Quote[] StockBatchQuote(IEnumerable <string> symbols)
        {
            TVCQuotesResponse response = GetQuotes(symbols);

            if (response != null && response.d != null && response.d.Count > 0)
            {
                List <Quote> quotes = new List <Quote>();
                foreach (var tvc in response.d)
                {
                    if (tvc.s == "ok")
                    {
                        Quote quote = ConvertTVCQuotesToQuotes(tvc);
                        if (quote != null)
                        {
                            quotes.Add(quote);
                        }
                    }
                }
                return(quotes.ToArray());
            }

            return(null);
        }