Ejemplo n.º 1
0
        public void SerializeDeserilize()
        {
            // setup imbalance
            const string s  = "IBM";
            const string e  = "NYSE";
            const int    x  = 500000;
            const int    t  = 1550;
            const int    p  = 1540;
            const int    px = 400000;
            Imbalance    i  = new ImbalanceImpl(s, e, x, t, px, p, 999);

            // verify it's valid
            Assert.IsTrue(i.isValid);

            // serialize it
            string msg = ImbalanceImpl.Serialize(i);
            // deserialize it somewhere else
            Imbalance ni = ImbalanceImpl.Deserialize(msg);

            // make sure it's valid
            Assert.IsTrue(ni.isValid);

            // verify it's the same
            Assert.AreEqual(i.Symbol, ni.Symbol);
            Assert.AreEqual(i.Exchange, ni.Exchange);
            Assert.AreEqual(i.PrevImbalance, ni.PrevImbalance);
            Assert.AreEqual(i.PrevTime, ni.PrevTime);
            Assert.AreEqual(i.ThisImbalance, ni.ThisImbalance);
            Assert.AreEqual(i.ThisTime, ni.ThisTime);
            Assert.AreEqual(i.InfoImbalance, ni.InfoImbalance);
        }
Ejemplo n.º 2
0
        void m_Session_OnNYSEImbalanceMessage(object sender, BWNYSEImbalance imbalanceMsg)
        {
            string    s   = imbalanceMsg.Symbol;
            int       i   = imbalanceMsg.ImbalanceVolume;
            int       it  = TradeLink.Common.Util.DT2FT(imbalanceMsg.Time);
            int       pi  = imbalanceMsg.InitImbalanceVolume;
            int       pt  = TradeLink.Common.Util.DT2FT(imbalanceMsg.InitTime);
            string    ex  = imbalanceMsg.FeedID.ToString();
            Imbalance imb = new ImbalanceImpl(s, ex, i, it, pi, pt, i);

            tl.newImbalance(imb);
        }
Ejemplo n.º 3
0
        public static Imbalance[] SampleImbalanceData(int count)
        {
            Random r = new Random((int)DateTime.Now.Ticks);

            string[]    syms = TradeLink.Research.RandomSymbol.GetSymbols((int)DateTime.Now.Ticks, 4, count);
            Imbalance[] imbs = new Imbalance[syms.Length];
            for (int j = 0; j < syms.Length; j++)
            {
                imbs[j] = new ImbalanceImpl(syms[j], "NYSE", r.Next(-1000, 1000) * r.Next(1000), 1550, r.Next(-1000, 1000) * r.Next(1000), 1540, 0);
            }
            return(imbs);
        }
Ejemplo n.º 4
0
        public void Performance()
        {
            const int OPS = 10000;

            Imbalance[] imbs  = SampleImbalanceData(OPS);
            DateTime    start = DateTime.Now;
            bool        v     = true;

            for (int i = 0; i < OPS; i++)
            {
                Imbalance im = ImbalanceImpl.Deserialize(ImbalanceImpl.Serialize(imbs[i]));
                v &= im.ThisImbalance == imbs[i].ThisImbalance;
            }

            double time = DateTime.Now.Subtract(start).TotalSeconds;

            Assert.IsTrue(v);
            Assert.LessOrEqual(time, .15);
            Console.WriteLine(string.Format("Imbalance performance: {0:n2} {1:n0}i/s", time, OPS / time));
        }
