예제 #1
0
        // OnNxCoreTrade: Function to handle NxCore Trade messages.
        //--------------------------------------------------------------
        static unsafe void OnNxCoreTrade(NxCoreSystem *pNxCoreSys, NxCoreMessage *pNxCoreMsg)
        {
            // Get the symbol for category message
            String Symbol = new String(&pNxCoreMsg->coreHeader.pnxStringSymbol->String);

            if (pNxCoreMsg->coreHeader.pnxStringSymbol->UserData1 == 1)
            {
                //if (Symbol.ToString() == "eCSIQ") {

                // 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);
                int    Hour        = pNxCoreMsg->coreHeader.nxExgTimestamp.Hour;
                int    Minute      = pNxCoreMsg->coreHeader.nxExgTimestamp.Minute;
                int    Second      = pNxCoreMsg->coreHeader.nxExgTimestamp.Second;
                int    Millisecond = pNxCoreMsg->coreHeader.nxExgTimestamp.Millisecond;
                int    MsOfDay     = Convert.ToInt32(pNxCoreMsg->coreHeader.nxExgTimestamp.MsOfDay);
                string TimeOfTrade = Hour.ToString() + ":" + Minute.ToString() + ":" + Second.ToString() + ":" + Millisecond.ToString();
                string Volume      = pNxCoreMsg->coreData.Trade.Size.ToString();

                //Check that price is within BBO or not tradethruexempt
                int tradeCondition = pNxCoreMsg->coreData.Trade.TradeCondition;
                //
                //var extendedTradeCondition = pNxCoreMsg->coreData.Trade.ExtTradeConditions;

                if (tradeCondition == 108) //TradeThruExempt
                {
                    //Get BBO
                    double bestBidPrice = pNxCoreMsg->coreData.ExgQuote.BestBidPrice;
                    double bestAskPrice = pNxCoreMsg->coreData.ExgQuote.BestAskPrice;

                    Console.WriteLine("Trade for Symbol: {0:S}, Time: {1:d}:{2:d}:{3:d}  Price: {4:f}    BBO:  {5}  {6}   TradeCondition:  {7}", Symbol,
                                      pNxCoreMsg->coreHeader.nxExgTimestamp.Hour, pNxCoreMsg->coreHeader.nxExgTimestamp.Minute, pNxCoreMsg->coreHeader.nxExgTimestamp.Second,
                                      Price, bestBidPrice, bestAskPrice, tradeCondition);
                }

                var newLine = string.Format("{0},{1},{2},{3}", MsOfDay, TimeOfTrade, Price, Volume);
                csvs[Symbol.Remove(0, 1)] += newLine + "\n";

                // Write out Symbol, Time, Price, NetChg, Size, Reporting Exg

                /*Console.WriteLine("Trade for Symbol: {0:S}, Time: {1:d}:{2:d}:{3:d}  Price: {4:f}  NetChg: {5:f}  Size: {6:d}  Exchg: {7:d} ",
                 *                Symbol,
                 *                pNxCoreMsg->coreHeader.nxExgTimestamp.Hour, pNxCoreMsg->coreHeader.nxExgTimestamp.Minute, pNxCoreMsg->coreHeader.nxExgTimestamp.Second,
                 *                Price, NetChange, Trade->Size,
                 *                pNxCoreMsg->coreHeader.ReportingExg);*/
            }
        }
예제 #2
0
        // OnNxCoreTrade: Function to handle NxCore Trade messages.
        //--------------------------------------------------------------
        static unsafe void OnNxCoreTrade(NxCoreSystem *pNxCoreSys, NxCoreMessage *pNxCoreMsg)
        {
            // Get the symbol for category message
            String Symbol = new String(&pNxCoreMsg->coreHeader.pnxStringSymbol->String);

            // 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);

            // Write out Symbol, Time, Price, NetChg, Size, Reporting Exg
            Console.WriteLine("Trade for Symbol: {0:S}, Time: {1:d}:{2:d}:{3:d}  Price: {4:f}  NetChg: {5:f}  Size: {6:d}  Exchg: {7:d} ",
                              Symbol,
                              pNxCoreMsg->coreHeader.nxExgTimestamp.Hour, pNxCoreMsg->coreHeader.nxExgTimestamp.Minute, pNxCoreMsg->coreHeader.nxExgTimestamp.Second,
                              Price, NetChange, Trade->Size,
                              pNxCoreMsg->coreHeader.ReportingExg);
        }
예제 #3
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);
            }
        }
