public void SerializeDeserilize()
        {
            // setup indication
            const string s = "IBM";
            const string e = "NYSE";
            const int t = 092500;
            const decimal h = 128.08m;
            const decimal l = 126.25m;
            const int v = 1;

            Indication i = new IndicationImpl(s, e, t, v, h, l);

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

            // serialize it
            string msg = IndicationImpl.Serialize(i);
            // deserialize it somewhere else
            Indication ni = IndicationImpl.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.Time, ni.Time);
            Assert.AreEqual(i.High, ni.High);
            Assert.AreEqual(i.Low, ni.Low);
        }
        public static Indication Deserialize(string msg)
        {
            IndicationImpl i = new IndicationImpl();
            string[] r = msg.Split(',');

            i._sym = r[0];
            i._ex = r[1];

            int t = 0;
            if (int.TryParse(r[2], out t))
                i._time = t;
            
            bool v = false;
            if (bool.TryParse(r[3], out v))
                i._validity = v;

            decimal d = 0;
            if (decimal.TryParse(r[4], out d))
                i._high = d;
            if (decimal.TryParse(r[5], out d))
                i._low = d;
            
            return i;
        }
Esempio n. 3
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);
                }
            }
        }