コード例 #1
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);
        }
コード例 #2
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());
        }
コード例 #3
0
        static void jsonPriceTests()
        {
            DateTime dt = new DateTime(2019, 7, 5);

            var fxp = new ForexPrices();

            fxp.Read(dt);
            fxp.PriceRecords = fxp.PriceRecords
                               .Where(r => r.PriceDateTime.TimeOfDay >= new TimeSpan(14, 31, 0) && r.PriceDateTime.TimeOfDay <= new TimeSpan(15, 31, 0))
                               .ToList();

            var json          = fxp.ToJson();
            var jsonTimeStats = fxp.SymbolTimeStats.ToJson();
            var jsonPrices    = fxp.PriceRecords.ToJson();

            // File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "fxp.json"), json);
            // File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "fxpTimeStats.json"), jsonTimeStats);
            File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "fxpPriceRecs.json"), jsonPrices);

            fxp.PriceRecords.ToCsvFileOHLC(Path.Combine(Directory.GetCurrentDirectory(), "fxp.csv"), true);
            Console.WriteLine(fxp.PriceRecords.Count());
        }