Ejemplo n.º 5
0
        void doquote(ref structSTIQuoteUpdate q)
        {
            Tick k = new TickImpl(q.bstrSymbol);

            k.bid = (decimal)q.fBidPrice;
            k.ask = (decimal)q.fAskPrice;
            k.bs  = q.nBidSize / 100;
            k.os  = q.nAskSize / 100;
            k.ex  = GetExPretty(q.bstrExch);
            k.be  = GetExPretty(q.bstrBidExch);
            k.oe  = GetExPretty(q.bstrAskExch);
            int now = Convert.ToInt32(q.bstrUpdateTime);

            k.date = Util.ToTLDate(DateTime.Now);
            //int sec = now % 100;
            k.time = now;

            // we don't want to simply return on out-of-order ticks because it'll prevent processing
            // of the mdx messages further in this function.
            if (!IgnoreOutOfOrderTicks || (k.time > _lasttime))
            {
                _lasttime = k.time;
                k.trade   = (decimal)q.fLastPrice;
                k.size    = q.nLastSize;
                // execute orders if papertrade is enabled
                if (isPaperTradeEnabled)
                {
                    ptt.newTick(k);
                }
                // notify clients of tick
                if (!_imbalance || (_imbalance && k.isValid))
                {
                    tl.newTick(k);
                }
            }

            /////////////////////////
            // MDX Processing
            /////////////////////////
            if (q.nMdxMsgType == 1)
            {
                if (VerboseDebugging)
                {
                    debug(q.bstrUpdateTime
                          + "  Received Regulatory Imbalance for: " + q.bstrSymbol
                          + "  ValidIntradayMarketImb: " + q.bValidIntradayMktImb
                          + "  ValidMktImb: " + q.bValidMktImb
                          + "  Imbalance: " + q.nImbalance
                          + "  iMktImbalance: " + q.nIntradayMktImbalance
                          + "  MktImbalance: " + q.nMktImbalance);
                }

                int time;
                if (int.TryParse(q.bstrUpdateTime, out time))
                {
                    Imbalance imb = new ImbalanceImpl(q.bstrSymbol, GetExPretty(q.bstrExch), q.nIntradayMktImbalance, time, 0, 0, 0);
                    tl.newImbalance(imb);
                }
            }
            else if (q.nMdxMsgType == 2)
            {
                if (VerboseDebugging)
                {
                    debug(q.bstrUpdateTime
                          + "  Received Informational Imbalance for: " + q.bstrSymbol
                          + "  ValidIntradayMarketImb: " + q.bValidIntradayMktImb
                          + "  ValidMktImb: " + q.bValidMktImb
                          + "  Imbalance: " + q.nImbalance
                          + "  iMktImbalance: " + q.nIntradayMktImbalance
                          + "  MktImbalance: " + q.nMktImbalance);
                }

                int time;
                if (int.TryParse(q.bstrUpdateTime, out time))
                {
                    Imbalance imb = new ImbalanceImpl(q.bstrSymbol, GetExPretty(q.bstrExch), 0, time, 0, 0, q.nIntradayMktImbalance);
                    tl.newImbalance(imb);
                }
            }
            else if (q.nMdxMsgType == 3)
            {
                if (VerboseDebugging)
                {
                    debug(q.bstrUpdateTime
                          + "  Received Halt/Delay for: " + q.bstrSymbol
                          + "  Status: " + q.bstrHaltResumeStatus
                          + "  Reason: " + q.bstrHaltResumeReason);
                }

                int time;
                if (int.TryParse(q.bstrUpdateTime, out time))
                {
                    HaltResume h = new HaltResumeImpl(q.bstrSymbol, GetExPretty(q.bstrExch), time, q.bstrHaltResumeStatus, q.bstrHaltResumeReason);
                    for (int clientNumber = 0; clientNumber < tl.NumClients; clientNumber++)
                    {
                        tl.TLSend(HaltResumeImpl.Serialize(h), MessageTypes.HALTRESUME, clientNumber);
                    }
                }
            }
            else if (q.nMdxMsgType == 4)
            {
                if (VerboseDebugging)
                {
                    debug(q.bstrUpdateTime
                          + "  Received Indication for: " + q.bstrSymbol
                          + "  ValidIndicators: " + q.bValidIndicators
                          + "  IndicatorHigh: " + q.fIndicatorHigh
                          + "  IndicatorLow: " + q.fIndicatorLow);
                }

                int time;
                if (int.TryParse(q.bstrUpdateTime, out time))
                {
                    Indication ind = new IndicationImpl(q.bstrSymbol, GetExPretty(q.bstrExch), time, q.bValidIndicators, (decimal)q.fIndicatorHigh, (decimal)q.fIndicatorLow);
                    for (int clientNumber = 0; clientNumber < tl.NumClients; clientNumber++)
                    {
                        tl.TLSend(IndicationImpl.Serialize(ind), MessageTypes.INDICATION, clientNumber);
                    }
                }
            }
        }