API Documentation

Syntax

Removes a permission ID from being processed from the tape. This function is introduced in version 3.0.123/3.2.21 and is intended to replace the ExcludeOpraExch function.

    int RemovePermission(int permissionID);

Parameters

permissionID

A list permission IDs can be found in the NxST_PERMID string table. To avoid tape errors, this function should not be used to split individual symbols. If a symbol comes under more than one permission ID, then you can either remove none or all of those permission ID.

Return Value

Returns one of the following values

#define in NxCoreAPI.h Int Description
NxAPIERR_NO_ERROR 0 The operation was completed succesfully
1 The permission table has not been loaded or the permission is invalid
NxAPIERR_NOT_CALLBACK_THREAD -1 Function was called from thread other than callback thread
NxAPIERR_BAD_PARAMETERS -2 permissionID value was invalid

Example

Here's an example of how to process CTA and UTP on separate threads. This example utilizes NxCoreTableHelper.h.

#include <stdio.h>
#include <vector>
#include <thread>
#include <iomanip>

#include <NxCoreAPI_Wrapper_C++.h>     
#include "NxCoreTableHelper.h"


struct ThreadData {
    int threadNum;
    std::vector<int> permissions;
    bool removed = false;
};

#define MAXID 128
NxCoreClass NxCore;
thread_local ThreadData myThreadData;

void onNxCoreStatus(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMsg) {
    //Print time
    if (pNxCoreSys->ClockUpdateInterval >= NxCLOCK_MINUTE && pNxCoreSys->nxTime.Hour < 24) {
        cout.fill('0');
        cout << "Thread: " << myThreadData.threadNum << " NxCoreTime: " <<
            setw(2) << (int)pNxCoreSys->nxTime.Hour << ":" <<
            setw(2) << (int)pNxCoreSys->nxTime.Minute << ":" <<
            setw(2) << (int)pNxCoreSys->nxTime.Second << endl;
    }
    
    //Log Errors. Errors NxCA_EXCEPTION_OPTSYMBOL(10) and NxCA_EXCEPTION_SYMBOL(11) indicate 
    //a permission was removed that shouldn't be. See Proper Use section for more details.
    if (pNxCoreSys->Status == NxCORESTATUS_ERROR)
        cout << "Tape Error: " << pNxCoreSys->StatusData << " on thread " << myThreadData.threadNum << endl;
    
    //Remove unwanted permissions
    if (!myThreadData.removed) {
        for (int perm = 1; perm < MAXID; ++perm) {
            if (std::find(myThreadData.permissions.begin(), myThreadData.permissions.end(), perm) != myThreadData.permissions.end())// this permission should be processed on this thread, so do not remove
                continue;
            int result = NxCore.RemovePermission(perm);
            if (result != 0) {//non-zero result indicates failure
                if (result == -1)
                    cout << "Function was called from thread other than callback thread" << endl;
                if (result == -2)
                    cout << "Permission ID value was invalid" << endl;
                return;// could not remove permission during this status message. Try again next status message.
            }
        }
        //successfully removed all permissions
        myThreadData.removed = true;
    }
}

int __stdcall nxCoreCallback(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMsg) {
    switch (pNxCoreMsg->MessageType) {
    case NxMSG_STATUS:
        onNxCoreStatus(pNxCoreSys, pNxCoreMsg);
            break;
    }
    return NxCALLBACKRETURN_CONTINUE;
}

void thProcess(const char* tapepath, int threadNum, std::vector<int> permissions) {
    //save thread information to thread_local object to be used during callback
    myThreadData.permissions = permissions;
    myThreadData.threadNum = threadNum;

    int returnValue = NxCore.ProcessTape(tapepath, 0, NxCF_EXCLUDE_CRC_CHECK, 0, (NxCoreCallback)nxCoreCallback);
    cout << "Thread " << threadNum << " completed: Status follows..." << endl;
    NxCore.ProcessReturnValue(returnValue);
}

