Пример #1
0
 public static Security SecurityFromFileName(string filename)
 {
     try
     {
         // file name with extension from path string
         filename = Path.GetFileName(filename);
         string   ds  = System.Text.RegularExpressions.Regex.Match(filename, "([0-9]{8})[.]", System.Text.RegularExpressions.RegexOptions.IgnoreCase).Result("$1");
         string   sym = filename.Replace(ds, "").Replace(".TXT", "").Replace(".txt", "");
         Security s   = Security.Deserialize(sym);
         //s.Date = Convert.ToInt32(ds);
         return(s);
     }
     catch (Exception)
     {
         return(new Security("", ""));
     }
 }
Пример #2
0
        public virtual void tickSize(int tickerId, int field, int size)
        {
            if (tickerId < 0 || tickerId > _marketDataRequests.Count)
            {
                OnDebug("can't match market data ticker.");
                return;
            }
            Tick     k  = new Tick();
            DateTime ct = DateTime.Now;

            k.Date       = ct.Year * 10000 + ct.Month * 100 + ct.Day;
            k.Time       = ct.Hour * 10000 + ct.Minute * 100 + ct.Second;
            k.FullSymbol = _marketDataRequests[tickerId].FullSymbol;

            // this will be removed
            Security sec         = Security.Deserialize(k.FullSymbol);
            bool     hundrednorm = (sec.SecurityType == "STK") || (sec.SecurityType == "NIL");

            if (field == (int)TickType.LastSize)
            {
                _marketDataRequests[tickerId].TradeSize = size;     // not adjusted by hundreds
                k.TradeSize  = _marketDataRequests[tickerId].TradeSize;
                k.TradePrice = _marketDataRequests[tickerId].TradePrice;
            }
            else if (field == (int)TickType.BidSize)
            {
                _marketDataRequests[tickerId].BidSize = size;
                k.BidPrice = _marketDataRequests[tickerId].BidPrice;
                k.BidSize  = _marketDataRequests[tickerId].BidSize;
            }
            else if (field == (int)TickType.AskSize)
            {
                _marketDataRequests[tickerId].AskSize = size;
                k.AskSize  = _marketDataRequests[tickerId].AskSize;
                k.AskPrice = _marketDataRequests[tickerId].AskPrice;
            }
            else
            {
                return;
            }
            if (k.IsValid)
            {
                OnGotTick(k);
            }
        }
Пример #3
0
        //********************************* Auxiliary Functions *************************************//
        #region Auxiliary Functions
        /// <summary>
        /// Deserialize SecurityImpl to Contract
        /// </summary>
        /// <param name="symbol">
        /// STK: LocalSymbol SMART
        /// OPT/FOP: Symbol Expiry C/P Strike Exchange Type
        /// Other; LocalSymbol Exchange Type
        /// </param>
        /// <returns></returns>
        private Contract SecurityFullNameToContract(string symbol)
        {
            Security sec      = (Security)Security.Deserialize(symbol);
            Contract contract = new Contract();

            if (sec.IsCall || sec.IsPut)
            {
                contract.Expiry = sec.Expiry.ToString();
                contract.Strike = (double)sec.Strike;
                contract.Right  = sec.IsCall ? "C" : "P";
                contract.Symbol = sec.Symbol;
            }
            else
            {
                contract.LocalSymbol = sec.Symbol;
            }

            if (sec.HasDest)
            {
                contract.Exchange = sec.Exchange;
                //contract.PrimaryExch = sec.DestEx;
            }
            else
            {
                contract.Exchange = "SMART";
            }
            if (sec.HasSecType)
            {
                contract.SecType = sec.SecurityType;
            }
            else
            {
                contract.SecType = "STK";
            }

            contract.Currency = "USD";

            return(contract);
        }