API Documentation

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

Introduction to Statuses

Status messages indicate general information about the tape has changed. NxCoreSys contains details of the status message. NxCoreSys is also populated for non-status messages as well. For this example we will be printing a timestamp every minute and printing the API version on initialization. Both NxCORESTATUS_WAITFORCOREACCESS and NxCORESTATUS_ERROR will not occur for demo.XU.nx2, but they are generally good checks to have while processing.

Code

import net.nanex.NxCoreClass;
class StatusSample extends NxCoreClass{

    @Override
    public int OnNxCoreCallback(NxCoreSystem nxCoreSys, NxCoreMessage nxCoreMsg) {
        if (nxCoreMsg.MessageType ==  defines.NxMSG_STATUS) {
            if (nxCoreSys.ClockUpdateInterval >= defines.NxCLOCK_MINUTE) {
                int year = nxCoreSys.nxDate.Year;
                int month = nxCoreSys.nxDate.Month;
                int day = nxCoreSys.nxDate.Day;
                int hour = nxCoreSys.nxTime.Hour;
                int minute = nxCoreSys.nxTime.Minute;
                System.out.println(String.format("%02d/%02d/%04d %02d:%02d", month, day, year, hour, minute));
            }

            if (nxCoreSys.Status  == defines.NxCORESTATUS_WAITFORCOREACCESS)
                System.out.println("Waiting on NxCore Access");

            if (nxCoreSys.Status  == defines.NxCORESTATUS_ERROR)
                System.out.println("tape error:" + nxCoreSys.StatusData);

            if (nxCoreSys.Status  == defines.NxCORESTATUS_INITIALIZING) {
                int major = GetMajorVersion(nxCoreSys.DLLVersion);
                int minor = GetMinorVersion(nxCoreSys.DLLVersion);
                int build = GetBuildVersion(nxCoreSys.DLLVersion);
                System.out.println("Initialized with decoder version "+String.format("%d.%d.%d",major,minor,build));
            }
        }
        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 status messages we check that MessageType equals NxMSG_STATUS.

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

On Interval

During status messages ClockUpdateInterval indicates if the timestamp has changed and whether it is a new hour, minute, or second. In this example we want to do something every minute, so we will check if ClockUpdateInterval is greater or equal to NxCLOCK_MINUTE, which is equivalent to 3. Checking greater than ensures we also perform the action on a new hour, since NxCLOCK_HOUR is equivalent to 4.
The fields nxDate and nxTime reflect the date and time of the server processing the data.

if (nxCoreSys.ClockUpdateInterval >= defines.NxCLOCK_MINUTE) {
    int year = nxCoreSys.nxDate.Year;
    int month = nxCoreSys.nxDate.Month;
    int day = nxCoreSys.nxDate.Day;
    int hour = nxCoreSys.nxTime.Hour;
    int minute = nxCoreSys.nxTime.Minute;
    ...
}

Incomplete File

The Status field of NxCore message is the current state of the tape. Most of the time Status will be NxCORESTATUS_RUNNING. If the API is unable process the next message after a period of time, either because the file is incomplete or real-time stream is paused, Status will be set to NxCORESTATUS_WAITFORCOREACCESS.

if (nxCoreSys.Status  == defines.NxCORESTATUS_WAITFORCOREACCESS)
    System.out.println("Waiting on NxCore Access");

Errors

If there is a problem while processing the tape, Status is set to NxCORESTATUS_ERROR. StatusData contains details of the Status. In this case it corresponds to the Error Codes Table.

if (nxCoreSys.Status  == defines.NxCORESTATUS_ERROR)
    System.out.println("tape error:" + nxCoreSys.StatusData);

Initialization

The first Status when beginning at the start of the file is NxCORESTATUS_INITIALIZING. If loading midday using states then the first status will instead be NxCORESTATUS_LOADED_STATE.
During the first message we will print the version of the API being used to process the tape. GetMajorVersion, GetMinorVersion, and GetBuildVersion can be used to get a more readable version from the int DLLVersion.

if (nxCoreSys.Status  == defines.NxCORESTATUS_INITIALIZING) {
    int major = GetMajorVersion(nxCoreSys.DLLVersion);
    int minor = GetMinorVersion(nxCoreSys.DLLVersion);
    int build = GetBuildVersion(nxCoreSys.DLLVersion);
    System.out.println("Initialized with decoder version "
        + String.format("%d.%d.%d",major,minor,build));
}

Next:
Symbol