Ejemplo n.º 1
0
        public static TickImpl NewTrade(string sym, int date, int time, decimal trade, int size, string ex)
        {
            TickImpl t = new TickImpl(sym)
            {
                Date     = date,
                Time     = time,
                Trade    = trade,
                Size     = size,
                Exchange = ex.Trim(),
                Bid      = 0
            };

            return(t);
        }
Ejemplo n.º 2
0
        public static Tick Deserialize(string msg)
        {
            string[] r = msg.Split(',');
            TickImpl t = new TickImpl();
            decimal  d;
            int      i;

            t.Symbol = r[(int)TickField.Symbol];
            if (decimal.TryParse(r[(int)TickField.Trade], NumberStyles.Any, CultureInfo.InvariantCulture, out d))
            {
                t.Trade = d;
            }
            if (decimal.TryParse(r[(int)TickField.Bid], NumberStyles.Any, CultureInfo.InvariantCulture, out d))
            {
                t.Bid = d;
            }
            if (decimal.TryParse(r[(int)TickField.Ask], NumberStyles.Any, CultureInfo.InvariantCulture, out d))
            {
                t.Ask = d;
            }
            if (int.TryParse(r[(int)TickField.Tsize], out i))
            {
                t.Size = i;
            }
            if (int.TryParse(r[(int)TickField.Asksize], out i))
            {
                t.OfferSize = i;
            }
            if (int.TryParse(r[(int)TickField.Bidsize], out i))
            {
                t.BidSize = i;
            }
            if (int.TryParse(r[(int)TickField.Time], out i))
            {
                t.Time = i;
            }
            if (int.TryParse(r[(int)TickField.Date], out i))
            {
                t.Date = i;
            }
            if (int.TryParse(r[(int)TickField.Tdepth], out i))
            {
                t.Depth = i;
            }
            t.Exchange    = r[(int)TickField.Tex];
            t.BidExchange = r[(int)TickField.Bidex];
            t.AskExchange = r[(int)TickField.Askex];
            t.Datetime    = t.Date * 1000000 + t.Time;
            return(t);
        }
Ejemplo n.º 3
0
        public static TickImpl NewQuote(string sym, int date, int time, decimal bid, decimal ask, int bidsize, int asksize, string be, string oe, int depth)
        {
            TickImpl q = new TickImpl(sym)
            {
                Date        = date,
                Time        = time,
                Bid         = bid,
                Ask         = ask,
                BidExchange = be.Trim(),
                AskExchange = oe.Trim(),
                AskSize     = asksize,
                BidSize     = bidsize,
                Trade       = 0,
                Size        = 0,
                Depth       = depth
            };

            return(q);
        }
Ejemplo n.º 4
0
        // normalized to bs/os
        public static TickImpl Copy(Tick c)
        {
            TickImpl k = new TickImpl();

            if (c.Symbol != "")
            {
                k._sym = c.Symbol;
            }
            k._time     = c.Time;
            k._date     = c.Date;
            k._datetime = c.Datetime;
            k._size     = c.Size;
            k._depth    = c.Depth;
            k.Trade     = c.Trade;
            k.Bid       = c.Bid;
            k.Ask       = c.Ask;
            k._bs       = c.BidSize;
            k._os       = c.AskSize;
            k._be       = c.BidExchange;
            k._oe       = c.AskExchange;
            k._ex       = c.Exchange;
            k._symidx   = c.Symidx;
            return(k);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// this constructor creates a new tick by combining two ticks this is to handle tick
        /// updates that only provide bid/ask changes.
        /// </summary>
        /// <param name="a">old tick</param>
        /// <param name="b">new tick or update</param>
        public static Tick Copy(TickImpl a, TickImpl b)
        {
            TickImpl k = new TickImpl();

            if (b.Symbol != a.Symbol)
            {
                return(k);                      // don't combine different symbols
            }
            if (b.Time < a.Time)
            {
                return(k);                 // don't process old updates
            }
            k.Time     = b.Time;
            k.Date     = b.Date;
            k.Datetime = b.Datetime;
            k.Symbol   = b.Symbol;
            k.Depth    = b.Depth;
            k.Symidx   = b.Symidx;
            if (b.IsTrade)
            {
                k.Trade    = b.Trade;
                k.Size     = b.Size;
                k.Exchange = b.Exchange;
                //
                k.Bid         = a.Bid;
                k.Ask         = a.Ask;
                k.OfferSize   = a.OfferSize;
                k.BidSize     = a.BidSize;
                k.BidExchange = a.BidExchange;
                k.AskExchange = a.AskExchange;
            }
            if (b.HasAsk && b.HasBid)
            {
                k.Bid         = b.Bid;
                k.Ask         = b.Ask;
                k.BidSize     = b.BidSize;
                k.OfferSize   = b.OfferSize;
                k.BidExchange = b.BidExchange;
                k.AskExchange = b.AskExchange;
                //
                k.Trade    = a.Trade;
                k.Size     = a.Size;
                k.Exchange = a.Exchange;
            }
            else if (b.HasAsk)
            {
                k.Ask         = b.Ask;
                k.OfferSize   = b.OfferSize;
                k.AskExchange = b.AskExchange;
                //
                k.Bid         = a.Bid;
                k.BidSize     = a.BidSize;
                k.BidExchange = a.BidExchange;
                k.Trade       = a.Trade;
                k.Size        = a.Size;
                k.Exchange    = a.Exchange;
            }
            else if (b.HasBid)
            {
                k.Bid         = b.Bid;
                k.BidSize     = b.BidSize;
                k.BidExchange = b.BidExchange;
                //
                k.Ask         = a.Ask;
                k.OfferSize   = a.OfferSize;
                k.AskExchange = a.AskExchange;
                k.Trade       = a.Trade;
                k.Size        = a.Size;
                k.Exchange    = a.Exchange;
            }
            return(k);
        }