Basic: | Intro/Trade | Quote | Category | Status | Symbol | Options |
Detailed: | Trade | Quote |
Introduction to Statuses
This guide assumes you have already read the "Getting Started With Trades" guide. 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 NxCore def OnNxCoreCallback(NxCoreSys, NxCoreMsg): if NxCoreMsg.MessageType == NxCore.NxMSG_STATUS: if NxCoreSys.ClockUpdateInterval >= NxCLOCK_MINUTE: year = NxCoreSys.nxDate.Year month = NxCoreSys.nxDate.Month day = NxCoreSys.nxDate.Day hour = NxCoreSys.nxTime.Hour minute = NxCoreSys.nxTime.Minute print("{:02d}/{:02d}/{:04d} {:02d}:{:02d}" .format(month, day, year, hour, minute)) if NxCoreSys.Status == NxCore.NxCORESTATUS_WAITFORCOREACCESS: print("Waiting on NxCore Access") if NxCoreSys.Status == NxCore.NxCORESTATUS_ERROR: print("tape error:{}",NxCoreSys.StatusData) if NxCoreSys.Status == NxCore.NxCORESTATUS_INITIALIZING: major = NxCore.GetMajorVersion(NxCoreSys.DLLVersion) minor = NxCore.GetMinorVersion(NxCoreSys.DLLVersion) build = NxCore.GetBuildVersion(NxCoreSys.DLLVersion) print("Initialized with decoder version {}.{}.{}" .format(major,minor,build)) 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 status messages we check that MessageType equals NxCore.NxMSG_STATUS. |
def OnNxCoreCallback(NxCoreSys, NxCoreMsg): if NxCoreMsg.MessageType == NxCore.NxMSG_CATEGORY: ... return 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. nxDate and nxTime are NxDate and NxTime types respectively. |
if NxCoreSys.ClockUpdateInterval >= NxCore.NxCLOCK_MINUTE: year = NxCoreSys.nxDate.Year month = NxCoreSys.nxDate.Month day = NxCoreSys.nxDate.Day hour = NxCoreSys.nxTime.Hour 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 == NxCore.NxCORESTATUS_WAITFORCOREACCESS: print("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 == NxCore.NxCORESTATUS_ERROR: print("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. |
if NxCoreSys.Status == NxCore.NxCORESTATUS_INITIALIZING: major = NxCore.GetMajorVersion(NxCoreSys.DLLVersion) minor = NxCore.GetMinorVersion(NxCoreSys.DLLVersion) build = NxCore.GetBuildVersion(NxCoreSys.DLLVersion) |
Next:
Symbol