API Documentation

NxMSG_STATUS message

Status messages are unique in that they do not have a corresponding NxCoreMessage data structure.

Status messages are sent on initialization, whenever the NxCore millisecond clock changes, if any errors are detected, when a tape completes or restarts, on shutdown and when paused waiting for more data. Nanex Clock changes occur at 1 millisecond intervals when trading is active making this the most frequent reason for receiving a NxMSG_STATUS message.

Since NxCore API is a callback model, these frequent callbacks give your program frequent opportunity to perform tasks.

Simplest example

Here's the simplest example.


#include <NxCoreAPI.h>

int processNxCoreStatus(const NxCoreSystem* pNxCoreSys)
{
  return NxCALLBACKRETURN_CONTINUE;
}

int __stdcall OnNxCoreCallback(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMsg)
{
  switch( pNxCoreMsg->MessageType ) {
      case NxMSG_STATUS:       return processNxCoreStatus(pNxCoreSys);
      case NxMSG_EXGQUOTE:     break;
      case NxMSG_MMQUOTE:      break;
      case NxMSG_TRADE:        break;
      case NxMSG_CATEGORY:     break;
      case NxMSG_SYMBOLCHANGE: break;
      case NxMSG_SYMBOLSPIN:   break;
  }

  return NxCALLBACKRETURN_CONTINUE;
}

In the switch statement, the case NxMSG_STATUS calls a new function we added, processNxCoreStatus, and passes the first formal parameter from the Callback function. The Status message does not use the second formal callback parameter pNxCoreMsg, other than testing to see that the message type is NxMSG_STATUS.

Example

Performing different tasks depending on the time of the callback


#include <NxCoreAPI.h>

int processNxCoreStatus(const NxCoreSystem* pNxCoreSys)
{
    switch( pNxCoreSys->Status ) {
        case NxCORESTATUS_RUNNING:       // all is well.
            break;
        case NxCORESTATUS_INITIALIZING:  // start up code.
            break;
        case NxCORESTATUS_COMPLETE:      // tear down code.
            break;
        case NxCORESTATUS_ERROR:
            print("Error %s (%d)\n:",pNxCoreSys->StatusDisplay,pNxCoreSys->StatusData);
            return NxCALLBACKRETURN_STOP;   // not required to return this
    }

    if( pNxCoreSystem->ClockUpdateInterval >= NxCLOCK_ON_SECOND ) {

        processOneSecondAnalysis();

        if( pNxCoreSystem->ClockUpdateInterval >= NxCLOCK_ON_MINUTE ) {  // MINUTE or HOUR
            
            // 9:00,9:01,9:02,9:03.. 9:07 another minute elapsed.. run one minute analysis procedure.
            processOneMinuteAnalysis();

            if( pNxClock->nxTime.Minute % 5 == 0 ) { // on 5 minute interval. 9:00,9:05,9:10, etc
                processFiveMinuteAnalysis();
            }

            if( pNxCoreSystem->ClockUpdateInterval == NxCLOCK_ON_HOUR ) {  // HOUR
                processOneHourAnalysis();
            }
        }
    }

    return NxCALLBACKRETURN_CONTINUE;
}

int __stdcall OnNxCoreCallback(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMsg)
{
    switch( pNxCoreMsg->MessageType ) {
        case NxMSG_STATUS:       return processNxCoreStatus(pNxCoreSys);
        case NxMSG_EXGQUOTE:     break;
        case NxMSG_MMQUOTE:      break;
        case NxMSG_TRADE:        break;
        case NxMSG_CATEGORY:     break;
        case NxMSG_SYMBOLCHANGE: break;
        case NxMSG_SYMBOLSPIN:   break;
    }
    return NxCALLBACKRETURN_CONTINUE;
}