NxCoreStateExgQuote
One of a number of regional exchange quotes in NxCoreStateExgQuotes.StateExgQuotes
The structure NxCoreStateExgQuote is defined in NxCoreAPI.h as:
struct NxCoreStateExgQuote { int AskPrice; int BidPrice; int AskSize; int BidSize; unsigned short ReportingExg; unsigned char QuoteCondition; unsigned char alignment[1]; };
Represents the value of the current ask from the exchange identified as ReportingExg.
Use PriceType to convert to double: nxCoreClass.PriceToDouble(AskPrice, PriceType)
Represents the value of the current bid from the exchange identified as ReportingExg.
Use PriceType to convert to double: nxCoreClass.PriceToDouble(BidPrice, PriceType)
Represents the size of the current Ask from the exchange ReportingExg. For most equities, the AskSize represents the number of round lots (a round lot is 100 shares in this case). For options contracts, the AskSize represents the number of option contracts. The size fields are set to the values as sent by the exchanges.
Represents the size of the current Bid from the exchange ReportingExg. For most equities, the BidSize represents the number of round lots (a round lot is 100 shares in this case). For options contracts, the BidSize represents the number of option contracts. The size fields are set to the values as sent by the exchanges.
The reporting exchange for this quote. Can be compared against BestAskExg or BestBidExg to determine NBBO
Described here
Here's an example of getting the Exg quote information for every symbol that trades
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include "NxCoreAPI.h" #include "NxCoreAPI_Wrapper_C++.h" NxCoreClass nxCoreClass; NxString* getSymbol(const NxCoreMessage* pNxCoreMsg, char *Symbol) { // Is this a valid option? if (pNxCoreMsg->coreHeader.pnxStringSymbol->String[0] == 'o' && pNxCoreMsg->coreHeader.pnxOptionHdr) { // If pnxsDateAndStrike->String[1] == ' ', then this symbol is in new OSI format. if (pNxCoreMsg->coreHeader.pnxOptionHdr->pnxsDateAndStrike->String[1] == ' ') { sprintf(Symbol,"%s%02d%02d%02d%c%08d", pNxCoreMsg->coreHeader.pnxStringSymbol->String, pNxCoreMsg->coreHeader.pnxOptionHdr->nxExpirationDate.Year-2000, pNxCoreMsg->coreHeader.pnxOptionHdr->nxExpirationDate.Month, pNxCoreMsg->coreHeader.pnxOptionHdr->nxExpirationDate.Day, (pNxCoreMsg->coreHeader.pnxOptionHdr->PutCall == 0) ? 'C' : 'P', pNxCoreMsg->coreHeader.pnxOptionHdr->strikePrice); } // Otherwise the symbol is in old OPRA format. else { sprintf(Symbol,"%s%c%c", pNxCoreMsg->coreHeader.pnxStringSymbol->String, pNxCoreMsg->coreHeader.pnxOptionHdr->pnxsDateAndStrike->String[0], pNxCoreMsg->coreHeader.pnxOptionHdr->pnxsDateAndStrike->String[1]); } // Return nx date-strike string ptr return pNxCoreMsg->coreHeader.pnxOptionHdr->pnxsDateAndStrike; } // Not an option, just copy the symbol and return nx string ptr strcpy(Symbol, pNxCoreMsg->coreHeader.pnxStringSymbol->String); return pNxCoreMsg->coreHeader.pnxStringSymbol; } int __stdcall nxCoreCallback(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMessage) { switch (pNxCoreMessage->MessageType) { case NxMSG_TRADE: { const NxCoreHeader& ch = pNxCoreMessage->coreHeader; const NxTime& t = pNxCoreSys->nxTime; // Get the symbol and the correct string pointer char symbol[23]; NxString* nx = getSymbol(pNxCoreMessage, symbol); // get the state data for current Exchange Quotes NxCoreStateExgQuotes q; int rc = nxCoreClass.StateGetExgQuotes(&q, nx); if (rc != 0) break; // print the data char buf[1024]; char* p = buf; for (int i = 0; i < q.StateQuoteCount; i++) { const NxCoreStateExgQuote& eq = q.StateExgQuotes[i]; if (eq.BidPrice > 0 && eq.BidSize > 0) { p += sprintf(p, "%s_bid(%ld @ %.2lf)[%ld] ", q.BestBidExg == eq.ReportingExg ? "BBO" : "RGN", eq.BidSize, nxCoreClass.PriceToDouble(eq.BidPrice, q.PriceType), eq.ReportingExg); } if (eq.AskPrice > 0 && eq.AskSize > 0) { p += sprintf(p, "%s_ask(%ld @ %.2lf)[%ld] ", q.BestAskExg == eq.ReportingExg ? "BBO" : "RGN", eq.AskSize, nxCoreClass.PriceToDouble(eq.AskPrice, q.PriceType), eq.ReportingExg); } } if (p > buf) { printf("%02d:%02d:%02d.%03d %s %s\n", (int) t.Hour, (int) t.Minute, (int) t.Second, (int) t.Millisecond, symbol, buf); } break; } } return NxCALLBACKRETURN_CONTINUE; } int main(int argc, char** argv) { if (!nxCoreClass.LoadNxCore("NxCoreAPI64.dll") && !nxCoreClass.LoadNxCore("NxCoreAPI.dll")) { fprintf(stderr, "loading library failed\n"); return -1; } nxCoreClass.ProcessTape(argv[1], 0, NxCF_EXCLUDE_CRC_CHECK, 0, nxCoreCallback); return 0; } |
import net.nanex.NxCoreClass; class StateExgQuoteSample extends NxCoreClass{ @Override public int OnNxCoreCallback(NxCoreSystem nxCoreSys, NxCoreMessage nxCoreMsg) { switch (nxCoreMsg.MessageType) { case defines.NxMSG_TRADE: NxCoreHeader ch = nxCoreMsg.coreHeader; NxTime t = nxCoreSys.nxTime; String symbol; NxCoreStateExgQuotes q; // Retrieve Exchange Quote if (ch.pnxStringSymbol.String.charAt(0) == 'o' && ch.pnxOptionHdr != null) {// If an option.... symbol = String.format("%s%02d%02d%02d%c%08d", ch.pnxStringSymbol.String, ch.pnxOptionHdr.nxExpirationDate.Year-2000, ch.pnxOptionHdr.nxExpirationDate.Month, ch.pnxOptionHdr.nxExpirationDate.Day, (ch.pnxOptionHdr.PutCall == 0) ? 'C' : 'P', ch.pnxOptionHdr.strikePrice); q = StateGetExgQuotes(ch.ListedExg, ch.pnxStringSymbol.String, ch.pnxOptionHdr.nxExpirationDate, ch.pnxOptionHdr.strikePrice, ch.pnxOptionHdr.PutCall); } else{// otherwise a non-option symbol = ch.pnxStringSymbol.String; q = StateGetExgQuotes(ch.ListedExg, ch.pnxStringSymbol.String); } //make sure a valid return from function if(q == null) break; String quoteString = ""; // Cycle through all quotes in the state for(int i = 0; i < q.StateQuoteCount; i++) { NxCoreStateExgQuote eq = q.StateExgQuotes[i]; if (eq.BidPrice > 0 && eq.BidSize > 0) { quoteString += String.format("%s_bid(%d @ %.2f)[%d] ", (q.BestBidExg == eq.ReportingExg || q.BestBidExg == 0)? "BBO" : "RGN", eq.BidSize, PriceToDouble(eq.BidPrice, q.PriceType), eq.ReportingExg); } if (eq.AskPrice > 0 && eq.AskSize > 0) { quoteString += String.format("%s_ask(%d @ %.2f)[%d] ", (q.BestAskExg == eq.ReportingExg || q.BestAskExg == 0) ? "BBO" : "RGN", eq.AskSize, PriceToDouble(eq.AskPrice, q.PriceType), eq.ReportingExg); } } if (quoteString.length() > 0) { System.out.println( String.format("%02d:%02d:%02d.%03d %s %s", t.Hour, t.Minute, t.Second, t.Millisecond, symbol, quoteString)); } break; } return defines.NxCALLBACKRETURN_CONTINUE; } public static void main(String args[]) { StateExgQuoteSample nxCore = new StateExgQuoteSample(); if (nxCore.LoadNxCore("NxCoreAPI64.dll") != 0){ nxCore.ProcessTape(args[0], 0, 0, 0); } else System.out.println("loading library failed"); } } |
import NxCore tapePath = "" def OnNxCoreCallback(NxCoreSys, NxCoreMsg): if NxCoreMsg.MessageType == NxCore.NxMSG_TRADE: ch = NxCoreMsg.coreHeader t = NxCoreSys.nxTime # Retrieve Exchange Quote if ch.pnxStringSymbol.String[0] == 'o' and ch.pnxOptionHdr:# If an option.... symbol = "{}{:02d}{:02d}{:02d}{}{:08d}".format( ch.pnxStringSymbol.String, ch.pnxOptionHdr.nxExpirationDate.Year-2000, ch.pnxOptionHdr.nxExpirationDate.Month, ch.pnxOptionHdr.nxExpirationDate.Day, 'C' if (ch.pnxOptionHdr.PutCall == 0) else 'P', ch.pnxOptionHdr.strikePrice) q = NxCore.StateGetExgQuotes(ch.ListedExg, ch.pnxStringSymbol.String, ch.pnxOptionHdr.nxExpirationDate.NDays, ch.pnxOptionHdr.strikePrice, ch.pnxOptionHdr.PutCall) else:# otherwise a non-option symbol = ch.pnxStringSymbol.String q = NxCore.StateGetExgQuotes(ch.ListedExg, ch.pnxStringSymbol.String) #make sure a valid return from function if not q: return NxCore.NxCALLBACKRETURN_CONTINUE quoteString = ""; # Cycle through all quotes in the state for i in range(q.StateQuoteCount): eq = q.StateExgQuotes[i] if eq.BidPrice > 0 and eq.BidSize > 0: quoteString += "{}_bid({} @ {:.2f})[{}] ".format( "BBO" if (q.BestBidExg == eq.ReportingExg or q.BestBidExg == 0) else "RGN", eq.BidSize, NxCore.PriceToFloat(eq.BidPrice, q.PriceType), eq.ReportingExg) if eq.AskPrice > 0 and eq.AskSize > 0 : quoteString += "{}_ask({} @ {:.2f})[{}] ".format( "BBO" if (q.BestAskExg == eq.ReportingExg or q.BestAskExg == 0) else "RGN", eq.AskSize, NxCore.PriceToFloat(eq.AskPrice, q.PriceType), eq.ReportingExg) if len(quoteString) > 0: print("{:02d}:{:02d}:{:02d}.{:03d} {} {}" .format(t.Hour, t.Minute, t.Second, t.Millisecond, symbol, quoteString)) return NxCore.NxCALLBACKRETURN_CONTINUE if NxCore.LoadNxCore("NxCoreAPI64.dll"): NxCore.ProcessTape(tapePath, 0, 0, 0, OnNxCoreCallback) else: print("loading library failed") |