#define cszNxCoreGetStateData "sNxCoreGetStateData"
typedef int (__stdcall *NxCoreGetStateData) (char* pBuffer, int bufferSize, int stateType, int param1, int param2, NxString* pnxsSymOrCtc);
int GetStateData(
char* pBuffer,
int bufferSize,
int stateType,
int param1,
int param2,
NxString* pnxsSymOrCtc
);
| stateType | pBuffer | param1 | param2 |
|---|---|---|---|
| NxSTATETYPE_OHLCTRADE | NxCoreStateOHLCTrade | 0 | 0 |
| NxSTATETYPE_EXGQUOTES | NxCoreStateExgQuotes | 0 | 0 |
| NxSTATETYPE_MMQUOTES | NxCoreStateMMQuotes | ReportingExg for which to get the MM quotes | 0 |
Here's an example of getting the OHLC trade, Exg quote, and MM quote information for every symbol that MM 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_MMQUOTE:
{
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);
do
{
NxCoreStateOHLCTrade nt;
int rc = nxCoreClass.GetStateData((char*) &nt, sizeof(nt), NxSTATETYPE_OHLCTRADE, 0, 0, nx);
if (rc != 0)
{
break;
}
printf("%.2d:%.2d:%.2d.%.3d %s Price(%ld @ %.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, nt.TradeSize, 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));
} while(false);
do
{
NxCoreStateExgQuotes q;
int rc = nxCoreClass.GetStateData((char*) &q, sizeof(q), NxSTATETYPE_EXGQUOTES, 0, 0, nx);
if (rc != 0)
{
break;
}
char buf[1024];
char* p = buf;
for (int i = 0; i < q.StateQuoteCount; i++)
{
const NxCoreStateExgQuote& eq = q.StateExgQuotes[i];
if (eq.BidPrice > 0 && eq.BidSize > 0)
{
p += sprintf(p, "%s_bid(%ld @ %.2lf)[%ld] ",
q.BestBidExg == eq.ReportingExg ? "BBO" : "RGN",
eq.BidSize, nxCoreClass.PriceToDouble(eq.BidPrice, q.PriceType), eq.ReportingExg);
}
if (eq.AskPrice > 0 && eq.AskSize > 0)
{
p += sprintf(p, "%s_ask(%ld @ %.2lf)[%ld] ",
q.BestAskExg == eq.ReportingExg ? "BBO" : "RGN",
eq.AskSize, nxCoreClass.PriceToDouble(eq.AskPrice, q.PriceType), eq.ReportingExg);
}
}
if (p > buf)
{
printf("%.2d:%.2d:%.2d.%.3d %s %s\n",
(int) t.Hour, (int) t.Minute, (int) t.Second, (int) t.Millisecond,
symbol, buf);
}
} while(false);
do
{
NxCoreStateMMQuotes mmq;
int rc = nxCoreClass.GetStateData((char*) &mmq, sizeof(mmq), NxSTATETYPE_MMQUOTES, ch.ReportingExg, 0, nx);
if (rc != 0)
{
break;
}
char buf[1024];
char* p = buf;
for (int i = 0; i < mmq.StateQuoteCount; i++)
{
const NxCoreStateMMQuote& mm = mmq.StateMMQuotes[i];
if (mm.BidPrice > 0 && mm.BidSize > 0)
{
p += sprintf(p, "MM_bid(%ld @ %.2lf)[%s|%ld] ",
mm.BidSize, nxCoreClass.PriceToDouble(mm.BidPrice, mmq.PriceType),
mm.pnxStringMarketMaker->String,
ch.ReportingExg);
}
if (mm.AskPrice > 0 && mm.AskSize > 0)
{
p += sprintf(p, "MM_ask(%ld @ %.2lf)[%s|%ld] ",
mm.AskSize, nxCoreClass.PriceToDouble(mm.AskPrice, mmq.PriceType),
mm.pnxStringMarketMaker->String,
ch.ReportingExg);
}
}
if (p > buf)
{
printf("%.2d:%.2d:%.2d.%.3d %s %s\n",
(int) t.Hour, (int) t.Minute, (int) t.Second, (int) t.Millisecond,
symbol, buf);
}
} while(false);
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;
}