예제 #1
0
        internal void AddHistory(CurrencyRateHistoryContainer data)
        {
            if (data == null || data.Count == 0)
            {
                return;
            }

            History.AddRange(data);
        }
예제 #2
0
        private CurrencyRateHistoryContainer InternalRetriveData(string currencyName, DateTime startDate, DateTime endDate, bool isNeedToReversePrice)
        {
            CurrencyRateHistoryContainer result = null;

            var symbolName = CreateSymbolName(currencyName, isNeedToReversePrice);

            var url = CreateServiceConnectionString(symbolName, startDate, endDate, isNeedToReversePrice);

            Log.Info(string.Format("Yahoo: Retrieve historical price data started for Symbol {0}...", symbolName));
            try
            {
                var webClient = new WebClient();
                var stream    = webClient.OpenRead(url);
                if (stream == null)
                {
                    throw new Exception(string.Format("Can`t read Yahoo Service, history update not possible for Symbol {0}", symbolName));
                }

                var reader   = new StreamReader(stream);
                var response = reader.ReadToEnd();

                result = ParceData(response, isNeedToReversePrice);

                if (result == null)
                {
                    Log.Info(string.Format("Yahoo: NO DATA for Symbol: {0}!", symbolName));
                }

                if (result == null && !isNeedToReversePrice)
                {
                    return(InternalRetriveData(currencyName, startDate, endDate, true));
                }
            }
            catch (WebException ex)
            {
                if (ex.Message.Contains("404"))
                {
                    if (symbolName == "USD" || symbolName == "GBP" || symbolName == "EUR" || symbolName == "CAD" || symbolName == "AUD" || symbolName == "ILS")
                    {
                        Log.Error(string.Format("Yahoo: for Symbol [{0}] Update: {1}", symbolName, ex.Message));
                    }
                    else
                    {
                        Log.Warn(string.Format("Yahoo: for Symbol [{0}] Update: {1}", symbolName, ex.Message));
                    }
                    if (!isNeedToReversePrice)
                    {
                        return(InternalRetriveData(currencyName, startDate, endDate, true));
                    }
                }
                else
                {
                    Log.Error(ex);
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                Log.Error(ex);
                throw;
            }

            Log.Info(string.Format("Yahoo: Retrieve historical price data successfully completed for Symbol {0}!", symbolName));
            return(result);
        }