コード例 #1
0
        static async Task getNfpTimeStats()
        {
            var ntpIndicatorData      = new NtpIndicatorData();
            List <IndicatorData> recs = await ntpIndicatorData.GetIndicatorsForCcyAndName("USD", "Non-Farm Employment Change");

            List <DateTime> dts = new List <DateTime>();

            foreach (var rec in recs)
            {
                var dt = DateTime.Parse(rec.ReleaseDate + " " + rec.ReleaseTime).AddHours(6).AddMinutes(1);
                dts.Add(dt);
            }

            SymbolTimeStatsUtils utils = new SymbolTimeStatsUtils();
            var tstats = utils.GetSymbolTimePeriodStats(dts);

            var tJson = (from r in tstats
                         select new
            {
                r.Symbol,
                r.DateTimeBeginAnchor,
                r.DateTimeBegin,
                r.DateTimeEnd,
                r.DateTimeEndAnchor,
                r.Open,
                r.High,
                r.Low,
                r.Close,
                r.PipMultiplier,
                r.PipsHigh,
                r.PipsLow,
                r.PipsRange
            }).ToList();

            //foreach (var r in tJson)
            //{
            //    var x = string.Format("{0}",
            //                 r.Symbol,
            //                 r.DateTimeBeginAnchor,
            //                 r.DateTimeBegin,
            //                 r.DateTimeEnd,
            //                 r.DateTimeEndAnchor,
            //                 r.Open,
            //                 r.High,
            //                 r.Low,
            //                 r.Close,
            //                 r.PipMultiplier,
            //                 r.PipsHigh,
            //                 r.PipsLow,
            //                 r.PipsRange);
            //}

            var jsonTimeStats = JsonConvert.SerializeObject(tJson, Formatting.Indented);

            // var jsonTimeStats = tstats.ToJson();
            File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "nfpTimeStats.json"), jsonTimeStats);
        }
コード例 #2
0
        public static async Task <IndicatorPrices> Load(this IndicatorPrices indicatorPrices, string country, string indicator)
        {
            var ntpIndicatorData = new NtpIndicatorData();

            List <IndicatorData> recs = new List <IndicatorData>();

            recs = await ntpIndicatorData.GetIndicatorsForCcyAndName("USD", "Non-Farm Employment Change");

            indicatorPrices           = new IndicatorPrices();
            indicatorPrices.Currency  = "USD";
            indicatorPrices.Indicator = "Non-Farm Employment Change";

            indicatorPrices.IndicatorDetails = (from r in recs
                                                select new IndicatorDetail
            {
                Actual = r.Actual,
                EventId = r.EventId,
                Forecast = r.Forecast,
                Id = r.Id,
                Previous = r.Previous,
                ReleaseDate = r.ReleaseDate,
                ReleaseDateTime = DateTime.Parse(r.ReleaseDate + " " + r.ReleaseTime).AddHours(6).AddMinutes(1),                                     // r.ReleaseDateTime,
                ReleaseTime = r.ReleaseTime
            }).ToList();;

            foreach (var rec in indicatorPrices.IndicatorDetails)
            {
                var fxp = new ForexPrices();
                fxp.Read(rec.ReleaseDateTime.Date);
                fxp.PriceRecords = fxp.PriceRecords
                                   .Where(r => r.PriceDateTime.TimeOfDay >= rec.ReleaseDateTime.TimeOfDay && r.PriceDateTime.TimeOfDay <= rec.ReleaseDateTime.AddMinutes(180).TimeOfDay)
                                   .ToList();

                foreach (var symbol in fxp.Symbols)
                {
                    IndicatorDetailPrices idp = new IndicatorDetailPrices();
                    idp.Symbol       = symbol;
                    idp.PricesDetail = (from r in fxp.PriceRecords where r.Symbol == symbol select new IndicatorDetailPricesDetail
                    {
                        Close = r.Close,
                        High = r.High,
                        Low = r.Low,
                        Open = r.Open,
                        PriceDateTime = r.PriceDateTime.DateTime
                    }).ToList();
                    rec.IndicatorDetailPrices.Add(idp);
                }

                // rec.ForexPrices.Add(fxp);

                Console.WriteLine(rec.ReleaseDateTime.Date);
            }
            return(indicatorPrices);
        }
コード例 #3
0
        static async Task getIndicators()
        {
            var ntpIndicatorData      = new NtpIndicatorData();
            List <IndicatorData> recs = await ntpIndicatorData.GetIndicatorsForCcyAndName("USD", "Non-Farm Employment Change");

            List <string> csvList  = new List <string>();
            List <string> csvStats = new List <string>();

            csvStats.Add(ForexTimePeriodStats.ToTimeStatCsvHeader());
            foreach (var rec in recs)
            {
                // Console.WriteLine(rec.ReleaseDateTime.AddHours(2));
                var dt = DateTime.Parse(rec.ReleaseDate + " " + rec.ReleaseTime).AddHours(6).AddMinutes(1);
                rec.ReleaseDateTime = dt;
                Console.WriteLine(rec.ReleaseDateTime);

                var fxp = new ForexPrices();
                try
                {
                    fxp.Read(dt, "EURUSD");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    continue;
                }
                fxp.PriceRecords = fxp.PriceRecords
                                   .Where(r => r.PriceDateTime.TimeOfDay >= rec.ReleaseDateTime.TimeOfDay && r.PriceDateTime.TimeOfDay <= rec.ReleaseDateTime.AddMinutes(180).TimeOfDay)
                                   .ToList();
                Console.WriteLine("price recs: " + fxp.PriceRecords.Count());
                Console.WriteLine("");
                //csvList.AddRange(fxp.PriceRecords.ToCsvListOHLC());
                //csvList.Add("");
                if (fxp.SymbolTimeStats.Count() > 0)
                {
                    csvStats.AddRange(fxp.SymbolTimeStats.ToCsv());
                }
                else
                {
                    Console.WriteLine("no recs");
                }
            }

            // File.WriteAllLines("nfpList.csv", csvList.ToArray());
            File.WriteAllLines("nfpListTimeStats.csv", csvStats.ToArray());
        }