Esempio n. 1
0
        /// <summary>
        /// Gets the data from the webserver and saves it onto disk for later usage.
        /// </summary>
        /// <param name="ticker">ticker to get data for</param>
        /// <param name="start">Start date for the data</param>
        /// <param name="end">End date for the data</param>
        /// <param name="interval">Interval in seconds of the data to retreive</param>
        /// <returns>Data (price, volume, etc) for the ticker</returns>
        private TickerData GetIntraDayDataFromGoogleServer(TickerExchangePair ticker, DateTime start, DateTime end, int interval)
        {
            string downloadedData;

            DownloadURIBuilder uriBuilder = new DownloadURIBuilder(ticker.Exchange, ticker.Ticker);

            // Need to always get up till today from the server since google only supports a start date.
            string uri = uriBuilder.getGetPricesUrlForIntraday(start, end, interval);

            using (WebClient wClient = new WebClient())
            {
                downloadedData = wClient.DownloadString(uri);
            }

            using (MemoryStream ms = new MemoryStream(System.Text.Encoding.Default.GetBytes(downloadedData)))
            {
                DataProcessor dp = new DataProcessor();
                string        errorMessage;
                string        resultValue;

                resultValue = dp.processIntradayStream(ms, out errorMessage);

                if (!string.IsNullOrEmpty(errorMessage))
                {
                    throw new Exception(errorMessage);
                }
                else
                {
                    return(CreateTickerDataFromString(resultValue, ticker, false, start, end));
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets teh Url from the Builder
        /// </summary>
        /// <returns>string - the url calculated in the Builder</returns>
        private string getDownloadURI()
        {
            string ticker   = textBoxTicker.Text;
            string exchange = textBoxExchange.Text;

            if (String.IsNullOrEmpty(ticker))
            {
                return(string.Empty);
            }

            DownloadURIBuilder uriBuilder = new DownloadURIBuilder(exchange, ticker);

            if (radioButtonAllData.Checked)
            {
                return(uriBuilder.GetGetPricesUrlToDownloadAllData(DateTime.Now));
            }
            else if (radioButtonLastQuoute.Checked)
            {
                return(uriBuilder.GetGetPricesUrlForLastQuote());
            }
            else if (radioButtonSince.Checked)
            {
                DateTime startDate = dateTimePickerSinceDate.Value.Date,
                         endDate   = DateTime.Now.Date;
                if (endDate < startDate)
                { //It's impossible to download data from the future. That's why no URL is returned in this case.
                    return(string.Empty);
                }
                else
                {
                    return(uriBuilder.GetGetPricesUrlForRecentData(startDate, endDate));
                }
            }
            else if (radioButtonMinutes.Checked)
            {
                return(uriBuilder.GetGetPricesUrlForLastNumberOfDays(15));
            }
            else
            {
                return(string.Empty);
            }
        }