UserDataSample1.cpp
//////////////////////////////////////////////////////////////////////////////// //// UserDataSample1.cpp //// //// Sample App for NxCore in C/C++ //// //// Author: Jeffrey Donovan //// //// Date: 10-29-10 //// //////////////////////////////////////////////////////////////////////////////// //// Demonstrates: //// //// 1) Using the SYMBOLSPIN message to filter symbols at startup. //// //// 2) Setting UserData1 for quick determination of symbols interested in. //// //// 3) Processing trades for only the symbols we are interested in. //// //////////////////////////////////////////////////////////////////////////////// //// To Read as Written: //// //// Tab Size: 4 Indent Size: 2, Keep Tabs //// //////////////////////////////////////////////////////////////////////////////// #include "stdio.h" #include "NxCoreLoadLib.h" // NxCore DLL Load Library // Forward define for callback int __stdcall OnNxCoreCallback(const NxCoreSystem* pNxCoreSys,const NxCoreMessage* pNxCoreMsg); // Main Entry Point for app. int main(int argc, char* argv[]) { printf("NxCore C UserDataSample1 Start.\n"); // If we can load the NxCore DLL if (LoadNxCore("NxCoreAPI.dll")) { printf("NxCoreAPI.dll Loaded.\n"); // If a tape filename was passed in command line argument, // call ProcessTape with that argument. Use control flags // to eliminate Level1 quotes, Level2 quotes and all OPRA // quotes. if (argv[1]) pfNxCoreProcessTape(argv[1], NULL, (NxCF_EXCLUDE_QUOTES | NxCF_EXCLUDE_QUOTES2 | NxCF_EXCLUDE_OPRA), 0,OnNxCoreCallback); else pfNxCoreProcessTape("", NULL, (NxCF_EXCLUDE_QUOTES | NxCF_EXCLUDE_QUOTES2 | NxCF_EXCLUDE_OPRA), 0,OnNxCoreCallback); // Unload NxCore DLL UnloadNxCore(); } printf("NxCore C UserDataSample1 Stop.\n"); // Exit app return 0; } //------------------------------------------------------------ int __stdcall OnNxCoreCallback(const NxCoreSystem* pNxCoreSys,const NxCoreMessage* pNxCoreMsg) { // If this is an NxCore Status message pass it to the status // message handler function. switch(pNxCoreMsg->MessageType) { // Process a status message case NxMSG_STATUS: // Print the specific NxCore status message switch( pNxCoreSys->Status ) { case NxCORESTATUS_COMPLETE:printf("NxCore Complete Message.\n");break; case NxCORESTATUS_INITIALIZING:printf("NxCore Initialize Message.\n");break; case NxCORESTATUS_ERROR:printf("NxCore Error.\n");break; } break; // Process SymbolSpin to initially set/filter symbols. // This message is sent once at the start of the tape for each symbol. 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) { // Print a line with trade details. printf("Trade Msg - %02d:%02d:%02d Symbol=%s, Price=%0.4f, Size=%d\n", pNxCoreMsg->coreHeader.nxExgTimestamp.Hour,pNxCoreMsg->coreHeader.nxExgTimestamp.Minute,pNxCoreMsg->coreHeader.nxExgTimestamp.Second, pNxCoreMsg->coreHeader.pnxStringSymbol->String, pfNxCorePriceToDouble(pNxCoreMsg->coreData.Trade.Price,pNxCoreMsg->coreData.Trade.PriceType), pNxCoreMsg->coreData.Trade.Size); } break; } // Continue running the tape return NxCALLBACKRETURN_CONTINUE; } |