API Documentation

Language: C++ Java Python
Basic: Intro/Trade Quote Category Status Symbol Options
Detailed: Trade Quote

Introduction to Quotes

Quotes discussed on this page are considered level 1 quotes or exchange quotes. The best exchange quotes form the NBBO quote which will be covered in the advanced quote guide.

Code

import net.nanex.NxCoreClass;
class QuoteSample extends NxCoreClass{
    
    @Override
    public int OnNxCoreCallback(NxCoreSystem nxCoreSys, NxCoreMessage nxCoreMsg) {
        if (nxCoreMsg.MessageType ==  defines.NxMSG_EXGQUOTE) {
            NxCoreHeader header = nxCoreMsg.coreHeader;
            String symbol = header.pnxStringSymbol.String;
            NxTime timestamp = header.nxExgTimestamp;
            String exchange = GetDefinedString(defines.NxST_EXCHANGE, header.ReportingExg);

            NxCoreQuote coreQuote = nxCoreMsg.coreData.ExgQuote.coreQuote;
            int sizeBid = coreQuote.BidSize;
            int sizeAsk = coreQuote.AskSize;
            double priceBid = PriceToDouble(coreQuote.BidPrice, coreQuote.PriceType);
            double priceAsk = PriceToDouble(coreQuote.AskPrice, coreQuote.PriceType);

            System.out.println("Quote for " + symbol + " on Exchange " + exchange + " at "
                + String.format("%02d:%02d:%02d", timestamp.Hour, timestamp.Minute, timestamp.Second)
                + " Bid: " + sizeBid + " lots at $" + String.format("%.2f", priceBid)
                + " Ask: " + sizeAsk + " lots at $" + String.format("%.2f", priceAsk));
        }
        return defines.NxCALLBACKRETURN_CONTINUE;
    }
    
    public static void main(String args[]) {
        TradeSample nxCore = new TradeSample();

        if (args.length > 1 && nxCore.LoadNxCore(args[0]) != 0){
            int returnValue = nxCore.ProcessTape(args[1], 0, 0, 0);
            nxCore.ProcessReturnValue(returnValue);
        }
        else
            System.out.println("loading library failed");
    }
}

Callback Function

Since we only want to process quotes we check that MessageType equals NxMSG_EXGQUOTE.

@Override
public int OnNxCoreCallback(NxCoreSystem nxCoreSys, NxCoreMessage nxCoreMsg) {
    if (nxCoreMsg.MessageType ==  defines.NxMSG_EXGQUOTE) {
        ...
    }
    return defines.NxCALLBACKRETURN_CONTINUE;
}

Message Header

In addition to symbol and timestamp, the coreHeader also contains the exchange that sent the message. The exchange is sent as a number corresponding to NxST_EXCHANGE. The name of the exchange can be found using GetDefinedString.

NxCoreHeader header = nxCoreMsg.coreHeader;
String symbol = header.pnxStringSymbol.String;
NxTime timestamp = header.nxExgTimestamp;
String exchange = GetDefinedString(
    defines.NxST_EXCHANGE, header.ReportingExg);

Quote Message

The ExgQuote object in the coreData object in NxCoreMessage contains details of the quote when MessageType is NxMSG_EXGQUOTE. For this simple example we will just use the contents of the coreQuote object. The other parts of the ExgQuote object will be covered in the advanced quote guide. Note quote sizes sent by most feeds are the number of lots, not the number of shares. Lots are usually 100 shares.

NxCoreQuote coreQuote = nxCoreMsg.coreData.ExgQuote.coreQuote;
int sizeBid = coreQuote.BidSize;
int sizeAsk = coreQuote.AskSize;
double priceBid = PriceToDouble(
    coreQuote.BidPrice, coreQuote.PriceType);
double priceAsk = PriceToDouble(
    coreQuote.AskPrice, coreQuote.PriceType);

Next:
Category
Detailed Quote