API Documentation

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

Introduction to Categories

Categories messages cover a wide variety of information about the security. For this example, we will be printing the symbol name and official closing report. The category list contains all available categories and indication if they are active. All categories from the previous day will be sent 4 minutes into the file and new categories will be added through the day.

Code

#include "stdio.h"
#include "NxCoreAPI_Wrapper_C++.h"
NxCoreClass NxCore;

int OnNxCoreCallback(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMsg) {
    if(pNxCoreMsg->MessageType == NxMSG_CATEGORY) {

        const NxCoreHeader& header = pNxCoreMsg->coreHeader;
        char* symbol = header.pnxStringSymbol->String;
        const NxTime& timestamp = header.nxExgTimestamp;
        const NxDate& sessionDate = header.nxSessionDate;

        const NxCoreCategory& category = pNxCoreMsg->coreData.Category;
        int categoryID = category.pnxStringCategory->Atom;
        NxCategoryField* pFields = category.pnxFields;

        if (categoryID == 4) {
            if (pFields[0].Set == 1) {
                const char* name = pFields[0].data.StringZ;
                printf("%s name is %s\n", symbol, name);
            }
        }
        if (categoryID == 50 || categoryID == 52 || categoryID == 54) {
            double high = 0.0;
            double low = 0.0;
            double last = 0.0;
            uint64_t volume = 0;
            if (pFields[2].Set == 1)
                high = NxCore.PriceToDouble(pFields[2].data.nxPrice.Price, pFields[2].data.nxPrice.PriceType);
            if (pFields[3].Set == 1)
                low = NxCore.PriceToDouble(pFields[3].data.nxPrice.Price, pFields[3].data.nxPrice.PriceType);
            if (pFields[4].Set == 1)
                last = NxCore.PriceToDouble(pFields[4].data.nxPrice.Price, pFields[4].data.nxPrice.PriceType);
            if (pFields[6].Set == 1)
                volume = pFields[6].data.i64Bit;
            printf( "%s on %d%02d%02d had a high of $%.2f, low of $%.2f, last of $%.2f, and volume of %llu shares\n",
                symbol, sessionDate.Year, sessionDate.Month, sessionDate.Day, high, low, last, volume);
        }
    }
    return NxCALLBACKRETURN_CONTINUE;
}

int main(int argc, char* argv[]) {
    if (argc < 3)
        return 1;

    if (NxCore.LoadNxCore(argv[1])){
        int returnValue = NxCore.ProcessTape(argv[2], 0, 0, 0, OnNxCoreCallback);
        NxCore.ProcessReturnValue(returnValue);
    }
    else
        printf("loading library failed\n");

    return 0;
}

Callback Function

Since we only want to process categories we check that MessageType equals NxMSG_CATEGORY.

int OnNxCoreCallback(
    const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMsg) {
    if(pNxCoreMsg->MessageType == NxMSG_CATEGORY) {
        ...
    }
    return NxCALLBACKRETURN_CONTINUE;
}

Message Header

In addition to symbol and timestamp, the coreHeader also contains the session date of the message. For most cases the session date will be the same as the current date but for some messages, such as the official trade summary report, the session date may be from a previous date.

const NxCoreHeader& header = pNxCoreMsg->coreHeader;
char* symbol = header.pnxStringSymbol->String;
const NxTime& timestamp = header.nxExgTimestamp;
const NxDate& sessionDate = header.nxSessionDate;

Category Message

The Category object in the coreData object in NxCoreMessage contains category information when MessageType is NxMSG_Category. The Atom of the pnxStringCategory object identifies the category and corresponds to the ID column of the category list. The array pnxFields contains the data of the category message.

const NxCoreCategory& category = pNxCoreMsg->coreData.Category;
int categoryID = category.pnxStringCategory->Atom;
NxCategoryField* pFields = category.pnxFields;

Equity Symbol Information Category

Symbol name is sent in the Equity Symbol Info category. On the web page for that category we can see the atom is 4, so we will check for the atom of 4. Additionally on the web page we can see the Security Name is index 0 of fields and is stored in data.StringZ. The data object is only be populated when Set equals 1.

if (categoryID == 4) {
    if (pFields[0].Set == 1) {
        const char* name = pFields[0].data.StringZ;
        ...
    }
}

Official Closing Report Category

Categories CTA_ClosingReport(50), OTC_ClosingReport(52), and Nasdaq_ClosingReport(54) have the same fields and contain the official High, Low, and Last prices as well as volume for a day. The sessionDate is the date the category message corresponds to.

if (categoryID == 50 || categoryID == 52 || categoryID == 54) {
    double high = 0.0;
    double low = 0.0;
    double last = 0.0;
    uint64_t volume = 0;
    if (pFields[2].Set == 1)
        high = NxCore.PriceToDouble(
            pFields[2].data.nxPrice.Price, pFields[2].data.nxPrice.PriceType);
    if (pFields[3].Set == 1)
        low = NxCore.PriceToDouble(
            pFields[3].data.nxPrice.Price, pFields[3].data.nxPrice.PriceType);
    if (pFields[4].Set == 1)
        last = NxCore.PriceToDouble(
            pFields[4].data.nxPrice.Price, pFields[4].data.nxPrice.PriceType);
    if (pFields[6].Set == 1)
        volume = pFields[6].data.i64Bit;
    ...
}

Next:
Status