int main(int argc, char* argv[])
{
    if (NxCore.LoadNxCore("NxCoreAPI64.dll")) {
        std::vector<std::thread> threads;

        //Create CTA feed thread
        threads.push_back(std::thread(thProcess, argc > 1 ? argv[1] : "", 0,
        std::vector<int>{nxST_PERMID::NYSEQTE, nxST_PERMID::AMEXQTE, nxST_PERMID::NYSETRD, nxST_PERMID::AMEXTRD, nxST_PERMID::NYSECORP, nxST_PERMID::AMEXCORP}
        ));
        //Create UTP feed thread
        threads.push_back(std::thread(thProcess, argc > 1 ? argv[1] : "", 1,
        std::vector<int>{nxST_PERMID::NASDQTE, nxST_PERMID::NASDTRD}
        ));
        
        //Wait for threads to finish
        for (std::thread& thread : threads)
            thread.join();

        // Unload NxCore DLL
        NxCore.UnloadNxCore();
    }
    else {
        cout << "loading library failed" << endl;
        return -1;
    }
    return 0;
}
import java.util.*;
import net.nanex.NxCoreClass;
class RemovePermissionSample {
    public static void main(String args[]) throws InterruptedException {

        Thread[] threads = {
            //create CTA feed thread
            //permissions: NYSEQTE(13), AMEXQTE(14), NYSETRD(17), AMEXTRD(18), NYSECORP(90), AMEXCORP(91)
            new Thread(new NxCoreThread(args.length > 0 ?  args[0] : "", 1, Arrays.asList(13, 14, 17, 18, 90, 91))),
            //create UTP feed thread
            //permissions: NASDQTE(6), NASDTRD(9)
            new Thread(new NxCoreThread(args.length > 0 ? args[0] : "", 2, Arrays.asList(1, 6, 9)))
        };
        for(Thread thread : threads)
            thread.start();
        for(Thread thread : threads)
            thread.join();
    }
}

class NxCoreThread extends NxCoreClass implements Runnable {
    private String tapepath;
    private int threadNum;
    private List<Integer> permissions;
    private boolean removed = false;
    private final int MAXID = 128;
    
    public NxCoreThread(String tapePath, int threadNum, List<Integer> permissions) {
        this.tapepath = tapePath;
        this.threadNum = threadNum;
        this.permissions = permissions;
    }
    
    public void run() {
        if(LoadNxCore("NxCoreAPI64.dll") != 0){
            int returnValue = ProcessTape(tapepath, 0, defines.NxCF_EXCLUDE_CRC_CHECK, 0);
            ProcessReturnValue(returnValue);
        }
        else
            System.out.println("loading library failed");
    }
    
    void onNxCoreStatus( NxCoreSystem nxCoreSys, NxCoreMessage nxCoreMsg) {
        //Print time
        if (nxCoreSys.ClockUpdateInterval >= defines.NxCLOCK_MINUTE && nxCoreSys.nxTime.Hour < 24) {
            System.out.println(String.format("Thread: %d NxCoreTime: %02d:%02d:%02d",
                threadNum,
                nxCoreSys.nxTime.Hour,
                nxCoreSys.nxTime.Minute,
                nxCoreSys.nxTime.Second));
        }
        
        //Log Errors. Errors NxCA_EXCEPTION_OPTSYMBOL(10) and NxCA_EXCEPTION_SYMBOL(11) indicate 
        //a permission was removed that shouldn't be. See Proper Use section for more details.
        if (nxCoreSys.Status == defines.NxCORESTATUS_ERROR)
            System.out.println("Tape Error: " + nxCoreSys.StatusData + " on thread " + threadNum);
        
        //Remove unwanted permissions
        if (!removed) {
            for (int perm = 1; perm < MAXID;perm ++) {
                if (permissions.contains(perm))// this permission should be processed on this thread, so do not remove
                    continue;
                int result = RemovePermission(perm);
                if (result != 0) {//non-zero result indicates failure
                    if (result == -1)
                        System.out.println("Function was called from thread other than callback thread");
                    if (result == -2)
                        System.out.println("Permission ID value was invalid");
                    return;// could not remove permission during this status message. Try again next status message.
                }
            }
            //Successfully removed unwanted permissions
            removed = true;
        }
    }
    
