void ReadHeader() { // get version id ReadByte(); // get version _filever = ReadInt32(); if (_filever != TikConst.FILECURRENTVERSION) { throw new BadTikFile("version: " + _filever + " expected: " + TikConst.FILECURRENTVERSION); } // get real symbol _realsymbol = ReadString(); // get security from symbol _sec = TradeLink.Common.SecurityImpl.Parse(_realsymbol); _sec.Date = SecurityImpl.SecurityFromFileName(_path).Date; // get short symbol _sym = _sec.symbol; // get end of header ReadByte(); // make sure we read something if (_realsymbol.Length <= 0) { throw new BadTikFile("no symbol defined in tickfile"); } // flag header as read _haveheader = true; }
/// <summary> /// get tick files created on a certain date /// </summary> /// <param name="tickfolder"></param> /// <param name="date"></param> /// <returns></returns> public static List <string> GetFilesFromDate(string tickfolder, int date) { string[] files = TikUtil.GetFiles(tickfolder, TikConst.WILDCARD_EXT); List <string> matching = new List <string>(); foreach (string file in files) { SecurityImpl sec = SecurityImpl.SecurityFromFileName(file); string symfix = System.IO.Path.GetFileNameWithoutExtension(sec.Name); if (sec.Date == date) { matching.Add(file); } } return(matching); }
/// <summary> /// play simulation until specified day/time is hit /// </summary> /// <param name="datetime"></param> virtual public void PlayTo(long datetime) { // check for event if (GotTick == null) { debug("Not handling ticks, quitting..."); return; } // handle non binary indicies if (!myhsi.isBinaryIndex) { // make sure inited if (!hsipinited) { Initialize(); // wait a moment System.Threading.Thread.Sleep(WaitRead * 2); } // ensure reader is done while (_reader.IsBusy) { _reader.CancelAsync(); } // start reading _reader.RunWorkerAsync(datetime); stopwatch(); // start writing while (hsipplay && (hsip_nexttime <= datetime)) { if (_buf.hasItems) { Tick k = _buf.Read(); gotnewtick(k); } else if (!_reader.IsBusy) { break; } System.Threading.Thread.Sleep(_writewait); } stopwatch(); } else { debug("Playing index containing " + myhsi.TicksPresent.ToString("N0") + " ticks."); TikReader tw = new TikReader(myhsi.BinaryIndex); // reset counters br = 0; tw.gotTick += new TickDelegate(tw_gotTick); // get symbols for every toc string[] syms = new string[myhsi.TOCTicks.Length]; for (int i = 0; i < syms.Length; i++) { syms[i] = SecurityImpl.SecurityFromFileName(myhsi.TOCTicks[i]).symbol; } // get symbol for every tick symidx = new string[TicksPresent]; for (int i = 0; i < symidx.Length; i++) { symidx[i] = syms[myhsi.Playindex[i]]; } // playback ticks stopwatch(); while (hsipplay && (hsip_nexttime <= datetime) && tw.NextTick()) { } stopwatch(); } }