Beispiel #1
0
 /// <summary>
 /// create file from ticks
 /// </summary>
 /// <param name="ticks"></param>
 /// <param name="debs"></param>
 /// <returns></returns>
 public static bool TicksToFile(Tick[] ticks, DebugDelegate debs)
 {
     try
     {
         TikWriter tw = new TikWriter();
         foreach (Tick k in ticks)
         {
             tw.newTick(k);
         }
         tw.Close();
         if (debs != null)
         {
             debs(tw.RealSymbol + " saved " + tw.Count + " ticks to: " + tw.Filepath);
         }
     }
     catch (Exception ex)
     {
         if (debs != null)
         {
             debs(ex.Message + ex.StackTrace);
         }
         return(false);
     }
     return(true);
 }
Beispiel #2
0
 /// <summary>
 /// converts EPF files to tradelink tick files in current directory
 /// </summary>
 /// <param name="args"></param>
 public static void EPF2TIK(string[] args)
 {
     // get a list of epf files
     foreach (string file in args)
     {
         SecurityImpl sec = SecurityImpl.FromTIK(file);
         sec.HistSource.gotTick += new TradeLink.API.TickDelegate(HistSource_gotTick);
         _tw = new TikWriter(sec.Symbol);
         while (sec.NextTick())
         _tw.Close();
     }
 }
Beispiel #3
0
 /// <summary>
 /// converts EPF files to tradelink tick files in current directory
 /// </summary>
 /// <param name="args"></param>
 public static void EPF2TIK(string[] args)
 {
     // get a list of epf files
     foreach (string file in args)
     {
         SecurityImpl sec = SecurityImpl.FromTIK(file);
         sec.HistSource.gotTick += new TradeLink.API.TickDelegate(HistSource_gotTick);
         _tw = new TikWriter(sec.Symbol);
         while (sec.NextTick())
         {
             _tw.Close();
         }
     }
 }
Beispiel #4
0
        public static bool TicksToFile(Tick[] ticks, DebugDelegate debs)
        {
            try
            {
                TikWriter tw = new TikWriter();
                foreach (Tick k in ticks)
                    tw.newTick(k);
                tw.Close();
                if (debs != null)
                    debs(tw.RealSymbol + " saved " + tw.Count + " ticks to: " + tw.Filepath);

            }
            catch (Exception ex)
            {
                if (debs != null)
                    debs(ex.Message + ex.StackTrace);
                return false;
            }
            return true;
        }
Beispiel #5
0
 public static bool ChartSave(BarList bl, string path, int date)
 {
     try
     {
         Directory.CreateDirectory(path);
     }
     catch { return false; }
     try
     {
         if (date == 0)
             date = bl.RecentBar.Bardate;
         string fn = TikWriter.SafeFilename(bl.Symbol, path, date);
         if (System.IO.File.Exists(fn))
         {
             try { System.IO.File.Delete(fn); }
             catch { return false; }
         }
         TikWriter tw = new TikWriter(path, bl.Symbol, date);
         foreach (Bar b in bl)
         {
             Tick[] ticks = BarImpl.ToTick(b);
             foreach (Tick k in ticks)
                 tw.newTick(k);
         }
         tw.Close();
         return true;
     }
     catch { }
     return false;
 }
        double writeandread(Tick[] data, int date, bool printperf)
        {            
            // clear out the read buffer
            readdata.Clear();
            // keep track of time
            double elapms;
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            // write new file from data
            TikWriter tw = new TikWriter(PATH,data[0].symbol,date==0 ? data[0].date: date);
            string FILE = tw.Filepath;
            sw.Start();
            foreach (Tick k in data)
                tw.newTick(k);
            sw.Stop();
            tw.Close();
            elapms = (double)sw.ElapsedMilliseconds;
            if (printperf)
                Console.WriteLine("write speed (ticks/sec): " + (data.Length / (elapms / 1000)).ToString("n0"));

            // read file back in from file
            TikReader tr = new TikReader(FILE);
            tr.gotTick += new TickDelegate(tr_gotTick);
            sw.Reset();
            sw.Start();
            while (tr.NextTick()) ;
            sw.Stop();
            tr.Close();
            elapms = (double)sw.ElapsedMilliseconds;
            if (printperf)
                Console.WriteLine("read speed (ticks/sec): " + (data.Length/(elapms/1000)).ToString("n0"));

            // remove file
            removefile(FILE);
            
            return elapms;
        }