    @Override
    public int OnNxCoreCallback( NxCoreSystem nxCoreSys, NxCoreMessage nxCoreMsg) {
        if (nxCoreMsg.MessageType == defines.NxMSG_STATUS)
            onNxCoreStatus(nxCoreSys, nxCoreMsg);
        return defines.NxCALLBACKRETURN_CONTINUE;
    }
}
import NxCore
from multiprocessing import Process

tapePath = ""

MAXID = 128

#Process varibles
permissions = set()
removed = False
threadNum = 0

def onNxCoreStatus(NxCoreSys, NxCoreMsg):
    #Print time
    if NxCoreSys.ClockUpdateInterval >= NxCore.NxCLOCK_MINUTE and NxCoreSys.nxTime.Hour < 24:
        print("Thread: {} NxCoreTime: {:02d}:{:02d}:{:02d}".format(
            threadNum,
            NxCoreSys.nxTime.Hour,
            NxCoreSys.nxTime.Minute,
            NxCoreSys.nxTime.Second))
    
    #Log Errors. Errors NxCA_EXCEPTION_OPTSYMBOL(10) and NxCA_EXCEPTION_SYMBOL(11) indicate 
    #a permission was removed that shouldn't be. See Proper Use section for more details.
    if NxCoreSys.Status == NxCore.NxCORESTATUS_ERROR:
        print("Tape Error: {} on thread {}".format(NxCoreSys.StatusData, threadNum))
    
    #Remove unwanted permissions
    global removed
    if not removed:
        print(permissions)
        for perm in range(1, MAXID):
            if perm in permissions:# this permission should be processed on this thread, so do not remove
                continue
            removeKey = NxCore.NxPERMID_REMOVE | perm
            result = NxCore.RemovePermission(removeKey)
            if result != 0:#non-zero result indicates failure
                if result == -1:
                    print("Function was called from thread other than callback thread")
                if result == -2:
                    print("Permission ID value was invalid")
                return# could not remove permission during this status message. Try again next status message.
        #Successfully removed unwanted permissions
        removed = True

def OnNxCoreCallback(NxCoreSys, NxCoreMsg):
    if NxCoreMsg.MessageType == NxCore.NxMSG_STATUS:
        onNxCoreStatus(NxCoreSys, NxCoreMsg)
    return NxCore.NxCALLBACKRETURN_CONTINUE

def NxCoreThread(permissionList, threadNumber):
    #set variables specific to this process
    global permissions
    global threadNum
    permissions = set(permissionList)
    threadNum = threadNumber
    
    #start processing NxCore Tape
    if NxCore.LoadNxCore("NxCoreAPI64.dll"):
        returnValue = NxCore.ProcessTape(tapePath, 0, NxCore.NxCF_EXCLUDE_CRC_CHECK, 0, OnNxCoreCallback)
        ProcessReturnValue(returnValue)
    else:
        print("loading library failed")
    
    
if __name__ == "__main__":
    threads = []
    #create CTA feed thread
    #permissions: NYSEQTE(13), AMEXQTE(14), NYSETRD(17), AMEXTRD(18), NYSECORP(90), AMEXCORP(91)
    threads.append(Process(target=NxCoreThread, args=([13, 14, 17, 18, 90, 91],1 )))
    #create UTP feed thread
    #permissions: NASDQTE(6), NASDTRD(9)
    threads.append(Process(target=NxCoreThread, args=([6,9],2 )))

    for thread in threads:
        thread.start()

    for thread in threads:
        thread.join()
using System;
using System.Threading;
using NxCoreAPI;
using System.Linq;// for array Contains function

