Table of Contents


NxCoreStateTrade

The struct NxCoreStateTrade is defined in NxCoreAPI.h as:

struct NxCoreStateTrade {
  unsigned __int64 TotalVolume;
  unsigned int     TickVolume;
  unsigned char    PriceType;
  unsigned char    PriceFlags;
  unsigned char    ConditionFlags;
  unsigned char    VolumeType;
  int              Open;
  int              High;
  int              Low;
  int              Last;
  int              NetChange;
  int              Price;
  int              Threshold;
  int              Tick;
};

TotalVolume

Latest TotalVolume for the symbol

TickVolume

Latest TickVolume for the symbol

PriceType

Latest PriceType for the symbol

PriceFlags

Latest PriceFlags for the symbol

ConditionFlags

Latest ConditionFlags for the symbol

VolumeType

Latest VolumeType for the symbol

Open

Latest Open for the symbol

High

Latest High for the symbol

Low

Latest Low for the symbol

Last

Latest Last for the symbol

NetChange

Latest NetChange for the symbol

Price

Latest Price for the symbol

Threshold

Latest Threshold for the symbol

Tick

Latest Tick for the symbol

Example

Here's an example of getting the trade information for every symbol that quotes

#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <stdio.h>
#include "NxCoreAPI.h"
#include "NxCoreAPI_class.h"    
  
NxCoreClass nxCoreClass;    
  
NxString *getSymbol(const NxCoreMessage* pNxCoreMsg,char *Symbol)
{
    // Is this a valid option?    
    if ((pNxCoreMsg->coreHeader.pnxStringSymbol->String[0]=='o')&&(pNxCoreMsg->coreHeader.pnxOptionHdr))
    {
        // If pnxsDateAndStrike->String[0] == ' ', then this symbol is in new OSI format. 	
        if (pNxCoreMsg->coreHeader.pnxOptionHdr->pnxsDateAndStrike->String[0]==' ')	
        {
            sprintf(Symbol,"%s%02d%02d%02d%c%08d",
                    pNxCoreMsg->coreHeader.pnxStringSymbol->String,
                    pNxCoreMsg->coreHeader.pnxOptionHdr->nxExpirationDate.Year-2000,
                    pNxCoreMsg->coreHeader.pnxOptionHdr->nxExpirationDate.Month,
                    pNxCoreMsg->coreHeader.pnxOptionHdr->nxExpirationDate.Day,
                    (pNxCoreMsg->coreHeader.pnxOptionHdr->PutCall == 0) ? 'C' : 'P',
                    pNxCoreMsg->coreHeader.pnxOptionHdr->strikePrice);
        }
        // Otherwise the symbol is in old OPRA format.
        else
        {
            sprintf(Symbol,"%s%c%c",
                    pNxCoreMsg->coreHeader.pnxStringSymbol->String,
                    pNxCoreMsg->coreHeader.pnxOptionHdr->pnxsDateAndStrike->String[0],
                    pNxCoreMsg->coreHeader.pnxOptionHdr->pnxsDateAndStrike->String[1]);
        }    
  
        // Return nx date-strike string ptr
        return pNxCoreMsg->coreHeader.pnxOptionHdr->pnxsDateAndStrike;
    }    
  
    // Not an option, just copy the symbol and return nx string ptr
    strcpy(Symbol,pNxCoreMsg->coreHeader.pnxStringSymbol->String);    
  
    return pNxCoreMsg->coreHeader.pnxStringSymbol;
}    
 
int __stdcall nxCoreCallback(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMessage)
{
    switch (pNxCoreMessage->MessageType)
    {
        case NxMSG_EXGQUOTE:
        {
            const NxCoreHeader& ch = pNxCoreMessage->coreHeader;
            const NxTime&       t  = pNxCoreSys->nxTime;    
    
            // Get the symbol and the correct string pointer
            char symbol[23];
            NxString* nx =getSymbol(pNxCoreMessage,symbol);    
 
            NxCoreStateTrade nt;
            int rc = nxCoreClass.StateGetLastTrade(&nt, nx);
            if (rc != 0)
            {
                break;
            }    
    
            printf("%.2d:%.2d:%.2d.%.3d %s Price(%.2lf) O(%.2lf) H(%.2lf) L(%.2lf) C(%.2lf) V(%I64d) Net(%.2lf)\n",
                                (int) t.Hour, (int) t.Minute, (int) t.Second, (int) t.Millisecond,
                                symbol, nxCoreClass.PriceToDouble(nt.Price, nt.PriceType),
                                nxCoreClass.PriceToDouble(nt.High,      nt.PriceType),
                                nxCoreClass.PriceToDouble(nt.Low,       nt.PriceType),
                                nxCoreClass.PriceToDouble(nt.Last,      nt.PriceType),
                                nxCoreClass.PriceToDouble(nt.Open,      nt.PriceType),
                                nt.TotalVolume,
                                nxCoreClass.PriceToDouble(nt.NetChange, nt.PriceType));
            break;
        }
    }    
    
    return NxCALLBACKRETURN_CONTINUE;
}    
    
int main(int argc, char** argv)
{
    if (!nxCoreClass.LoadNxCore("NxCoreAPI.dll") &&
        !nxCoreClass.LoadNxCore("C:\\Program Files\\Nanex\\NxCoreAPI\\NxCoreAPI.dll"))
    {
        fprintf(stderr, "Can't find NxCoreAPI.dll\n");
        return -1;
    }
    nxCoreClass.ProcessTape(argv[1], 0, NxCF_EXCLUDE_CRC_CHECK, 0, nxCoreCallback);
    return 0;
}