Esempio n. 1
0
        public override TimeSeriesDataOutput GetTimeSeriesData(TimeSeriesDataInput input)
        {
            if (input == null || string.IsNullOrEmpty(input.Symbol))
            {
                return(null);
            }

            string timeSeriesData = GetTimeSeriesDataDirect(input);

            if (!string.IsNullOrEmpty(timeSeriesData))
            {
                DataTable dtTimeSeries = TextUtility.ConvertCSVToTable(timeSeriesData, input.Symbol);
                return(ConvertDataToTimeSeriesDataOutput(input, dtTimeSeries));
            }

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

            string[] symbolNames = symbols.Distinct().ToArray();

            while (symbolNames.Length > 0)
            {
                string[] splitedSymbols = symbolNames.Take(100).ToArray();
                symbolNames = symbolNames.Skip(100).ToArray();
                batchList.Add(splitedSymbols);
            }

            ConcurrentBag <Quote> quotes = new ConcurrentBag <Quote>();

            Parallel.ForEach(batchList, s =>
            {
                try
                {
                    string symbolString = string.Join(",", s);
                    string quoteResult  = _keyManager.Call <string>(key => HttpGet(string.Format(AV_STOCK_BATCH_QUOTES, key, symbolString)));

                    if (!string.IsNullOrEmpty(quoteResult))
                    {
                        DataTable dtQuotes = TextUtility.ConvertCSVToTable(quoteResult, "Quotes");
                        foreach (DataRow row in dtQuotes.AsEnumerable())
                        {
                            try
                            {
                                Quote quote    = new Quote();
                                quote.Price    = double.Parse(row.Field <string>(AV_FIELD_PRICE));
                                quote.Ask      = quote.Price;
                                quote.Bid      = quote.Price;
                                quote.Symbol   = row.Field <string>(AV_FIELD_SYMBOL);
                                quote.TimeZone = "US/Eastern";
                                try
                                {
                                    quote.Volume = double.Parse(row.Field <string>(AV_FIELD_VOLUME));
                                }
                                catch (Exception)
                                {
                                }
                                try
                                {
                                    quote.TimeStamp = DateTime.Parse(row.Field <string>(AV_FIELD_TIMESTAMP));
                                }
                                catch (Exception)
                                {
                                }

                                quotes.Add(quote);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }
                catch (Exception)
                {
                }
            });

            return(quotes.ToArray());
        }