public static void ToCsvFile(this List <ForexPriceRecord> records, string Filepath, bool IncludeHeader)
 {
     try
     {
         if (IncludeHeader)
         {
             List <string> recs = (from r in records
                                   select r.ToCsv()).ToList();
             recs.Insert(0, ForexPriceRecord.CsvHeader());
             File.WriteAllLines(Filepath, recs.ToArray());
         }
         else
         {
             File.WriteAllLines(Filepath,
                                (from r in records
                                 select r.ToCsv()).ToArray());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#2
0
 public static ForexPriceRecord Create(ForexPriceRecord rec, int symbolid)
 {
     rec.SymbolId = symbolid;
     return(rec);
 }
示例#3
0
        // not yest implimented
        public static List <ForexPriceRecord> Compress(this List <ForexPriceRecord> recs, string symbol, Periodicity period)
        {
            if (period == Periodicity.OneMinute)
            {
                return(recs);
            }

            List <ForexPriceRecord> cp = recs.Where(r => r.Symbol.Equals(symbol)).OrderBy(p => p.PriceDateTime).ToList();

            if (cp.Count < 2)
            {
                return(cp);
            }

            List <ForexPriceRecord> newRecs  = new List <ForexPriceRecord>();
            List <ForexPriceRecord> tempRecs = new List <ForexPriceRecord>();
            ForexPriceRecord        tempRec  = new ForexPriceRecord();

            ForexPriceRecord firstRec = cp.First();
            ForexPriceRecord lastRec  = cp.Last();

            int minutes = (int)period;

            double OpenPrice    = firstRec.Open;
            double BidOpenPrice = firstRec.BidOpen;
            double AskOpenPrice = firstRec.AskOpen;
            double mult         = firstRec.PipMultiplier;


            #region csv recs in 1 minute tf

            /*
             * AUDCAD	02/04/2009 12:00:00 AM +00:00	0	0	0	0	0.79936	0.79953	0.79932	0.79953	0.80073	0.80085	0.8005	0.80081
             * AUDCAD	02/04/2009 12:01:00 AM +00:00	0	0	0	0	0.79953	0.79973	0.79945	0.79973	0.80081	0.80092	0.80081	0.80092
             * AUDCAD	02/04/2009 12:02:00 AM +00:00	0	0	0	0	0.79973	0.79993	0.79925	0.79957	0.80092	0.80144	0.80064	0.80076
             * AUDCAD	02/04/2009 12:03:00 AM +00:00	0	0	0	0	0.79957	0.79957	0.79905	0.79909	0.80076	0.80076	0.80016	0.80022
             * AUDCAD	02/04/2009 12:04:00 AM +00:00	0	0	0	0	0.79909	0.79959	0.79909	0.79943	0.80022	0.8008	0.80022	0.80059
             * AUDCAD	02/04/2009 12:05:00 AM +00:00	0	0	0	0	0.79943	0.79953	0.79931	0.79948	0.80059	0.80073	0.80047	0.80068
             * AUDCAD	02/04/2009 12:06:00 AM +00:00	0	0	0	0	0.79948	0.79954	0.79936	0.79936	0.80068	0.80075	0.80056	0.80056
             * AUDCAD	02/04/2009 12:07:00 AM +00:00	0	0	0	0	0.79936	0.79961	0.79903	0.79959	0.80056	0.80091	0.80044	0.8008
             * AUDCAD	02/04/2009 12:08:00 AM +00:00	0	0	0	0	0.79959	0.79959	0.79941	0.79948	0.8008	0.8008	0.80061	0.80068
             * AUDCAD	02/04/2009 12:09:00 AM +00:00	0	0	0	0	0.79948	0.80004	0.79936	0.80004	0.80068	0.80123	0.80056	0.80123
             * AUDCAD	02/04/2009 12:10:00 AM +00:00	0	0	0	0	0.80004	0.80039	0.8	0.80039	0.80123	0.80149	0.80117	0.80149
             * AUDCAD	02/04/2009 12:11:00 AM +00:00	0	0	0	0	0.80039	0.80045	0.79989	0.80035	0.80149	0.80155	0.80136	0.80148
             * AUDCAD	02/04/2009 12:12:00 AM +00:00	0	0	0	0	0.80035	0.80043	0.80029	0.80029	0.80148	0.80154	0.80142	0.80142
             * AUDCAD	02/04/2009 12:13:00 AM +00:00	0	0	0	0	0.80029	0.80035	0.80018	0.8002	0.80142	0.80142	0.80136	0.80136
             * AUDCAD	02/04/2009 12:14:00 AM +00:00	0	0	0	0	0.8002	0.80037	0.79963	0.79989	0.80136	0.80156	0.80107	0.80107
             * AUDCAD	02/04/2009 12:15:00 AM +00:00	0	0	0	0	0.79989	0.80012	0.79965	0.79972	0.80107	0.80129	0.80085	0.80091
             * AUDCAD	02/04/2009 12:16:00 AM +00:00	0	0	0	0	0.79972	0.80041	0.79972	0.79984	0.80091	0.80176	0.80091	0.80119
             * AUDCAD	02/04/2009 12:17:00 AM +00:00	0	0	0	0	0.79984	0.80049	0.79984	0.80034	0.80119	0.80174	0.80119	0.80152
             * AUDCAD	02/04/2009 12:18:00 AM +00:00	0	0	0	0	0.80034	0.80093	0.79982	0.80062	0.80152	0.80224	0.80151	0.80193
             * AUDCAD	02/04/2009 12:19:00 AM +00:00	0	0	0	0	0.80062	0.80074	0.80019	0.80019	0.80193	0.80198	0.80147	0.80147
             */

            #endregion

            DateTimeOffset lastDto         = lastRec.PriceDateTime;
            DateTimeOffset currDto         = firstRec.PriceDateTime;
            bool           hasBidAskPrices = firstRec.HasBidAskPrices;
            ForexPriceRecord.ShowPriceOptionsEnum showPriceOpts = firstRec.ShowPriceOptions;
            int symbolId = firstRec.SymbolId;

            while (currDto <= lastDto)
            {
                DateTimeOffset endPeriodDto = currDto.AddMinutes(minutes);

                if (endPeriodDto > lastDto)
                {
                    endPeriodDto = lastDto.AddMinutes(10);
                }

                ForexPrices pr = new ForexPrices()
                {
                    PriceRecords = (from r in recs
                                    where r.PriceDateTime >= currDto & r.PriceDateTime < endPeriodDto
                                    select r).ToList()
                };

                var ts = pr.SymbolTimeStats.FirstOrDefault() as ForexPriceRecordBase;
                tempRecs.Add(new ForexPriceRecord()
                {
                    BidOpen          = ts.BidOpen,
                    BidHigh          = ts.BidHigh,
                    BidLow           = ts.BidLow,
                    BidClose         = ts.BidClose,
                    AskOpen          = ts.AskOpen,
                    AskHigh          = ts.AskHigh,
                    AskLow           = ts.AskLow,
                    AskClose         = ts.AskClose,
                    Open             = ts.Open,
                    High             = ts.High,
                    Low              = ts.Low,
                    Close            = ts.Close,
                    HasBidAskPrices  = hasBidAskPrices,
                    PriceDateTime    = currDto,
                    ShowPriceOptions = showPriceOpts,
                    Symbol           = symbol,
                    SymbolId         = symbolId
                });

                currDto = endPeriodDto;

                if (currDto >= lastDto)
                {
                    break;
                }
            }

            return(tempRecs);
        }