Beispiel #7
0
        /// <summary>
        /// build the index
        /// </summary>
        public void Start()
        {
            const int RATE    = 30000;
            int       esttick = estsize() / 40;
            double    est     = esttick / RATE;
            TimeSpan  ts      = new TimeSpan(0, 0, (int)est);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            debug("Starting creation of index... estimated: " + ts.ToString());
            // start the workers
            for (int i = 0; i < TOC.GetLength(0); i++)
            {
                // try provided path
                string fn = TOC[i, 0];
                // ensure file exists
                if (File.Exists(fn))
                {
                    readers.Add(new tickreader(i, fn, _binaryindex, Interval));
                }
                else
                {
                    // try default path
                    fn = Folder + "\\" + Path.GetFileName(TOC[i, 0]);
                    if (File.Exists(fn))
                    {
                        readers.Add(new tickreader(i, fn, _binaryindex, Interval));
                    }
                    else
                    {
                        debug(fn + " not found.");
                    }
                }
            }
            debug("Started " + readers.Count + " readers, waiting for completition");
            // wait till they're done
            _running = true;
            while (_running)
            {
                System.Threading.Thread.Sleep(SLEEP);
                bool busy = false;
                for (int i = 0; i < readers.Count; i++)
                {
                    busy |= readers[i].IsBusy;
                }
                _running = busy;
            }
            debug("Readers completed, assembling master index.");
            _running = false;
            // estimate size
            int  size     = 0;
            bool finished = true;

            foreach (tickreader tr in readers)
            {
                finished &= tr.finished;
                size     += tr.count;
            }
            // append to single arrays
            List <long> times = new List <long>(size);
            List <int>  index = new List <int>(size);

            foreach (tickreader tr in readers)
            {
                times.AddRange(tr.datetimes);
                index.AddRange(tr.index);
            }
            long[] ltimes = times.ToArray();
            int[]  iindex = index.ToArray();
            // sort master array
            Array.Sort(ltimes, iindex);
            // save play index
            _idx = iindex;
            // save times
            _times = ltimes;
            // see if we're saving binary index
            if (_binaryindex)
            {
                // fake symbol name
                string sym = MD5(indextoc(this));
                // ensure binary index folder exists
                if (!Directory.Exists(IndexFolder))
                {
                    Directory.CreateDirectory(IndexFolder);
                }
                // create file
                TikWriter tw = new TikWriter(IndexFolder, sym, 0);
                // get a filename
                _binaryidx = tw.Filepath;
                debug("Creating binary index: " + BinaryIndex);
                // master tick list
                Tick[] ktiks = new Tick[times.Count];
                ltimes = times.ToArray();
                int next = 0;
                for (int i = 0; i < readers.Count; i++)
                {
                    int len = readers[i].ticks.Count;
                    readers[i].ticks.CopyTo(0, ktiks, next, len);
                    next += len;
                    readers[i].ticks.Clear();
                }
                // sort ticks
                Array.Sort(ltimes, ktiks);
                // save ticks to binary file
                int count = 0;
                for (int i = 0; i < iindex.Length; i++)
                {
                    // get tick
                    Tick k = ktiks[count++];
                    // save
                    tw.newTick(k);
                }
                tw.Close();
                debug("binary index completed containing " + count + " ticks.");
            }
            // save finish state
            _finished = finished;
            // clean up readers
            readers.Clear();
            sw.Stop();
            double actual = sw.Elapsed.TotalSeconds;
            double rate   = actual == 0 ? 0 : ltimes.Length / actual;

            debug("Master index complete.   actual: " + sw.Elapsed.ToString() + "(" + rate.ToString("N0") + " ticks/sec)");
        }
