Example #1
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);
                }
            }
        }
Example #2
0
        static unsafe void OnNxCoreTrade(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 Trade data
            NxCoreTrade *Trade = &pNxCoreMsg->coreData.Trade;
            // Get the price and net change
            double Price = NxCore.PriceToDouble(Trade->Price, Trade->PriceType);
            //double NetChange = NxCore.PriceToDouble(Trade->NetChange, Trade->PriceType);
            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;
            string ex     = excode2name(pNxCoreMsg->coreHeader.ReportingExg);
            int    size   = (int)Trade->Size;

            // check for index
            if (size <= 0)
            {
                return;
            }
            Tick k = new TickImpl();

            k.symbol = _realsym2nxidx.getlabel(idx);
            k.date   = tldate;
            k.time   = tltime;
            k.trade  = (decimal)Price;
            k.ex     = ex;
            k.size   = size;
            try
            {
                tl.newTick(k);
            }
            catch (Exception e)
            {
                D("bad tick: " + k.symbol + " " + Price + " " + size + " " + ex + " " + e.Message + e.StackTrace);
            }
        }