Basic: | Intro/Trade | Quote | Category | Status | Symbol | Options |
Detailed: | Trade | Quote |
Introduction to Statuses
Status messages indicate general information about the tape has changed. pNxCoreSys contains details of the status message. pNxCoreSys 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
using System; using NxCoreAPI; class StatusSample { static unsafe int OnNxCoreCallback(NxCoreSystem* pNxCoreSys, NxCoreMessage* pNxCoreMsg) { if (pNxCoreMsg->MessageType == NxCore.NxMSG_STATUS) { if (pNxCoreSys->ClockUpdateInterval >= NxCore.NxCLOCK_MINUTE) { int year = pNxCoreSys->nxDate.Year; int month = pNxCoreSys->nxDate.Month; int day = pNxCoreSys->nxDate.Day; int hour = pNxCoreSys->nxTime.Hour; int minute = pNxCoreSys->nxTime.Minute; Console.WriteLine("{0:d2}/{1:d2}/{2:d} {3:d2}:{4:d2}", month, day, year, hour, minute); } if (pNxCoreSys->Status == NxCore.NxCORESTATUS_WAITFORCOREACCESS) Console.WriteLine("Waiting on NxCore Access"); if (pNxCoreSys->Status == NxCore.NxCORESTATUS_ERROR) Console.WriteLine("tape error:{0:d}", pNxCoreSys->StatusData); if (pNxCoreSys->Status == NxCore.NxCORESTATUS_INITIALIZING) { int major = NxCore.GetMajorVersion(pNxCoreSys->DLLVersion); int minor = NxCore.GetMinorVersion(pNxCoreSys->DLLVersion); int build = NxCore.GetBuildVersion(pNxCoreSys->DLLVersion); Console.WriteLine("Initialized with decoder version {0:d}.{1:d}.{2:d}", major, minor, build); } } return (int)NxCore.NxCALLBACKRETURN_CONTINUE; } static unsafe void Main(string[] args) { if (args.Length < 1) return; int returnValue = NxCore.ProcessTape(args[0], null, 0, 0, StatusSample.OnNxCoreCallback); NxCore.processReturnValue(returnValue); } }
Callback Function
Since we only want to process status messages we check that MessageType equals NxMSG_STATUS. |
static unsafe int OnNxCoreCallback(NxCoreSystem* pNxCoreSys, NxCoreMessage* pNxCoreMsg) { if (pNxCoreMsg->MessageType == NxCore.NxMSG_STATUS) { ... } return (int)NxCore.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 (pNxCoreSys->ClockUpdateInterval >= NxCore.NxCLOCK_MINUTE) { int year = pNxCoreSys->nxDate.Year; int month = pNxCoreSys->nxDate.Month; int day = pNxCoreSys->nxDate.Day; int hour = pNxCoreSys->nxTime.Hour; int minute = pNxCoreSys->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 (pNxCoreSys->Status == NxCore.NxCORESTATUS_WAITFORCOREACCESS) Console.WriteLine("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 (pNxCoreSys->Status == NxCore.NxCORESTATUS_ERROR) Console.WriteLine("tape error:{0:d}", pNxCoreSys->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. | if (pNxCoreSys->Status == NxCore.NxCORESTATUS_INITIALIZING) { int major = NxCore.GetMajorVersion(pNxCoreSys->DLLVersion); int minor = NxCore.GetMinorVersion(pNxCoreSys->DLLVersion); int build = NxCore.GetBuildVersion(pNxCoreSys->DLLVersion); Console.WriteLine("Initialized with decoder version {0:d}.{1:d}.{2:d}", major, minor, build); } |
Next:
Symbol