API Documentation

Language: C++ Java Python
Basic: Intro/Trade Quote Category Status Symbol Options
Detailed: Trade Quote

Getting Started and Introduction to Trades

This is a simple introduction to writing code using NxCore. If you are not ready to begin writing code, check out Time and Sales to extract NxCore Data using a GUI. This example will cover printing the price and size of trades.

Getting Started

  • Download and extract the zip which includes everything you need to get started: here
  • To compile the code using the included project files, install Visual Studios Build Tools on Windows or Make on MacOS and Linux. If compiling with a different IDE simply ensure the NxCoreAPI folder is an included directory.
    • On Windows: open the MSVS Developer Command prompt and run msbuild trade.vcxproj /p:Platform="x64"
    • On macOS and Linux: run make
  • Run the executable specifying the path to the library(.dll or .so or.dylib depending on OS) as the first argument and path to the demo.XU.nx2 file as the second argument.

Code

#include "stdio.h"
#include "NxCoreAPI_Wrapper_C++.h"
NxCoreClass NxCore;

int OnNxCoreCallback(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMsg) {
    if(pNxCoreMsg->MessageType == NxMSG_TRADE) {

        const NxCoreHeader& header = pNxCoreMsg->coreHeader;
        char* symbol = header.pnxStringSymbol->String;
        const NxTime& timestamp = header.nxExgTimestamp;

        const NxCoreTrade& trade = pNxCoreMsg->coreData.Trade;
        double price = NxCore.PriceToDouble(trade.Price,trade.PriceType);
        int size = trade.Size;

        printf("Trade for %s at %02d:%02d:%02d %d shares at $%.02f\n",
        symbol, timestamp.Hour, timestamp.Minute, timestamp.Second, size, price);
    }
    return NxCALLBACKRETURN_CONTINUE;
}

int main(int argc, char* argv[]) {
    if (argc < 3)
        return 1;

    if (NxCore.LoadNxCore(argv[1])){
        int returnValue = NxCore.ProcessTape(argv[2], 0, 0, 0, OnNxCoreCallback);
        NxCore.ProcessReturnValue(returnValue);
    }
    else
        printf("loading library failed\n");

    return 0;
}

Import

This imports the basic IO header for printf as well as the NxCore c++ Header to use the NxCore Class as well as defined values. Next, the NxCore class for this program is declared.

#include "stdio.h"
#include "NxCoreAPI_Wrapper_C++.h"
NxCoreClass NxCore;

Callback Function

The NxCore API uses a callback function to deliver tick data. OnNxCoreCallback must be defined with 2 parameters of type NxCoreSystem and NxCoreMessage, respectively. The callback should return NxCALLBACKRETURN_CONTINUE to receive the next message.
The type of message is set in the MessageType field of the NxCoreMessage object. Since we only want to process trades we check that MessageType equals NxMSG_TRADE.

int OnNxCoreCallback(
    const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMsg) {
    if(pNxCoreMsg->MessageType == NxMSG_TRADE) {
        ...
    }
    return NxCALLBACKRETURN_CONTINUE;
}

Message Header

The coreHeader member in NxCoreMessage contains general information about the message. For this example we will get the Symbol from pnxStringSymbol and exchange timestamp. For most feeds nxExgTimestamp will have millisecond resolution.

const NxCoreHeader& header = pNxCoreMsg->coreHeader;
char* symbol = header.pnxStringSymbol->String;
const NxTime& timestamp = header.nxExgTimestamp;

Trade Message

The Trade member in the coreData member in NxCoreMessage contains details of the trade when MessageType is NxMSG_TRADE. For this example we will get the size of the trade and the price as a double. PriceToDouble can be used to convert NxCore integer Prices into a double floating-point price.

const NxCoreTrade& trade = pNxCoreMsg->coreData.Trade;
double price = NxCore.PriceToDouble(trade.Price,trade.PriceType);
int size = trade.Size;

Printing

This simply prints the values we found earlier in the code.

printf("Trade for %s at %02d:%02d:%02d %d shares at $%.02f\n",
    symbol, timestamp.Hour, timestamp.Minute, timestamp.Second, size, price);

Loading Library

Processing NxCore tapes requires that the NxCore dynamic library is loaded. The argument for LoadNxCore is the path to the corresponding dynamic library. On Windows the path can be relative to the working directory or absolute. For all other operating systems the path must be absolute. On success LoadNxCore returns non-zero.
For 32-bit Windows: "NxCoreAPI.dll"
For 64-bit Windows: "NxCoreAPI64.dll"
For Linux: "libnx.so"
For macOS: "libnx.dylib"

if (NxCore.LoadNxCore(argv[1]))
    ...
else
    printf("loading library failed\n");

Start Processing

ProcessTape begins processing the file in the first argument. The callback declared earlier should be the fifth argument. For this simple example all other arguments can be ignored. ProcessReturnValue prints the result of ProcessTape.

int returnValue = NxCore.ProcessTape(argv[2], 0, 0, 0, OnNxCoreCallback);
NxCore.ProcessReturnValue(returnValue);

Next:
Quote
Detailed Trade