示例#1
0
        private async Task GetRatesAsync(
            RateSource rateSource,
            ICollector <RateEntity> queueCollector,
            ILogger logger
            )
        {
            var rateDefinitions = Rate.FetchAll();

            if (!_ratesServices.TryGetValue(rateSource, out var service))
            {
                throw new ArgumentException($"No service available for rate source {rateSource}");
            }

            // chose rates for this source
            var rateLookups = rateDefinitions.Where(r => r.Source == rateSource);

            // fetch rates
            var rates = await service.GetRates(rateLookups);

            // save to table storage & send queue message
            logger.LogInformation($"Got {rates.Count()} rates. Saving to storage.");
            foreach (var rate in rates)
            {
                await rate.SaveAsync();

                queueCollector.Add(rate);

                var rateHistory = new RateHistory(rate.Ticker, rate.Value);
                await rateHistory.SaveAsync();
            }
        }
示例#2
0
文件: CacheData.cs 项目: vovus/curves
        public static InflationCurveSnapshot GetInflationCurveSnapshot(int InflationCurveID, DateTime d)
        {
            InflationCurveSnapshot ics = new InflationCurveSnapshot();

            ics.Id               = InflationCurveID;
            ics.settlementDate   = d;
            ics.Name             = CachedInflationCurveDataDic[InflationCurveID].Name;
            ics.Family           = CachedInflationCurveDataDic[InflationCurveID].Family;
            ics.CurrencyId       = CachedInflationCurveDataDic[InflationCurveID].CurrencyId;
            ics.InflationIndexId = CachedInflationCurveDataDic[InflationCurveID].InflationIndexId;
            ics.InflationIndex   = CachedInflationIndexDic[ics.InflationIndexId];
            ics.settings         = CachedInflationCurveDataDic[InflationCurveID].settings;

            List <EntryValuePair> ListEVP = new List <EntryValuePair>();

            foreach (InflationCurveEntryData iced in CachedInflationCurveEntryDataDic.Values.ToList())
            {
                EntryValuePair evp = new EntryValuePair();                 //to be added to ListEVP

                if ((iced.InflationCurveId == InflationCurveID) &&
                    (iced.ValidDateBegin <= d) &&
                    (iced.ValidDateEnd >= d)
                    )
                {
                    //  ics.EntryList.Add(iced);
                    //now for that entry we need to find the most recent historical value

                    evp.iced = iced;

                    if (iced.Type == "inflationbond")
                    {
                        List <RateHistory> bh = getBondsHistoryById(iced.Instrument.Id, d);
                        RateHistory        rh = bh[bh.Count() - 1];
                        if (rh.RateId != iced.Instrument.Id)
                        {
                            MessageBox.Show("something is wrong in GetInflationCurveSnapshot");
                        }
                        else
                        {
                            evp.value = bh[bh.Count() - 1].Close;
                            //  ics.ValueList.Add(bh[bh.Count() - 1].Close);
                        }
                    }
                    else if (iced.Type == "swap")
                    {
                        List <RateHistory> bh = getRateHistoryById(iced.Instrument.Id, d);
                        RateHistory        rh = bh[bh.Count() - 1];
                        if (rh.RateId != iced.Instrument.Id)
                        {
                            MessageBox.Show("something is wrong in GetInflationCurveSnapshot");
                        }
                        else
                        {
                            //  ics.ValueList.Add(bh[bh.Count() - 1].Close);
                            evp.value = bh[bh.Count() - 1].Close;
                        }
                    }
                    ListEVP.Add(evp);
                }
            }
            //   ics.EntryList.Sort((x, y) => y.Date.CompareTo(x.Date));

            ListEVP.Sort();
            ics.EntryList = new ObservableCollection <InflationCurveEntryData>();
            ics.ValueList = new ObservableCollection <double>();
            foreach (EntryValuePair evp in ListEVP)
            {
                ics.EntryList.Add(evp.iced);
                ics.ValueList.Add(evp.value);
            }

            List <RateHistory> iihistory = getIndexHistoryById(ics.InflationIndexId, d);

            ics.IndexHistory = new ObservableCollection <HistoricValue>();
            foreach (RateHistory iirh in iihistory)
            {
                HistoricValue vp = new HistoricValue();
                vp.Date  = iirh.Date;
                vp.Value = iirh.Close;
                ics.IndexHistory.Add(vp);
            }

            return(ics);
        }