API Documentation

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

Detailed Trades

This guide assumes you have already read the "Getting Started and Introduction to Trades" guide. This guide will cover more detailed processing of trade messages.

Code

using System;
using NxCoreAPI;

class DetailedTradeSample {
    static unsafe int OnNxCoreCallback(NxCoreSystem* pNxCoreSys, NxCoreMessage* pNxCoreMsg) {
        if (pNxCoreMsg->MessageType == NxCore.NxMSG_TRADE) {
            NxCoreHeader* pHeader = &pNxCoreMsg->coreHeader;
            String symbol = new String(&pHeader->pnxStringSymbol->String);
            NxTime* pTimestamp = &pHeader->nxExgTimestamp;
            String exchange = new String(NxCore.GetDefinedString(NxCore.NxST_EXCHANGE, pHeader->ReportingExg)).Split('|')[0];

            NxCoreTrade* pTrade = &pNxCoreMsg->coreData.Trade;
            double price = NxCore.PriceToDouble(pTrade->Price, pTrade->PriceType);
            uint size = pTrade->Size;
            uint sequence = pTrade->ExgSequence;

            String conditions = "";
            for (int i = 0; i < 4; i++) {
                byte condition = pTrade->ExtTradeConditions[i];
                String conditionName = new String(NxCore.GetDefinedString(NxCore.NxST_TRADECONDITION, condition));
                conditions += conditionName + "|";
            }

            String eligibility = "";
            if (pTrade->ConditionFlags != 0) {
                eligibility += "(Doesn't set";
                if ((pTrade->ConditionFlags & NxCore.NxTCF_NOHIGH) != 0)
                    eligibility += " high";
                if ((pTrade->ConditionFlags & NxCore.NxTCF_NOLOW) != 0)
                    eligibility += " low";
                if ((pTrade->ConditionFlags & NxCore.NxTCF_NOLAST) != 0)
                    eligibility += " last";
                eligibility += ")";
            }
            if ((pTrade->PriceFlags & NxCore.NxTPF_EXGCANCEL) != 0)
                Console.WriteLine("Cancel for {0:s} at sequence {1:d} on {2:s} {3:d} shares at ${4:f2}",
                    symbol, sequence, exchange, size, price);
            else
                Console.WriteLine("Trade for {0:s} at {1:d2}:{2:d2}:{3:d2}" +
                    "sequence {4:d} on {5:s} for {6:d} shares at ${7:f2} {8:s}{9:s}",
                    symbol, pTimestamp->Hour, pTimestamp->Minute, pTimestamp->Second,
                    sequence, exchange, size, price, conditions, eligibility);
          }
        return NxCore.NxCALLBACKRETURN_CONTINUE;
    }

    static unsafe void Main(string[] args) {
        if (args.Length < 1)
            return;
        int returnValue = NxCore.ProcessTape(args[0], null, 0, 0, DetailedTradeSample.OnNxCoreCallback);
        NxCore.processReturnValue(returnValue);
    }
}

Trade Message

Trades are identified by combination of sequence and reporting exchange. This can be used in conjunction with cancels to determine which trade was canceled. Note that some feeds use non-sequential 64-bit sequences which may cause sequence number to not be unique. GetDefinedString returns the both a short and full name of the exchange split by a pipe. We get the short exchange name by taking the part of the string before the pipe.

String exchange = new String(NxCore.GetDefinedString(
    NxCore.NxST_EXCHANGE, pHeader->ReportingExg)).Split('|')[0];

NxCoreTrade* pTrade = &pNxCoreMsg->coreData.Trade;
double price = NxCore.PriceToDouble(pTrade->Price, pTrade->PriceType);
uint size = pTrade->Size;
uint sequence = pTrade->ExgSequence;

Trade Conditions

The type of trade is indicated by up to 4 conditions. The full list of possible trade conditions can be found in the Trade Condition Table. For example, trades with less than 100 shares will have the OddLot(115) condition. GetDefinedString can be used to find the string name of the condition using NxST_TRADECONDITION as ixTable. GetDefinedString returns null if there is no valid condition.

String conditions = "";
for (int i = 0; i < 4; i++) {
    byte condition = pTrade->ExtTradeConditions[i];
    String conditionName = new String(NxCore.GetDefinedString(
	NxCore.NxST_TRADECONDITION, condition));
    conditions += conditionName + "|";
}

Trade Eligiblity

Not all trades are permitted to set the daily high, low, and last. Whether or not a trade can set daily prices is determined by the aforementioned trade conditions. ConditionFlags is a bitmap of which daily prices the trade can not set. A value of zero means the trade can set all Daily prices.

String eligibility = "";
if (pTrade->ConditionFlags != 0) {
    eligibility += "(Doesn't set";
    if ((pTrade->ConditionFlags & NxCore.NxTCF_NOHIGH) != 0)
        eligibility += " high";
    if ((pTrade->ConditionFlags & NxCore.NxTCF_NOLOW) != 0)
        eligibility += " low";
    if ((pTrade->ConditionFlags & NxCore.NxTCF_NOLAST) != 0)
        eligibility += " last";
    eligibility += ")";
}

Cancels

Sometimes past trades are canceled or modified. In this case, PriceFlags will have the NxTPF_EXGCANCEL(0x20) bit set. When avaiable the sequence and reporting exchange will match the trade being canceled.

if ((pTrade->PriceFlags & NxCore.NxTPF_EXGCANCEL) != 0)
    ...

Next:
Quote