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

import NxCore

def OnNxCoreCallback(NxCoreSys, NxCoreMsg):
    if NxCoreMsg.MessageType == NxCore.NxMSG_CATEGORY:

        header = NxCoreMsg.coreHeader
        symbol = header.pnxStringSymbol.String
        timestamp = header.nxExgTimestamp
        session_date = header.nxSessionDate

        category = NxCoreMsg.coreData.Category
        category_id = category.pnxStringCategory.Atom
        fields = category.pnxFields

        if category_id == 4:
            if fields[0].Set:
                name = fields[0].data.StringZ
                print("{} name is {}".format(symbol, name))

        if category_id == 50 or category_id == 52  or category_id == 54:
            high = 0
            low = 0
            last = 0
            volume = 0
            if fields[2].Set:
                high = NxCore.PriceToFloat(fields[2].data.nxPrice.Price, fields[2].data.nxPrice.PriceType)
            if fields[3].Set:
                low = NxCore.PriceToFloat(fields[3].data.nxPrice.Price, fields[3].data.nxPrice.PriceType)
            if fields[4].Set:
                last = NxCore.PriceToFloat(fields[4].data.nxPrice.Price, fields[4].data.nxPrice.PriceType)
            if fields[6].Set:
                volume = fields[6].data.i64Bit
            print("{} on {}{:02d}{:02d} had a high of ${:.2f}, low of ${:.2f}, last of ${:.2f}, and volume of {} shares"
                .format(symbol, session_date.Year, session_date.Month, session_date.Day, high, low, last, volume))
    return NxCore.NxCALLBACKRETURN_CONTINUE

if NxCore.LoadNxCore("NxCoreAPI64.dll"):
    returnValue = NxCore.ProcessTape("demo.XU.nx2", 0, 0, 0, OnNxCoreCallback)
    NxCore.ProcessReturnValue(returnValue)
else:
    print("loading library failed")

Callback Function

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

def OnNxCoreCallback(NxCoreSys, NxCoreMsg):
    if NxCoreMsg.MessageType == NxCore.NxMSG_CATEGORY:
        ...
    return NxCore.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. Note SessionDate is not a Python date type, instead it is a NxDate type.

header = NxCoreMsg.coreHeader
symbol = header.pnxStringSymbol.String
timestamp = header.nxExgTimestamp
session_date = header.nxSessionDate

Category Message

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

category = NxCoreMsg.coreData.Category
category_id = category.pnxStringCategory.Atom
fields = 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.

if category_id == 4:
    if fields[0].Set:
        name = fields[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 category_id == 50 or category_id == 52  or category_id == 54:
    high = 0
    low = 0
    last = 0
    volume = 0
    if fields[2].Set:
        high = NxCore.PriceToFloat(
            fields[2].data.nxPrice.Price, fields[2].data.nxPrice.PriceType)
    if fields[3].Set:
        low = NxCore.PriceToFloat(
            fields[3].data.nxPrice.Price, fields[3].data.nxPrice.PriceType)
    if fields[4].Set:
        last = NxCore.PriceToFloat(
            fields[4].data.nxPrice.Price, fields[4].data.nxPrice.PriceType)
    if fields[6].Set:
        volume = fields[6].data.i64Bit

Next:
Status