예제 #1
0
파일: TikUtil.cs 프로젝트: w1r2p1/Core-1
 /// <summary>
 /// converts EPF files to 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 += HistSource_gotTick;
         _tw = new TikWriter(sec.Name);
         while (sec.NextTick())
         {
             _tw.Close();
         }
     }
 }
예제 #2
0
 /// <summary>
 /// write header for tick file
 /// </summary>
 /// <param name="bw"></param>
 /// <param name="realsymbol"></param>
 /// <returns></returns>
 public static bool Header(TikWriter bw, string realsymbol)
 {
     bw.OutStream = new FileStream(bw.Filepath, FileMode.Create, FileAccess.Write, FileShare.Read);
     // version
     bw.Write(TikConst.Version);
     bw.Write(TikConst.Filecurrentversion);
     // full symbol name
     bw.Write(realsymbol); //
     // fields end
     bw.Write(TikConst.StartData);
     // flag header as created
     bw._hasheader = true;
     return(true);
 }
예제 #3
0
파일: TikUtil.cs 프로젝트: w1r2p1/Core-1
 /// <summary>
 /// create file from ticks
 /// </summary>
 /// <param name="ticks"></param>
 /// <param name="tw"></param>
 /// <returns></returns>
 public static bool TicksToFile(Tick[] ticks, TikWriter tw)
 {
     try
     {
         foreach (Tick k in ticks)
         {
             tw.NewTick(k);
         }
         tw.Close();
         Log.Debug(tw.RealSymbol + " saved " + tw.Count + " ticks to: " + tw.Filepath);
     }
     catch (Exception ex)
     {
         Log.Error(ex, "Error creating file from ticks");
         return(false);
     }
     return(true);
 }
예제 #4
0
        public bool NewTick(Tick t)
        {
            if (_stopped)
            {
                return(false);
            }
            if ((t.Symbol == null) || (t.Symbol == ""))
            {
                return(false);
            }
            TikWriter tw;
            // prepare last date of tick
            int lastdate;
            // get last date
            bool havedate = _datedict.TryGetValue(t.Symbol, out lastdate);

            // if we don't have date, use present date
            if (!havedate)
            {
                lastdate = t.Date;
                _datedict.Add(t.Symbol, t.Date);
            }
            // see if we need a new day
            bool samedate = lastdate == t.Date;
            // see if we have stream already
            bool havestream = _filedict.TryGetValue(t.Symbol, out tw);

            // if no changes, just save tick
            if (samedate && havestream)
            {
                try
                {
                    tw.NewTick((TickImpl)t);
                    return(true);
                }
                catch (IOException) { return(false); }
            }
            try
            {
                // if new date, close stream
                if (!samedate)
                {
                    try
                    {
                        if (tw != null)
                        {
                            tw.Close();
                        }
                    }
                    catch (IOException) { }
                }
                // ensure file is writable
                string fn = TikWriter.SafeFilename(t.Symbol, _path, t.Date);
                if (TikUtil.IsFileWritetable(fn))
                {
                    // open new stream
                    tw = new TikWriter(_path, t.Symbol, t.Date);
                    // save tick
                    tw.NewTick((TickImpl)t);
                    // save stream
                    if (!havestream)
                    {
                        _filedict.Add(t.Symbol, tw);
                    }
                    else
                    {
                        _filedict[t.Symbol] = tw;
                    }
                    // save date if changed
                    if (!samedate)
                    {
                        _datedict[t.Symbol] = t.Date;
                    }
                }
            }
            catch (IOException) { return(false); }
            catch (Exception) { return(false); }

            return(false);
        }