// OnNxCoreMMQuote: Function to handle NxCore MMQuote messages. //-------------------------------------------------------------- static unsafe void OnNxCoreMMQuote(NxCoreSystem *pNxCoreSys, NxCoreMessage *pNxCoreMsg) { // Get the symbol for category message String Symbol = new String(&pNxCoreMsg->coreHeader.pnxStringSymbol->String); // Assign a pointer to the MMQuote data NxCoreMMQuote *Quote = &pNxCoreMsg->coreData.MMQuote; if (Quote->pnxStringMarketMaker == null) { return; } // Get the market maker string String MarketMaker = new String(&Quote->pnxStringMarketMaker->String); // Get bid and ask price double Bid = NxCore.PriceToDouble(Quote->coreQuote.BidPrice, Quote->coreQuote.PriceType); double Ask = NxCore.PriceToDouble(Quote->coreQuote.AskPrice, Quote->coreQuote.PriceType); // Write out Symbol, MarketMaker, Time, Bid, Ask, Bidsize, Asksize, Reporting Exg Console.WriteLine("MMQuote for Symbol: {0:S}, MarketMaker: {1:S} Time: {2:d}:{3:d}:{4:d} Bid: {5:f} Ask: {6:f} BidSize: {7:d} AskSise: {8:d} Exchg: {9:d} ", Symbol, MarketMaker, pNxCoreMsg->coreHeader.nxExgTimestamp.Hour, pNxCoreMsg->coreHeader.nxExgTimestamp.Minute, pNxCoreMsg->coreHeader.nxExgTimestamp.Second, Bid, Ask, Quote->coreQuote.BidSize, Quote->coreQuote.AskSize, pNxCoreMsg->coreHeader.ReportingExg); }
static unsafe void OnNxCoreStatus(NxCoreSystem *pNxCoreSys, NxCoreMessage *pNxCoreMsg) { if (DOSAVESTATE) { if (pNxCoreSys->nxTime.MsOfDay >= nextstatesavetime) { D("saving state at: " + nextstatesavetime + " " + statefilepath); NxCore.SaveState(statefilepath, NxCore.NxSAVESTATE_ONEPASS); if (nextstatesavetime == 0) { nextstatesavetime = pNxCoreSys->nxTime.MsOfDay; } nextstatesavetime += savestateint; D("save complete. next save time: " + nextstatesavetime); } } STATUS = pNxCoreSys->StatusData; // Print the specific NxCore status message switch (pNxCoreSys->Status) { case NxCore.NxCORESTATUS_COMPLETE: D("NxCore Complete Message."); break; case NxCore.NxCORESTATUS_INITIALIZING: D("NxCore Initialize Message."); break; case NxCore.NxCORESTATUS_SYNCHRONIZING: D("NxCore Synchronizing Message."); break; case NxCore.NxCORESTATUS_WAITFORCOREACCESS: { //D("NxCore Wait For Access."); break; } case NxCore.NxCORESTATUS_RESTARTING_TAPE: D("NxCore Restart Tape Message."); break; case NxCore.NxCORESTATUS_ERROR: D("NxCore Error."); break; case NxCore.NxCORESTATUS_RUNNING: break; case NxCore.NxCORESTATUS_LOADED_STATE: D("Nxcore has been loaded from a saved state."); break; case NxCore.NxCORESTATUS_SAVING_STATE: D("Nxcore is now saving it's current state."); break; } }
// Thread function called to start Process Tape //---------------------------------------------- static void StartProcessTapeThread() { // Use control flags to eliminate OPRA quotes. NxCore.ProcessTape(FileName, null, (uint)(NxCore.NxCF_EXCLUDE_OPRA), 0, OnNxCoreCallback); InThread = false; }
// 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);*/ } }
// 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); }
void proc() { while (!QUIT) { try { if (!QUIT) { debug("starting run: " + loops++ + " on nxcore tape: " + (isLive ? "LIVE" : _fn)); NxCore.ProcessTape(_fn, null, 0, 0, OnNxCoreCallback); } else { break; } } catch (Exception ex) { debug(ex.Message + ex.StackTrace); } } }
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); } } }
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); } }
// 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);*/ } }