UserDataSample1.cpp
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include "NxCoreAPI.h" #include "NxCoreAPI_Wrapper_C++.h" NxCoreClass NxCore; int __stdcall OnNxCoreCallback(const NxCoreSystem* pNxCoreSys,const NxCoreMessage* pNxCoreMsg) { // message handler function. switch(pNxCoreMsg->MessageType) { // Process Symbol Spin and Symbol Change add messages case NxMSG_SYMBOLCHANGE: if(pNxCoreMsg->coreData.SymbolChange.Status != NxSS_ADD) return NxCALLBACKRETURN_CONTINUE; case NxMSG_SYMBOLSPIN: // First check to see if this is an equity symbol type.... if (pNxCoreMsg->coreHeader.pnxStringSymbol->String[0]=='e') { // Check to see if this is one of the stocks we are interested in. // If it is, set UserData1 to 1. if ((strcmp(pNxCoreMsg->coreHeader.pnxStringSymbol->String,"eAAPL")==0)|| (strcmp(pNxCoreMsg->coreHeader.pnxStringSymbol->String,"eIBM")==0)|| (strcmp(pNxCoreMsg->coreHeader.pnxStringSymbol->String,"eGE")==0)) { pNxCoreMsg->coreHeader.pnxStringSymbol->UserData1=1; printf("Interest Set for %s\n",pNxCoreMsg->coreHeader.pnxStringSymbol->String); } } break; // Process a trade message case NxMSG_TRADE: // If UserData1 is set then we are interested in this symbol.... if (pNxCoreMsg->coreHeader.pnxStringSymbol->UserData1) { const NxTime& t = pNxCoreMsg->coreHeader.nxExgTimestamp; const NxCoreTrade& nt = pNxCoreMsg->coreData.Trade; // Print a line with trade details. printf("Trade Msg - %02d:%02d:%02d.%03d Symbol=%s, Price=%0.4f, Size=%d\n", t.Hour,t.Minute,t.Second,t.Millisecond, pNxCoreMsg->coreHeader.pnxStringSymbol->String, NxCore.PriceToDouble(nt.Price,nt.PriceType), nt.Size); } break; } // Continue running the tape return NxCALLBACKRETURN_CONTINUE; } int main(int argc, char** argv) { if (!NxCore.LoadNxCore("NxCoreAPI64.dll") && !NxCore.LoadNxCore("NxCoreAPI.dll")) { fprintf(stderr, "loading library failed\n"); return -1; } NxCore.ProcessTape(argv[1], 0, NxCF_EXCLUDE_CRC_CHECK | NxCF_EXCLUDE_QUOTES | NxCF_EXCLUDE_QUOTES2 | NxCF_EXCLUDE_OPRA, 0, OnNxCoreCallback); return 0; } |
import net.nanex.NxCoreClass; class UserDataSample1 extends NxCoreClass{ @Override public int OnNxCoreCallback(NxCoreSystem nxCoreSys, NxCoreMessage nxCoreMsg) { switch (nxCoreMsg.MessageType) { // Process Symbol Spin and Symbol Change add messages case defines.NxMSG_SYMBOLCHANGE: if(nxCoreMsg.coreData.SymbolChange.Status != defines.NxSS_ADD) return defines.NxCALLBACKRETURN_CONTINUE; case defines.NxMSG_SYMBOLSPIN: // First check to see if this is an equity symbol type.... if (nxCoreMsg.coreHeader.pnxStringSymbol.String.charAt(0)=='e') { // Check to see if this is one of the stocks we are interested in. // If it is, set UserData1 to 1. if (nxCoreMsg.coreHeader.pnxStringSymbol.String.equals("eAAPL")|| nxCoreMsg.coreHeader.pnxStringSymbol.String.equals("eIBM")|| nxCoreMsg.coreHeader.pnxStringSymbol.String.equals("eGE")) { nxCoreMsg.coreHeader.pnxStringSymbol.UserData1=1; System.out.println(String.format( "Interest Set for %s\n",nxCoreMsg.coreHeader.pnxStringSymbol.String)); } } break; case defines.NxMSG_TRADE: // If UserData1 is set then we are interested in this symbol.... if (nxCoreMsg.coreHeader.pnxStringSymbol.UserData1 != 0) { NxTime t = nxCoreMsg.coreHeader.nxExgTimestamp; NxCoreTrade nt = nxCoreMsg.coreData.Trade; // Print a line with trade details. System.out.println(String.format( "Trade Msg - %02d:%02d:%02d.%03d Symbol=%s, Price=%.4f, Size=%d", t.Hour,t.Minute,t.Second,t.Millisecond, nxCoreMsg.coreHeader.pnxStringSymbol.String, PriceToDouble(nt.Price,nt.PriceType), nt.Size)); } break; } return defines.NxCALLBACKRETURN_CONTINUE; } public static void main(String args[]) { UserDataSample1 nxCore = new UserDataSample1(); if (nxCore.LoadNxCore("NxCoreAPI64.dll") != 0){ nxCore.ProcessTape(args[0], 0, defines.NxCF_EXCLUDE_CRC_CHECK | defines.NxCF_EXCLUDE_QUOTES | defines.NxCF_EXCLUDE_QUOTES2 | defines.NxCF_EXCLUDE_OPRA, 0); } else System.out.println("loading library failed"); } } |
import NxCore tapePath = "" def OnNxCoreCallback(NxCoreSys, NxCoreMsg): #Process Symbol Spin and Symbol Change add messages if ((NxCoreMsg.MessageType == NxCore.NxMSG_SYMBOLCHANGE and NxCoreMsg.coreData.SymbolChange.Status != NxCore.NxSS_ADD) or NxCoreMsg.MessageType == NxCore.NxMSG_SYMBOLSPIN): ch = NxCoreMsg.coreHeader t = NxCoreSys.nxTime # First check to see if this is an equity symbol type.... if NxCoreMsg.coreHeader.pnxStringSymbol.String[0]=='e': # Check to see if this is one of the stocks we are interested in. # If it is, set UserData1 to 1. if (NxCoreMsg.coreHeader.pnxStringSymbol.String == "eAAPL" or NxCoreMsg.coreHeader.pnxStringSymbol.String == "eIBM" or NxCoreMsg.coreHeader.pnxStringSymbol.String == "eGE"): NxCoreMsg.coreHeader.pnxStringSymbol.UserData1=1 print("Interest Set for {}\n".format(NxCoreMsg.coreHeader.pnxStringSymbol.String)) elif NxCoreMsg.MessageType == NxCore.NxMSG_TRADE: # If UserData1 is set then we are interested in this symbol.... if NxCoreMsg.coreHeader.pnxStringSymbol.UserData1 != 0: t = NxCoreMsg.coreHeader.nxExgTimestamp nt = NxCoreMsg.coreData.Trade # Print a line with trade details. print( "Trade Msg - {:02d}:{:02d}:{:02d}.{:03d} Symbol={}, Price={:.4f}, Size={}".format( t.Hour,t.Minute,t.Second,t.Millisecond, NxCoreMsg.coreHeader.pnxStringSymbol.String, NxCore.PriceToFloat(nt.Price,nt.PriceType), nt.Size)) return NxCore.NxCALLBACKRETURN_CONTINUE if NxCore.LoadNxCore("NxCoreAPI64.dll"): NxCore.ProcessTape(tapePath, 0, 0, NxCore.NxCF_EXCLUDE_CRC_CHECK | NxCore.NxCF_EXCLUDE_QUOTES | NxCore.NxCF_EXCLUDE_QUOTES2 | NxCore.NxCF_EXCLUDE_OPRA, OnNxCoreCallback) else: print("loading library failed") |