class NxCoreThread
{
    private const int MAXID = 128;
    private String tapepath;
    private int threadNum;
    private int[] permissions;
    private bool removed = false;
    public NxCoreThread(String path, int num, int[] perms)
    {
        this.tapepath = path;
        this.permissions = perms;
        this.threadNum = num;
    }
    public unsafe void run()
    {
        int returnValue = NxCore.ProcessTape(tapepath, null, (uint)NxCore.NxCF_EXCLUDE_CRC_CHECK, 0, this.OnNxCoreCallback);
        NxCore.processReturnValue(returnValue);
    }
    unsafe void onNxCoreStatus(NxCoreSystem* pNxCoreSys, NxCoreMessage* pNxCoreMsg)
    {
        //Print time
        if (pNxCoreSys->ClockUpdateInterval >= NxCore.NxCLOCK_MINUTE && pNxCoreSys->nxTime.Hour < 24)
        {
            Console.WriteLine("Thread: {0:d} NxCoreTime: {1:d2}:{2:d2}:{3:d2}",
                threadNum,
                pNxCoreSys->nxTime.Hour,
                pNxCoreSys->nxTime.Minute,
                pNxCoreSys->nxTime.Second);
        }

        //Log Errors. Errors NxCA_EXCEPTION_OPTSYMBOL(10) and NxCA_EXCEPTION_SYMBOL(11) indicate 
        //a permission was removed that shouldn't be. See Proper Use section for more details.
        if (pNxCoreSys->Status == NxCore.NxCORESTATUS_ERROR)
            Console.WriteLine("Tape Error: {0:d}  on thread {1:d}", pNxCoreSys->StatusData, threadNum);

        //Remove unwanted permissions
        if (removed)
        {
            for (int perm = 1; perm < NxCoreThread.MAXID; ++perm)
            {
                if (permissions.Contains(perm))// this permission should be processed on this thread, so do not remove
                    continue;
                int result = NxCore.RemovePermission(perm);
                if (result != 0)
                {//non-zero result indicates failure
                    if (result == -1)
                        Console.WriteLine("Function was called from thread other than callback thread");
                    if (result == -2)
                        Console.WriteLine("Permission ID value was invalid");
                    return;// could not remove permission during this status message. Try again next status message.
                }
            }
            //successfully removed all permissions
            removed = true;
        }
    }
    unsafe int OnNxCoreCallback(NxCoreSystem* pNxCoreSys, NxCoreMessage* pNxCoreMsg)
    {
        switch (pNxCoreMsg->MessageType)
        {
            case NxCore.NxMSG_STATUS:
                onNxCoreStatus(pNxCoreSys, pNxCoreMsg);
                break;
        }
        return NxCore.NxCALLBACKRETURN_CONTINUE;
    }
}

class RemovePermissionSample
{
    static void Main(string[] args)
    {
        if (args.Length < 1)
            return;

        Thread[] threads = {
            new Thread((new NxCoreThread(args.Length > 0 ? args[0] : "", 0,new int[]{13,14,17,18,90,91})).run),//NYSEQTE,AMEXQTE,NYSETRD,AMEXTRD,NYSECORP,AMEXCORP
            new Thread((new NxCoreThread(args.Length > 0 ? args[0] : "", 1,new int[]{6,9})).run)//NASDQTE,NASDTRD
        };
        foreach (var thread in threads)
            thread.Start();
        foreach (var thread in threads)
            thread.Join();
    }
}
#ifdef _WIN32
#include "windows.h"
#else
#include "pthread.h"
#endif

#include "NxCoreAPI_Wrapper_C.h"

struct ThreadData {
    int threadNum;
    int* pPermissions;
    int nPermissions;
    bool removed;
};

#define MAXID 128
#ifdef _WIN32
__declspec(thread)struct ThreadData* pMyThreadData;
#else
_Thread_local struct ThreadData* pMyThreadData;
#endif

char* pszTapepath;

