Esempio n. 1
0
        /// <summary>
        /// returns ohlc stats for the price series - all symbols
        /// </summary>
        /// <param name="records"></param>
        /// <param name="symbol"></param>
        /// <returns></returns>
        public static ForexTimePeriodStats OHLCStats(this List <ForexPriceRecord> records)
        {
            string symbol;

            if (records.Count == 0)
            {
                return(new ForexTimePeriodStats());
            }

            symbol = records[0].Symbol;

            ForexTimePeriodStats stats =
                new ForexTimePeriodStats()
            {
                SymbolId      = records[0].SymbolId,
                Symbol        = symbol,
                DateTimeBegin = records[0].PriceDateTime,
                DateTimeEnd   = records[records.Count - 1].PriceDateTime,
                Open          = records.Open(),
                High          = records.High(),
                Low           = records.Low(),
                Close         = records.Close(),
                BidOpen       = records.BidOpen(),
                BidHigh       = records.BidHigh(),
                BidLow        = records.BidLow(),
                BidClose      = records.BidClose(),
                AskOpen       = records.AskOpen(),
                AskHigh       = records.AskHigh(),
                AskLow        = records.AskLow(),
                AskClose      = records.AskClose()
            };

            return(stats);
        }
        public static List <string> ToCsv(this List <ForexTimePeriodStats> timeStats, bool withHeader = false)
        {
            List <string> csv = new List <string>();

            if (withHeader)
            {
                csv.Add(ForexTimePeriodStats.ToTimeStatCsvHeader());
            }

            foreach (ForexTimePeriodStats rec in timeStats)
            {
                csv.Add(rec.ToTimeStatCsv());
            }
            return(csv);
        }
        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());
        }