Пример #1
0
        public void StaticFactories()
        {
            // factory inputs
            const string  s = "TST";
            const decimal p = 13m;
            const int     z = 400;

            // produce a new ask tick
            TickImpl t = TickImpl.NewAsk(s, p, z);

            Assert.That(t.hasAsk && !t.hasBid, t.ToString());
            Assert.That(t.ask == p, t.ask.ToString());
            Assert.That(t.AskSize == z, t.AskSize.ToString());
            Assert.That(t.os == (int)(z / 100), t.os.ToString());
            Assert.That(t.symbol == s);

            // produce bid tick
            t = TickImpl.NewBid(s, p, z);
            Assert.That(t.hasBid && !t.hasAsk, t.ToString());
            Assert.That(t.bid == p, t.bid.ToString());
            Assert.That(t.BidSize == z, t.BidSize.ToString());
            Assert.That(t.bs == (int)(z / 100), t.bs.ToString());
            Assert.That(t.symbol == s);

            // produce a trade tick
            t = TickImpl.NewTrade(s, p, z);
            Assert.That(t.isTrade && !t.isQuote, t.ToString());
            Assert.That(t.trade == p, t.trade.ToString());
            Assert.That(t.TradeSize == z, t.TradeSize.ToString());
            Assert.That(t.ts == (int)(z / 100), t.ts.ToString());
            Assert.That(t.symbol == s);
        }
Пример #2
0
        public void StaticFactories()
        {
            // factory inputs
            const string  s = "TST";
            const decimal p = 13m;
            const int     z = 400;

            // produce a new ask tick
            TickImpl t = TickImpl.NewAsk(s, p, z);

            Assert.True(t.HasAsk && !t.HasBid, t.ToString());
            Assert.True(t.Ask == p, t.Ask.ToString());
            Assert.True(t.AskSize == z, t.AskSize.ToString());
            Assert.True(t.OfferSize == z, t.OfferSize.ToString());
            Assert.True(t.Symbol == s);

            // produce bid tick
            t = TickImpl.NewBid(s, p, z);
            Assert.True(t.HasBid && !t.HasAsk, t.ToString());
            Assert.True(t.Bid == p, t.Bid.ToString());
            Assert.True(t.BidSize == z, t.BidSize.ToString());
            Assert.True(t.BidSize == z, t.BidSize.ToString());
            Assert.True(t.Symbol == s);

            // produce a trade tick
            t = TickImpl.NewTrade(s, p, z);
            Assert.True(t.IsTrade && !t.IsQuote, t.ToString());
            Assert.True(t.Trade == p, t.Trade.ToString());
            Assert.True(t.TradeSize == z, t.TradeSize.ToString());
            Assert.True(t.Ts == z, t.Ts.ToString());
            Assert.True(t.Symbol == s);
        }
Пример #3
0
        static unsafe void OnNxCoreExgQuote(NxCoreSystem *pNxCoreSys, NxCoreMessage *pNxCoreMsg)
        {
            if (keepcurrent && (STATUS < 4))
            {
                return;
            }
            if (DOLIVESKIPTEST)
            {
                if (pNxCoreSys->nxTime.MsOfDay < (DateTime.UtcNow.TimeOfDay.TotalMilliseconds - (DateTime.Now.IsDaylightSavingTime() ? (1000 * 60 * 60 * 4) : (1000 * 60 * 60 * 5))))
                {
                    return;
                }
                DOLIVESKIPTEST = false;
                D("NxCore starting realtime data");
            }
            // Get the symbol for category message

            int idx = _nxsyms.getindex(new string(&pNxCoreMsg->coreHeader.pnxStringSymbol->String));

            if (idx < 0)
            {
                return;
            }
            if (!_nxsyms[idx])
            {
                return;
            }

            // Assign a pointer to the ExgQuote data
            NxCoreExgQuote *Quote = &pNxCoreMsg->coreData.ExgQuote;
            NxCoreQuote     cq    = Quote->coreQuote;
            // Get bid and ask price
            double bid  = 0;
            double ask  = 0;
            int    bs   = 0;
            int    os   = 0;
            string be   = string.Empty;
            string oe   = string.Empty;
            bool   bbid = false;
            bool   bask = false;

            if ((cq.BidPriceChange != 0) || (cq.BidSizeChange != 0))
            {
                bid  = NxCore.PriceToDouble(Quote->coreQuote.BidPrice, Quote->coreQuote.PriceType);
                bs   = Quote->coreQuote.BidSize;
                be   = excode2name(Quote->BestBidExg);
                bbid = true;
            }
            if ((cq.AskPriceChange != 0) || (cq.AskSizeChange != 0))
            {
                ask  = NxCore.PriceToDouble(Quote->coreQuote.AskPrice, Quote->coreQuote.PriceType);
                os   = Quote->coreQuote.AskSize;
                oe   = excode2name(Quote->BestAskExg);
                bask = true;
            }
            if (bask || bbid)
            {
                NxTime time   = pNxCoreMsg->coreHeader.nxExgTimestamp;
                int    tltime = time.Hour * 10000 + time.Minute * 100 + time.Second;
                NxDate date   = pNxCoreMsg->coreHeader.nxSessionDate;
                int    tldate = (int)date.Year * 10000 + (int)date.Month * 100 + (int)date.Day;
                Tick   k      = new TickImpl();
                k.symbol = _realsym2nxidx.getlabel(idx);
                k.date   = tldate;
                k.time   = tltime;
                if (bask && bbid)
                {
                    k.bid = (decimal)bid;
                    k.bs  = bs;
                    k.be  = be;
                    k.ask = (decimal)ask;
                    k.os  = os;
                    k.oe  = oe;
                }
                else if (bbid)
                {
                    k.bid = (decimal)bid;
                    k.bs  = bs;
                    k.be  = be;
                }
                else
                {
                    k.ask = (decimal)ask;
                    k.os  = os;
                    k.oe  = oe;
                }
                try
                {
                    tl.newTick(k);
                }
                catch (Exception ex)
                {
                    D("bad tick: " + k.ToString() + " " + ex.Message + ex.StackTrace);
                }
            }
        }