public static BarList FromTIK(string filename) { SecurityImpl s = SecurityImpl.FromTIK(filename); s.HistSource.gotTick += new TickDelegate(HistSource_gotTick); _fromepf = new BarListImpl(s.Symbol); while (s.HistSource.NextTick()) { ; } return(_fromepf); }
SecurityImpl getsec(string file) { try { SecurityImpl s = SecurityImpl.FromTIK(file); return(s); } catch (Exception ex) { debug("error reading TIK file: " + file + " err: " + ex.Message + ex.StackTrace); return(null); } }
/// <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(); } } }
/// <summary> /// create barlist from a tik file using given intervals/types /// </summary> /// <param name="filename"></param> /// <param name="uselast"></param> /// <param name="usebid"></param> /// <param name="intervals"></param> /// <param name="types"></param> /// <returns></returns> public static BarList FromTIK(string filename, bool uselast, bool usebid, int[] intervals, BarInterval[] types) { _uselast = uselast; _usebid = usebid; SecurityImpl s = SecurityImpl.FromTIK(filename); s.HistSource.gotTick += new TickDelegate(HistSource_gotTick); _fromepf = new BarListImpl(s.Symbol, intervals, types); while (s.HistSource.NextTick()) { ; } return(_fromepf); }
/// <summary> /// Reinitialize the cache /// </summary> public void Initialize() { if (_inited) { return; // only init once } if (_tickfiles.Length == 0) { // get our listings of historical files (idx and epf) string[] files = Directory.GetFiles(_folder, tickext); _tickfiles = _filter.Allows(files); } // now we have our list, initialize instruments from files foreach (string file in _tickfiles) { SecurityImpl s = SecurityImpl.FromTIK(file); if ((s != null) && s.isValid && s.HistSource.isValid) { Workers.Add(new simworker(s)); } } // setup our initial index idx = genidx(Workers.Count); cidx = new int[Workers.Count]; D("Initialized " + (_tickfiles.Length) + " instruments."); D(string.Join(Environment.NewLine.ToString(), _tickfiles)); // read in single tick just to get first time for user FillCache(1); // get total ticks represented by files _availticks = 0; for (int i = 0; i < Workers.Count; i++) { if (Workers[i].workersec != null) { _availticks += Workers[i].workersec.ApproxTicks; } } D("Approximately " + TicksPresent + " ticks to process..."); _inited = true; // set first time as hint for user setnexttime(); }
public static bool PlayHistoricalTicks(Response r, GenericTracker <string> symbols, DateTime start, DateTime endexclusive, int expecteddays, DebugDelegate deb) { bool skipexpected = expecteddays == 0; // prepare to track actual days for each symbol GenericTracker <int> actualdays = new GenericTracker <int>(); foreach (string sym in symbols) { actualdays.addindex(sym, 0); } // prepare to track all tickfiles Dictionary <string, List <string> > files = new Dictionary <string, List <string> >(); // get all required tickfiles for each symbol on each date DateTime now = new DateTime(start.Ticks); int tfc = 0; while (now < endexclusive) { // get the tick files List <string> allfiles = TikUtil.GetFilesFromDate(Util.TLTickDir, Util.ToTLDate(now)); // go through them all and see if we find expected number foreach (string fn in allfiles) { // get security SecurityImpl sec = SecurityImpl.FromTIK(fn); // see if we want this symbol int idx = symbols.getindex(sec.HistSource.RealSymbol); if (idx < 0) { idx = symbols.getindex(sec.Symbol); } sec.HistSource.Close(); // skip if we don't if (idx < 0) { continue; } string sym = symbols.getlabel(idx); // if we have it, count actual day actualdays[idx]++; // save file and symbol if (!files.ContainsKey(sym)) { files.Add(sym, new List <string>()); } files[sym].Add(fn); // count files tfc++; } // add one day now = now.AddDays(1); } // notify if (deb != null) { deb("found " + tfc + " tick files matching dates: " + Util.ToTLDate(start) + "->" + Util.ToTLDate(endexclusive) + " for: " + string.Join(",", symbols.ToArray())); } // playback when actual meets expected bool allok = true; foreach (string sym in symbols) { if (skipexpected || (actualdays[sym] >= expecteddays)) { // get tick files string[] tf = files[sym].ToArray(); // notify if (deb != null) { deb(sym + " playing back " + tf.Length + " tick files."); } // playback HistSim h = new SingleSimImpl(tf); h.GotTick += new TickDelegate(r.GotTick); h.PlayTo(MultiSimImpl.ENDSIM); h.Stop(); // notify if (deb != null) { deb(sym + " completed playback. "); } } else { allok = false; } } return(allok); }
SecurityImpl getsec(string file) { SecurityImpl s = SecurityImpl.FromTIK(file); return(s); }