Performance Magic
pnxStringSymbol, pnxOptionHdr, UserData1 and UserData2
Many new NxCore share a common problem when first beginning to use NxCore. As an example one user shared the following comment:
This (or similar situations) is the most common performance related issue we hear about. If this relates to an issue you are experiencing please continue reading! For every message type sent through the NxCore callback function, a NxCoreMessage structure is passed. Within this structure is another structure, NxCoreHeader. Within that structure you will find a pointer (pnxStringSymbol) to an NxString structure, which contains: struct NxString { int UserData1; int UserData2; unsigned short Atom; char String[1];There are 3 very important facts worth emphasizing here:
Once the concepts of using the pnxStringSymbol pointer and the UserData1 and UserData2 elements is understood, the next question is usually when to set and/or capture this data. While there are numerous caveats depending on the exact application, you will generally want to set/capture these items in the initial symbol spin, which is a primary NxCore message NxMSG_SYMBOLSPIN. Options While other equity types (futures, indexes, currencies, etc) operate the same way as equities, Options are handled slightly differently. With options, pnxStringSymbol will only point to the root symbol. To set option data for an individual contract, use the pnxOptionHdr pointer (contained in the NxCoreHeader structure). This points to a NxOptionHdr structure which contains another NxString pointer, pnxsDateAndStrike. For options, set/check UserData1 and UserData2 with pnxsDateAndStrike (pnxsDateAndStrike->UserData1, pnxsDateAndStrike->UserData2). Because an example is always the easiest way to demonstrate a concept, we provide 2 very simple console applications that demonstrate the use of these elements. With a little imagination these two examples should provide the insight needed for complex filtering at blazingly fast speeds. Please note that the examples use the standard console ( "printf" ) to display the data and in the first example will print every trade for the symbols with interest set. This is not an efficient GUI by any stretch and is in fact quite slow. However, we wanted to keep the samples as simple as possible to demonstrate the concept without the need to understand pages of GUI code first. We leave it to you to improve upon these mechanisms in your own applications. UserDataSample1 In this example, we suppose the user would like to look at only 3 symbols throughout the course of the day, and process every trade message for those symbols only. The symbols in this example will be hard-coded to "IBM, AAPL and GE". Click HERE to view the source. UserDataSample2 In this example, we again suppose the user would like to look at only 3 symbols throughout the course of the day, and process every trade message for those symbols only. However in this sample, data is also indexed and referenced into a user defined composite record, and data from the composite records are printed every minute for the symbols. The symbols in this example will be hard-coded to "IBM, AAPL and GE". Click HERE to view the source. As you can see, in both examples we have only used UserData1 and in UserDataSample2, we used it to perform 2 tasks (interest set check and a reference into a custom structure array). Using both UserData1 and UserData2, the possibilities are endless. |