public bool Watch(Tick tick, int NoTicksAlertWait) { int last = tick.time; if (!_last.ContainsKey(tick.symbol)) { _last.Add(tick.symbol, last); if (_alertonfirst) // if we're notifying when first tick arrives, do it. { if (FirstTick != null) { FirstTick(SecurityImpl.Parse(tick.symbol)); } } return(true); } int span = Util.FTDIFF(_last[tick.symbol], last); bool alert = span > NoTicksAlertWait; _last[tick.symbol] = last; if (alert && (Alerted != null)) { Alerted(SecurityImpl.Parse(tick.symbol, _last[tick.symbol])); } return(!alert); }
/// <summary> /// Sends the alerts for tickstreams who have gone idle based on the provided datetime. /// </summary> /// <param name="date">The datetime.</param> /// <param name="AlertSecondsWithoutTick">The alert seconds without tick.</param> public void SendAlerts(DateTime date, int AlertSecondsWithoutTick) { foreach (string sym in _last.Keys) { if (Alerted != null) { if (Util.FTDIFF(_last[sym], Util.DT2FT(date)) > AlertSecondsWithoutTick) { Alerted(SecurityImpl.Parse(sym, _last[sym])); } } } }
/// <summary> /// Initilize the reading of an EPF file and return the header as a Stock object. /// </summary> /// <param name="EPFfile">The EP ffile.</param> /// <returns></returns> public static SecurityImpl InitEpf(StreamReader EPFfile) { StreamReader cf = EPFfile; string symline = cf.ReadLine(); string dateline = cf.ReadLine(); Regex se = new Regex("=[$^a-z-A-Z0-9]+"); Regex dse = new Regex(@"; Date=([0-9]+)/([0-9]+)/([0-9]+).*$"); MatchCollection r = se.Matches(symline, 0); string t = r[0].Value; string symbol = t.Substring(1, t.Length - 1); SecurityImpl s = SecurityImpl.Parse(symbol.ToUpper()); string date = dateline.Contains("/") ? dse.Replace(dateline, "20$3$1$2") : Regex.Match(dateline, "[0-9]+").ToString(); s.Date = Convert.ToInt32(date); return(s); }
public static Tick Deserialize(string msg) { string [] r = msg.Split(','); Tick t = new TickImpl(); t.Sec = SecurityImpl.Parse(r[(int)TickField.symbol]); t.symbol = t.Sec.Symbol; t.trade = Convert.ToDecimal(r[(int)TickField.trade]); t.size = Convert.ToInt32(r[(int)TickField.tsize]); t.bid = Convert.ToDecimal(r[(int)TickField.bid]); t.ask = Convert.ToDecimal(r[(int)TickField.ask]); t.os = Convert.ToInt32(r[(int)TickField.asksize]); t.bs = Convert.ToInt32(r[(int)TickField.bidsize]); t.ex = r[(int)TickField.tex]; t.be = r[(int)TickField.bidex]; t.oe = r[(int)TickField.askex]; t.time = Convert.ToInt32(r[(int)TickField.time]); t.date = Convert.ToInt32(r[(int)TickField.date]); t.datetime = t.date * 1000000 + t.time; t.depth = Convert.ToInt32(r[(int)TickField.tdepth]); return(t); }
public static BasketImpl Deserialize(string serialBasket) { BasketImpl mb = new BasketImpl(); if ((serialBasket == null) || (serialBasket == "")) { return(mb); } string[] r = serialBasket.Split(','); for (int i = 0; i < r.Length; i++) { if (r[i] == "") { continue; } SecurityImpl sec = SecurityImpl.Parse(r[i]); if (sec.isValid) { mb.Add(sec); } } return(mb); }
/// <summary> /// adds a security if not already present /// </summary> /// <param name="sym"></param> public void Add(string sym) { var sec = SecurityImpl.Parse(sym); Add(sec); }