예제 #1
0
        public ICollection <LoadedMarketData> Load(
            TickerSymbol ticker,
            IList <MarketDataType> dataNeeded,
            DateTime from,
            DateTime to)
        {
            // TODO: nyyyyyyyaaagh!

            ICollection <LoadedMarketData> result =
                new List <LoadedMarketData>();
            Uri             url      = BuildURL(ticker, from, to);
            WebRequest      http     = HttpWebRequest.Create(url);
            HttpWebResponse response = http.GetResponse() as HttpWebResponse;

            using (Stream istream = response.GetResponseStream())
            {
                ReadCSV csv = new ReadCSV(
                    istream,
                    true,
                    CSVFormat.DECIMAL_POINT
                    );

                while (csv.Next())
                {
                    // todo: edit headers to match
                    DateTime date = csv.GetDate("DATE");
                    date =
                        date.Add(
                            new TimeSpan(
                                csv.GetDate("TIME").Hour,
                                csv.GetDate("TIME").Minute,
                                csv.GetDate("TIME").Second
                                )
                            );
                    double open   = csv.GetDouble("OPEN");
                    double high   = csv.GetDouble("MIN");
                    double low    = csv.GetDouble("MAX");
                    double close  = csv.GetDouble("CLOSE");
                    double volume = csv.GetDouble("VOLUME");

                    LoadedMarketData data =
                        new LoadedMarketData(date, ticker);
                    data.SetData(MarketDataType.OPEN, open);
                    data.SetData(MarketDataType.HIGH, high);
                    data.SetData(MarketDataType.LOW, low);
                    data.SetData(MarketDataType.CLOSE, close);
                    data.SetData(MarketDataType.VOLUME, volume);
                    result.Add(data);
                }

                csv.Close();
                istream.Close();
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// Loads the specified financial data.
        /// </summary>
        /// <param name="ticker">The currency pair to load.</param>
        /// <param name="dataNeeded">The financial data needed.</param>
        /// <param name="from">The beginning date to load data from.</param>
        /// <param name="to">The ending date to load data to.</param>
        /// <returns>A collection of LoadedMarketData objects that represent
        /// the data loaded.</returns>
        public ICollection <LoadedMarketData> Load(
            TickerSymbol ticker,
            IList <MarketDataType> dataNeeded,
            DateTime from,
            DateTime to
            )
        {
            ICollection <LoadedMarketData> result =
                new List <LoadedMarketData>();
            Uri             url      = buildURL(ticker, from, to);
            WebRequest      http     = HttpWebRequest.Create(url);
            HttpWebResponse response = http.GetResponse() as HttpWebResponse;

            using (Stream istream = response.GetResponseStream())
            {
                ReadCSV csv =
                    new ReadCSV(istream, true, CSVFormat.DECIMAL_POINT);
                while (csv.Next())
                {
                    // TODO: check these values if possible
                    DateTime date     = csv.GetDate("date");
                    double   adjClose = csv.GetDouble("adj close"); // TODO: deprecate?
                    double   open     = csv.GetDouble("open");
                    double   close    = csv.GetDouble("close");
                    double   high     = csv.GetDouble("high");
                    double   low      = csv.GetDouble("low");
                    double   volume   = csv.GetDouble("volume"); // TODO: deprecate?

                    LoadedMarketData data =
                        new LoadedMarketData(date, ticker);
                    data.SetData(MarketDataType.ADJUSTED_CLOSE, adjClose);
                    data.SetData(MarketDataType.OPEN, open);
                    data.SetData(MarketDataType.CLOSE, close);
                    data.SetData(MarketDataType.HIGH, high);
                    data.SetData(MarketDataType.LOW, low);
                    data.SetData(MarketDataType.OPEN, open);
                    data.SetData(MarketDataType.VOLUME, volume);
                    result.Add(data);
                }

                csv.Close();
                istream.Close();
            }
            return(result);
        }