API Documentation

NxMSG_EXGQUOTE message

The second parameter to the NxCoreCallback function, NxCoreMessage, holds the symbol and session information in pNxCoreMessage->coreHeader, and data information in pNxCoreMessage->coreData.ExgQuote, which is a NxCoreExgQuote data structure.

Sent for every exchange quote (regular quote) and BBO (Exchange-determined Best Bid/Offer). Each quote update includes the bid and ask prices, sizes and condition codes, plus price/size changes. Also for symbols trading on multiple exchanges, each ExgQuote also contains fields with the current values of the best bid/best ask prices, sizes and condition codes. This message type is by far the most active of all messages your callback will receive (depending of course on the exchanges you subscribe to). A typical trading day will have 700+ million option quotes!

Simplest example

Here's the simplest example.

#include "NxCoreAPI.h"
int processNxCoreExgQuote(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMsg)
{
    return NxCALLBACKRETURN_CONTINUE;
}
int __stdcall OnNxCoreCallback(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMsg)
{
    switch( pNxCoreMsg->MessageType ) {
        case NxMSG_STATUS:       break;
        case NxMSG_EXGQUOTE:     return processNxCoreExgQuote(pNxCoreSys, pNxCoreMsg);
        case NxMSG_MMQUOTE:      break;
        case NxMSG_TRADE:        break;
        case NxMSG_CATEGORY:     break;
        case NxMSG_SYMBOLCHANGE: break;
        case NxMSG_SYMBOLSPIN:   break;
    }
    return NxCALLBACKRETURN_CONTINUE;
}

Example

Here's an example of printing out every quote that happens

#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <stdio.h>
#include "NxCoreAPI.h"
#include "NxCoreAPI_class.h"    
  
NxCoreClass nxCoreClass;    
  
void 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]);
        }
    }
    // Not an option, just copy the symbol
    else
    {
        strcpy(Symbol,pNxCoreMsg->coreHeader.pnxStringSymbol->String);
    }
}    
  
int __stdcall nxCoreCallback(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMessage)
{
    switch (pNxCoreMessage->MessageType)
    {
        case NxMSG_EXGQUOTE:
        {
            const NxCoreHeader&   ch = pNxCoreMessage->coreHeader;
            const NxCoreExgQuote& eq = pNxCoreMessage->coreData.ExgQuote;
            const NxCoreQuote&    cq = eq.coreQuote;
            const NxTime& t = pNxCoreSys->nxTime;    
    
            char symbol[23];
            getSymbol(pNxCoreMessage,symbol);    
    
            char buf[1024] = {0};
            char* p = buf;    
    
            if (cq.BidPriceChange || cq.BidSizeChange)
            {
                p += sprintf(p, "RGN_bid(%ld @ %.2lf)[%ld] ",
                            cq.BidSize,
                            nxCoreClass.PriceToDouble(cq.BidPrice, cq.PriceType),
                            ch.ReportingExg);
            }
            if (cq.AskPriceChange || cq.AskSizeChange)
            {
                p += sprintf(p, "RGN_ask(%ld @ %.2lf)[%ld] ",
                            cq.AskSize,
                            nxCoreClass.PriceToDouble(cq.AskPrice, cq.PriceType),
                            ch.ReportingExg);
            }
            if ((eq.BBOChangeFlags & (NxBBOCHANGE_BIDPRICE | NxBBOCHANGE_BIDSIZE)) && eq.BestBidPrice > 0)
            {
                p += sprintf(p, "BBO_bid(%ld @ %.2lf) ",
                            eq.BestBidSize,
                            nxCoreClass.PriceToDouble(eq.BestBidPrice, cq.PriceType));
            }
            if ((eq.BBOChangeFlags & (NxBBOCHANGE_ASKPRICE | NxBBOCHANGE_ASKSIZE)) && eq.BestAskPrice > 0)
            {
                p += sprintf(p, "BBO_ask(%ld @ %.2lf) ",
                            eq.BestAskSize,
                            nxCoreClass.PriceToDouble(eq.BestAskPrice, cq.PriceType));
            }
            if (p > buf)
            {
                printf("%.2d:%.2d:%.2d.%.3d %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("NxCoreAPI.dll") &&
        !nxCoreClass.LoadNxCore("C:\\Program Files\\Nanex\\NxCoreAPI\\NxCoreAPI.dll"))
    {
        fprintf(stderr, "Can't find NxCoreAPI.dll\n");
        return -1;
    }
    nxCoreClass.ProcessTape(argv[1], 0, NxCF_EXCLUDE_CRC_CHECK, 0, nxCoreCallback);
    return 0;
}