예제 #4
0
        // OnNxCoreTrade: Function to handle NxCore Trade messages.
        //--------------------------------------------------------------
        static unsafe void OnNxCoreTrade(NxCoreSystem *pNxCoreSys, NxCoreMessage *pNxCoreMsg)
        {
            // Get the symbol for category message
            String Symbol = new String(&pNxCoreMsg->coreHeader.pnxStringSymbol->String);

            if (pNxCoreMsg->coreHeader.pnxStringSymbol->UserData1 == 1)
            {
                //if (Symbol.ToString() == "eCSIQ") {

                // 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);
                int    Hour        = pNxCoreMsg->coreHeader.nxExgTimestamp.Hour;
                int    Minute      = pNxCoreMsg->coreHeader.nxExgTimestamp.Minute;
                int    Second      = pNxCoreMsg->coreHeader.nxExgTimestamp.Second;
                int    Millisecond = pNxCoreMsg->coreHeader.nxExgTimestamp.Millisecond;
                int    MsOfDay     = Convert.ToInt32(pNxCoreMsg->coreHeader.nxExgTimestamp.MsOfDay);
                string TimeOfTrade = Hour.ToString() + ":" + Minute.ToString() + ":" + Second.ToString() + ":" + Millisecond.ToString();
                string Volume      = pNxCoreMsg->coreData.Trade.Size.ToString();

                //Check that price is not tradethruexempt in the extended trade conditions - for future imports
                //int tradeCondition = pNxCoreMsg->coreData.Trade.ExtTradeConditions[]

                var   tradeCondition          = pNxCoreMsg->coreData.Trade.TradeCondition;
                byte *extendedTradeConditions = pNxCoreMsg->coreData.Trade.ExtTradeConditions;


                int len = 0;

                for (int i = 0; i < 10; i++)
                {
                    try
                    {
                        string aaa = extendedTradeConditions[i].ToString();
                        if (aaa == "255")
                        {
                            break;
                        }
                        len++;
                    }
                    catch (Exception)
                    {
                        break;
                    }
                }

                byte[] _extendedTradeConditions = new byte[len];
                Marshal.Copy((IntPtr)extendedTradeConditions, _extendedTradeConditions, 0, len);


                Debug.WriteLine(tradeCondition);

                foreach (int condition in _extendedTradeConditions)
                {
                    Debug.WriteLine(condition);
                }
                Debug.WriteLine("");
                Debug.WriteLine("------------------------");
                Debug.WriteLine("");

                //string extCondition = extendedTradeConditions[0].ToString();



                //Debug.WriteLine(extCondition);

                int a = 1;

                /*if (tradeCondition == 108) //TradeThruExempt
                 * {
                 *  //Get BBO
                 *  double bestBidPrice = pNxCoreMsg->coreData.ExgQuote.BestBidPrice;
                 *  double bestAskPrice = pNxCoreMsg->coreData.ExgQuote.BestAskPrice;
                 *
                 *  Console.WriteLine("Trade for Symbol: {0:S}, Time: {1:d}:{2:d}:{3:d}  Price: {4:f}    BBO:  {5}  {6}   TradeCondition:  {7}", Symbol,
                 *      pNxCoreMsg->coreHeader.nxExgTimestamp.Hour, pNxCoreMsg->coreHeader.nxExgTimestamp.Minute, pNxCoreMsg->coreHeader.nxExgTimestamp.Second,
                 *                Price, bestBidPrice, bestAskPrice, tradeCondition);
                 * }*/

                if (len == 0)
                {
                    var newLine = string.Format("{0},{1},{2},{3},{4}", MsOfDay, TimeOfTrade, Price, Volume, tradeCondition.ToString());
                    csvs[Symbol.Remove(0, 1)] += newLine + "\n";
                }

                if (len == 1)
                {
                    var newLine = string.Format("{0},{1},{2},{3},{4},{5}", MsOfDay, TimeOfTrade, Price, Volume, tradeCondition.ToString(), _extendedTradeConditions[0].ToString());
                    csvs[Symbol.Remove(0, 1)] += newLine + "\n";
                }

                if (len == 2)
                {
                    var newLine = string.Format("{0},{1},{2},{3},{4},{5},{6}", MsOfDay, TimeOfTrade, Price, Volume, tradeCondition.ToString(), _extendedTradeConditions[0].ToString(),
                                                _extendedTradeConditions[1].ToString());
                    csvs[Symbol.Remove(0, 1)] += newLine + "\n";
                }

                if (len == 3)
                {
                    var newLine = string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", MsOfDay, TimeOfTrade, Price, Volume, tradeCondition.ToString(), _extendedTradeConditions[0].ToString(),
                                                _extendedTradeConditions[1].ToString(), _extendedTradeConditions[2].ToString());
                    csvs[Symbol.Remove(0, 1)] += newLine + "\n";
                }

                // Write out Symbol, Time, Price, NetChg, Size, Reporting Exg

                /*Console.WriteLine("Trade for Symbol: {0:S}, Time: {1:d}:{2:d}:{3:d}  Price: {4:f}  NetChg: {5:f}  Size: {6:d}  Exchg: {7:d} ",
                 *                Symbol,
                 *                pNxCoreMsg->coreHeader.nxExgTimestamp.Hour, pNxCoreMsg->coreHeader.nxExgTimestamp.Minute, pNxCoreMsg->coreHeader.nxExgTimestamp.Second,
                 *                Price, NetChange, Trade->Size,
                 *                pNxCoreMsg->coreHeader.ReportingExg);*/
            }
        }