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 NxCore def OnNxCoreCallback(NxCoreSys, NxCoreMsg): if NxCoreMsg.MessageType == NxCore.NxMSG_TRADE: header = NxCoreMsg.coreHeader symbol = header.pnxStringSymbol.String ts = header.nxExgTimestamp exchange = NxCore.GetDefinedString(NxCore.NxST_EXCHANGE, header.ReportingExg).split('|')[0] trade = NxCoreMsg.coreData.Trade price = NxCore.PriceToFloat(trade.Price,trade.PriceType) size = trade.Size sequence = trade.ExgSequence conditions = "" for condition in trade.ExtTradeConditions: conditions += str(NxCore.GetDefinedString(NxCore.NxST_TRADECONDITION, condition)) + "|" eligibility = "" if trade.ConditionFlags: eligibility += "(Doesn't set" if trade.ConditionFlags & NxCore.NxTCF_NOHIGH: eligibility += " high " if trade.ConditionFlags & NxCore.NxTCF_NOLOW: eligibility += " low" if trade.ConditionFlags & NxCore.NxTCF_NOLAST: eligibility += " last" eligibility += ")" if trade.PriceFlags & NxCore.NxTPF_EXGCANCEL: print("Cancel for {} at sequence {} on {} for {} shares at ${:.2f}" .format( symbol, sequence, exchange, size, price)) else: print("Trade for {} at {:02d}:{:02d}:{:02d} sequence {} on {} for {} shares at ${:.2f} conditions : {}{} " .format(symbol, ts.Hour, ts.Minute, ts.Second, sequence, exchange, size, price, conditions, eligibility)) return NxCore.NxCALLBACKRETURN_CONTINUE
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. |
exchange = NxCore.GetDefinedString( NxCore.NxST_EXCHANGE, header.ReportingExg).split('|')[0] trade = NxCoreMsg.coreData.Trade price = NxCore.PriceToFloat(trade.Price,trade.PriceType) size = trade.Size 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 None if there is no valid condition, so using str is necessary to ensure the result is always a string. |
conditions = "" for condition in trade.ExtTradeConditions: conditions += str(NxCore.GetDefinedString( NxCore.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. |
eligibility = "" if trade.ConditionFlags: eligibility += "(Doesn't set" if trade.ConditionFlags & NxCore.NxTCF_NOHIGH: eligibility += " high" if trade.ConditionFlags & NxCore.NxTCF_NOLOW: eligibility += " low" if trade.ConditionFlags & NxCore.NxTCF_NOLAST: 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 & NxCore.NxTPF_EXGCANCEL: ... |
Next:
Quote