void onNxCoreStatus(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMsg) {
    //Print time
    if (pNxCoreSys->ClockUpdateInterval >= NxCLOCK_MINUTE && pNxCoreSys->nxTime.Hour < 24) {
        printf("Thread: %d NxCoreTime: %02d:%02d:%02d\n",
        pMyThreadData->threadNum,
        (int)pNxCoreSys->nxTime.Hour,
        (int)pNxCoreSys->nxTime.Minute,
        (int)pNxCoreSys->nxTime.Second);
    }

    //Log Errors. Errors NxCA_EXCEPTION_OPTSYMBOL(10) and NxCA_EXCEPTION_SYMBOL(11) indicate 
    //a permission was removed that shouldn't be. See Proper Use section for more details.
    if (pNxCoreSys->Status == NxCORESTATUS_ERROR)
        printf("Tape Error: %d on thread /n",pNxCoreSys->StatusData,pMyThreadData->threadNum);

    //Remove unwanted permissions
    if (!pMyThreadData->removed) {
        for (int perm = 1; perm < MAXID; ++perm) {
            bool bPermissionAssigned = false;
            for (int iPerm = 0; iPerm < pMyThreadData->nPermissions; iPerm++)// this permission should be processed on this thread, so do not remove
                if(pMyThreadData->pPermissions[iPerm] == perm){
                    bPermissionAssigned = true;
                    break;
                }
            int result = RemovePermission(perm);
            if (result != 0) {//non-zero result indicates failure
                if (result == -1)
                    printf("Function was called from thread other than callback thread");
                if (result == -2)
                    printf("Permission ID value was invalid");
                return;// could not remove permission during this status message. Try again next status message.
            }
        }
        //successfully removed all permissions
        pMyThreadData->removed = true;
    }
}
int OnNxCoreCallback(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMsg) {
    switch (pNxCoreMsg->MessageType) {
    case NxMSG_STATUS:
        onNxCoreStatus(pNxCoreSys, pNxCoreMsg);
            break;
    }
    return NxCALLBACKRETURN_CONTINUE;
}
void thProcess(struct ThreadData* pThreadData) {
    pMyThreadData = pThreadData;
    int returnValue = pfNxCoreProcessTape(pszTapepath, NULL, NxCF_EXCLUDE_CRC_CHECK, 0, OnNxCoreCallback);
    processReturnValue(returnValue);
}
int main(int argc, char* argv[])
{
    if (LoadNxCore("NxCoreAPI64.dll")) {
        pszTapepath = argc > 1 ? argv[1] : "";
        struct ThreadData* pThreadData[2];

        pThreadData[0] = (struct ThreadData*) malloc(sizeof(struct ThreadData));
        pThreadData[0]->threadNum = 0;
        pThreadData[0]->removed = false;
        pThreadData[0]->nPermissions = 6;
        pThreadData[0]->pPermissions = (int*) malloc(sizeof(int) * pThreadData[0]->nPermissions);
        pThreadData[0]->pPermissions[0] = 13;//NYSEQTE
        pThreadData[0]->pPermissions[1] = 14;//AMEXQTE
        pThreadData[0]->pPermissions[2] = 17;//NYSETRD
        pThreadData[0]->pPermissions[3] = 18;//AMEXTRD
        pThreadData[0]->pPermissions[4] = 90;//NYSECORP
        pThreadData[0]->pPermissions[5] = 91;//AMEXCORP

        pThreadData[1] = (struct ThreadData*) malloc(sizeof(struct ThreadData));
        pThreadData[1]->threadNum = 1;
        pThreadData[1]->removed = false;
        pThreadData[1]->nPermissions = 2;
        pThreadData[1]->pPermissions = (int*) malloc(sizeof(int) * pThreadData[1]->nPermissions);
        pThreadData[1]->pPermissions[0] = 6;//NASDQTE
        pThreadData[1]->pPermissions[1] = 9;//NASDTRD

#ifdef _WIN32
        HANDLE threads[2];
        threads[0] = CreateThread(NULL, 0, thProcess, pThreadData[0], 0, 0);
        threads[1] = CreateThread(NULL, 0, thProcess, pThreadData[1], 0, 0);

        WaitForMultipleObjects(2, threads, TRUE, INFINITE);

        for (int i = 0; i < 2; i++)
            CloseHandle(threads[i]);
#else
        pthread_t threads[2];
        pthread_create(&threads[0],0,thProcess,pThreadData[0]);
        pthread_create(&threads[1],0,thProcess,pThreadData[1]);

        for (int i = 0; i<2; i++)
            pthread_join(threads[i],NULL);
#endif
        free(pThreadData[0]);
        free(pThreadData[1]);
    }
    else {
        printf("loading library failed");
    }
    return 0;
}