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
import net.nanex.NxCoreClass; class DetailedTradeSample extends NxCoreClass{ @Override public int OnNxCoreCallback(NxCoreSystem nxCoreSys, NxCoreMessage nxCoreMsg) { if (nxCoreMsg.MessageType == defines.NxMSG_TRADE) { NxCoreHeader header = nxCoreMsg.coreHeader; String symbol = header.pnxStringSymbol.String; NxTime timestamp = header.nxExgTimestamp; String exchange = GetDefinedString(defines.NxST_EXCHANGE, header.ReportingExg).split("\\|")[0]; NxCoreTrade trade = nxCoreMsg.coreData.Trade; double price = PriceToDouble(trade.Price,trade.PriceType); int size = trade.Size; long sequence = trade.ExgSequence; String conditions = ""; for (int condition : trade.ExtTradeConditions) conditions += GetDefinedString(defines.NxST_TRADECONDITION, condition) + "|"; String eligibility = ""; if ((trade.ConditionFlags) !=0 ) { eligibility += "(Doesn't set"; if ((trade.ConditionFlags & defines.NxTCF_NOHIGH) !=0 ) eligibility += " high"; if ((trade.ConditionFlags & defines.NxTCF_NOLOW) !=0 ) eligibility += " low"; if ((trade.ConditionFlags & defines.NxTCF_NOLAST) !=0 ) eligibility += " last"; eligibility += ")"; } if((trade.PriceFlags & defines.NxTPF_EXGCANCEL) !=0 ) System.out.println("Cancel for " + symbol + " at " + " sequence " + sequence + " on " + exchange + " for " + size + " shares at $" + String.format("%.2f", price)); else System.out.println("Trade for " + symbol + " at " + String.format("%02d:%02d:%02d", timestamp.Hour, timestamp.Minute, timestamp.Second) + " sequence " + sequence + " on " + exchange + " for " + size + " shares at $" + String.format("%.2f", price) + " conditions: " + conditions + eligibility); } return defines.NxCALLBACKRETURN_CONTINUE; } public static void main(String args[]) { TradeSample nxCore = new TradeSample(); if (args.length > 1 && nxCore.LoadNxCore(args[0]) != 0){ int returnValue = nxCore.ProcessTape(args[1], 0, 0, 0); nxCore.ProcessReturnValue(returnValue); } else System.out.println("loading library failed"); } }
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 = GetDefinedString( defines.NxST_EXCHANGE, header.ReportingExg).split("\\|")[0]; NxCoreTrade trade = nxCoreMsg.coreData.Trade; double price = PriceToDouble( trade.Price,trade.PriceType); int size = trade.Size; long sequence = trade.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 an empty string if there is no valid condition |
String conditions = ""; for (int condition : trade.ExtTradeConditions) conditions += GetDefinedString( defines.NxST_TRADECONDITION, condition) + "|"; |
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 ((trade.ConditionFlags) !=0 ) { eligibility += "(Doesn't set"; if ((trade.ConditionFlags & defines.NxTCF_NOHIGH) !=0 ) eligibility += " high"; if ((trade.ConditionFlags & defines.NxTCF_NOLOW) !=0 ) eligibility += " low"; if ((trade.ConditionFlags & defines.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((trade.PriceFlags & defines.NxTPF_EXGCANCEL) !=0 ) ... |
Next:
Quote