Beispiel #1
0
        public async Task <IEnumerable <CurrencyRate> > GetCurrencyRatesByDate(DateTime date)
        {
            IEnumerable <CurrencyRate> currencyRates = new List <CurrencyRate>();
            List <NationalBankUaDto>   responseBankClientSerialize = new List <NationalBankUaDto>();

            string responseBankClient = await HttpModule.DownloadData(UrlConfigurator(date));

            try
            {
                responseBankClientSerialize = ApiParserData(responseBankClient);
            }
            catch (Exception ex)
            {
                throw new Exception("Can't parse response. BankClient - NationalBankUa. Error: " + ex.Message);
            }

            if (responseBankClientSerialize.Count == 0 || responseBankClientSerialize.Count == 1)
            {
                throw new Exception("NationalBankUa - Wrong date. Error date: " + date);
            }

            currencyRates = responseBankClientSerialize.Select(currencyItem => new CurrencyRate
            {
                BankId       = BankClientType.NationalBankUa.ToString(),
                CurrencyCode = currencyItem.Code,
                Rate         = currencyItem.Rate,
                Timestamp    = date.Date
            });

            return(currencyRates);
        }
        public async Task <IEnumerable <CurrencyRate> > GetCurrencyRatesByDate(DateTime date)
        {
            IEnumerable <CurrencyRate> currencyRates = new List <CurrencyRate>();
            NationalBankKzDto          responseBankClientSerialize = new NationalBankKzDto();

            string responseBankClient = await HttpModule.DownloadData(UrlConfigurator(date));

            responseBankClientSerialize = XmlApiSerializer.DataConverterDto <NationalBankKzDto>(responseBankClient);

            if (responseBankClientSerialize.Error == "введена неверная дата")
            {
                throw new Exception("NationalBankKz - Wrong format date. Error date: " + date);
            }

            if (responseBankClientSerialize.Rates.Count == 0)
            {
                throw new Exception("NationalBankKz - returned error. Date: " + date + ". Add information: " + responseBankClientSerialize.Info);
            }

            currencyRates = responseBankClientSerialize.Rates.Select(currencyItem => new CurrencyRate
            {
                BankId       = BankClientType.NationalBankKz.ToString(),
                CurrencyCode = currencyItem.Code,
                Rate         = currencyItem.Rate / currencyItem.Quantity,
                Timestamp    = date.Date
            });

            return(currencyRates);
        }
Beispiel #3
0
        public async Task <IEnumerable <CurrencyRate> > GetCurrencyRatesByDate(DateTime date)
        {
            IEnumerable <CurrencyRate>    currencyRates = new List <CurrencyRate>();
            OpenExchangeRateBankClientDto responseBankClientSerialize = new OpenExchangeRateBankClientDto();

            string responseBankClient = await HttpModule.DownloadData(UrlConfigurator(date));

            try
            {
                responseBankClientSerialize = ApiParserData(responseBankClient);
            }
            catch (Exception ex)
            {
                throw new Exception("Can't parse response. BankClient - OpenExchangeRateBankClient. Error: " + ex.Message);
            }

            if (responseBankClientSerialize.Error == true)
            {
                throw new Exception("OpenExchangeRateBankClient - returned error: " + responseBankClientSerialize.Message + ". Date: " + date);
            }

            currencyRates = responseBankClientSerialize.Rates.Select(currencyItem => new CurrencyRate
            {
                BankId       = BankClientType.OpenExchangeRateBankClient.ToString(),
                CurrencyCode = currencyItem.Key,
                Rate         = currencyItem.Value,
                Timestamp    = date.Date
            });

            return(currencyRates);
        }