Table of Contents


Syntax


    typedef NxCoreCallback(__stdcall *NxCoreSetCallback) (NxCoreCallback nxCoreCallback);
    #define cszNxCoreSetCallback "sNxCoreSetCallback"

    int __stdcall SetCallback(NxCoreCallback nxCoreCallback);

Parameters

nxCoreCallback

Specifies the function to use as a callback from now on.

Return Value

Returns the old nxCoreCallback function

Example

Here's an example of switching callbacks


#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <stdio.h>

#include <NxCoreAPI.h>
#include <NxCoreAPI_class.h>

#include "SymbolData.h"

NxCoreClass nxCoreClass;

SymbolData* getSymbol(const NxCoreHeader& ch)
{
    NxString* nx;

    if (ch.pnxOptionHdr)
    {
        nx = ch.pnxOptionHdr->pnxsDateAndStrike;
    }
    else
    {
        nx = ch.pnxStringSymbol;
    }

    if (nx->UserData1 == 0)
    {
        char symbol[32];

        if (ch.pnxOptionHdr)
        {
            sprintf(symbol, "%s%c%c",
                    ch.pnxStringSymbol->String,
                    ch.pnxOptionHdr->pnxsDateAndStrike->String[0],
                    ch.pnxOptionHdr->pnxsDateAndStrike->String[1]);
        }
        else
        {
            sprintf(symbol, "%s", ch.pnxStringSymbol->String);
        }

        SymbolData* symbolData = new SymbolData(symbol);

        nx->UserData1 = (int) symbolData;
    }

    return (SymbolData*) nx->UserData1;
}

int __stdcall nxCoreCallback(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMessage)
{
    // normal stuff
    return NxCALLBACKRETURN_CONTINUE;
}

int __stdcall nxCoreCallbackInitialSpin(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMessage)
{
    switch (pNxCoreMessage->MessageType)
    {
        case NxMSG_SYMBOLSPIN:
        {
            const NxCoreHeader& ch = pNxCoreMessage->coreHeader;

            getSymbol(ch);

            break;
        }
        case NxMSG_STATUS:
        {
            switch (pNxCoreSys->Status)
            {
                case NxCORESTATUS_SYMBOLSPIN:
                {
                    if (pNxCoreSys->StatusData == NxCSSYMBOLSPIN_COMPLETE)
                    {
                        nxCoreClass.SetCallback(nxCoreCallback);

                        return NxCALLBACKRETURN_RESTART;
                    }

                    break;
                }
            }
            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("", 0, NxCF_EXCLUDE_CRC_CHECK, 0, nxCoreCallbackInitialSpin);

    return 0;
}