Ejemplo n.º 1
0
        /// <summary>
        /// Load a security from a zipfile containing a historical tick file
        /// </summary>
        /// <param name="zipfile"></param>
        /// <param name="tikfile"></param>
        /// <returns></returns>
        public static SecurityImpl FromZip(string zipfile, string tikfile)
        {
            TikReader    tr = new TikReader(zipfile, tikfile);
            SecurityImpl s  = (SecurityImpl)tr.ToSecurity();

            if (s.IsValid && tr.IsValid)
            {
                s.HasHistorical = true;
                s.HistSource    = tr;
                s.ApproxTicks   = s.HistSource.ApproxTicks;
            }
            return(s);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// determine security from the filename, without opening file (use SecurityImpl.FromFile to
 /// actually read it in)
 /// </summary>
 /// <param name="filename"></param>
 /// <returns></returns>
 public static SecurityImpl SecurityFromFileName(string filename)
 {
     try
     {
         filename = Path.GetFileName(filename);
         string       ds  = Regex.Match(filename, "([0-9]{8})[.]", RegexOptions.IgnoreCase).Result("$1");
         string       sym = filename.Replace(ds, "").Replace(TikConst.DotExt, "");
         SecurityImpl s   = new SecurityImpl(sym)
         {
             Date = Convert.ToInt32(ds)
         };
         return(s);
     }
     catch (Exception) { }
     return(new SecurityImpl());
 }
Ejemplo n.º 3
0
        /// <summary>
        /// get a security form a user-specified string
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        public static SecurityImpl Parse(string msg, int date)
        {
            string[]     r   = msg.Split(' ');
            SecurityImpl sec = new SecurityImpl {
                Name = r[0]
            };

            // look for option first
            if (msg.Contains("OPT") || msg.Contains("PUT") || msg.Contains("CALL") || msg.Contains("FOP") || msg.Contains("FUT"))
            {
                if (msg.Contains("OPT") || msg.Contains("PUT") || msg.Contains("CALL"))
                {
                    sec.Type = SecurityType.Option;
                }

                if (msg.Contains("FUT"))
                {
                    sec.Type = SecurityType.Future;
                }

                msg         = msg.ToUpper();
                sec.Details = msg.Contains("PUT") ? "PUT" : (msg.Contains("CALL") ? "CALL" : string.Empty);
                msg         = msg.Replace("CALL", "");
                msg         = msg.Replace("PUT", "");
                msg         = msg.Replace("OPT", "");
                msg         = msg.Replace("FOP", "");
                msg         = msg.Replace("FUT", "");
                r           = msg.Split(' ');
                sec.Name    = r[0];
                sec.Date    = ExpirationDate(ref r);
                sec.DestEx  = Ex(sec.Name, ref r);
            }
            else if (r.Length > 2)
            {
                int f2Id = SecurityId(r[2]);
                int f1Id = SecurityId(r[1]);
                if (f2Id != -1)
                {
                    sec.Type   = (SecurityType)f2Id;
                    sec.DestEx = r[1];
                }
                else if (f1Id != -1)
                {
                    sec.Type   = (SecurityType)f1Id;
                    sec.DestEx = r[2];
                }
            }
            else if (r.Length > 1)
            {
                int f1Id = SecurityId(r[1]);
                if (f1Id != -1)
                {
                    sec.Type = (SecurityType)f1Id;
                }
                else
                {
                    sec.DestEx = r[1];
                }
            }
            else
            {
                sec.Type = SecurityType.Equity;
            }
            if (date != 0)
            {
                sec.Date = date;
            }
            if (sec.HasDest && !sec.HasType)
            {
                sec.Type = TypeFromExchange(sec.DestEx);
            }
            return(sec);
        }