Beispiel #8
0
        /// <summary>
        /// build the index
        /// </summary>
        public void Start()
        {
            const int RATE = 30000;
            int esttick = estsize() / 40;
            double est =  esttick/ RATE;
            TimeSpan ts = new TimeSpan(0, 0, (int)est);
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            debug("Starting creation of index... estimated: "+ts.ToString());
            // start the workers
            for (int i = 0; i < TOC.GetLength(0); i++)
            {
                // try provided path
                string fn = TOC[i, 0];
                // ensure file exists
                if (File.Exists(fn))
                    readers.Add(new tickreader(i, fn, _binaryindex, Interval));
                else
                {
                    // try default path
                    fn = Folder + "\\" + Path.GetFileName(TOC[i, 0]);
                    if (File.Exists(fn))
                        readers.Add(new tickreader(i, fn, _binaryindex, Interval));
                    else
                        debug(fn + " not found.");
                }
            }
            debug("Started "+readers.Count+" readers, waiting for completition");
            // wait till they're done
            _running = true;
            while (_running)
            {
                System.Threading.Thread.Sleep(SLEEP);
                bool busy = false;
                for (int i = 0; i < readers.Count; i++)
                    busy |= readers[i].IsBusy;
                _running = busy;
            }
            debug("Readers completed, assembling master index.");
            _running = false;
            // estimate size
            int size = 0;
            bool finished = true;
            foreach (tickreader tr in readers)
            {
                finished &= tr.finished;
                size += tr.count;
            }
            // append to single arrays
            List<long> times = new List<long>(size);
            List<int> index = new List<int>(size);
            foreach (tickreader tr in readers)
            {
                times.AddRange(tr.datetimes);
                index.AddRange(tr.index);
            }
            long[] ltimes = times.ToArray();
            int[] iindex = index.ToArray();
            // sort master array
            Array.Sort(ltimes, iindex);
            // save play index
            _idx = iindex;
            // save times
            _times = ltimes;
            // see if we're saving binary index
            if (_binaryindex)
            {
                // fake symbol name
                string sym = MD5(indextoc(this));
                // ensure binary index folder exists
                if (!Directory.Exists(IndexFolder))
                    Directory.CreateDirectory(IndexFolder);
                // create file
                TikWriter tw = new TikWriter(IndexFolder, sym, 0);
                // get a filename
                _binaryidx = tw.Filepath;
                debug("Creating binary index: "+BinaryIndex);
                // master tick list
                Tick[] ktiks = new Tick[times.Count];
                ltimes = times.ToArray();
                int next = 0;
                for (int i = 0; i < readers.Count; i++)
                {
                    int len = readers[i].ticks.Count;
                    readers[i].ticks.CopyTo(0, ktiks, next, len);
                    next += len;
                    readers[i].ticks.Clear();
                }
                // sort ticks
                Array.Sort(ltimes, ktiks);
                // save ticks to binary file
                int count = 0;
                for (int i = 0; i < iindex.Length; i++)
                {
                    // get tick
                    Tick k = ktiks[count++];
                    // save
                    tw.newTick(k);
                }
                tw.Close();
                debug("binary index completed containing " + count + " ticks.");

            }
            // save finish state
            _finished = finished;
            // clean up readers
            readers.Clear();
            sw.Stop();
            double actual = sw.Elapsed.TotalSeconds;
            double rate =  actual == 0 ? 0 : ltimes.Length / actual;
            debug("Master index complete.   actual: "+sw.Elapsed.ToString()+"("+rate.ToString("N0")+" ticks/sec)");
            
        }