Basic: | Intro/Trade | Quote | Category | Status | Symbol | Options |
Detailed: | Trade | Quote |
Introduction to Quotes
Quotes discussed on this page are considered level 1 quotes or exchange quotes. The best exchange quotes form the NBBO quote which will be covered in the advanced quote guide.
Code
import NxCore def OnNxCoreCallback(NxCoreSys, NxCoreMsg): if NxCoreMsg.MessageType == NxCore.NxMSG_EXGQUOTE: header = NxCoreMsg.coreHeader symbol = header.pnxStringSymbol.String timestamp = header.nxExgTimestamp exchange = NxCore.GetDefinedString(NxCore.NxST_EXCHANGE, header.ReportingExg) core_quote = NxCoreMsg.coreData.ExgQuote.coreQuote size_bid = core_quote.BidSize size_ask = core_quote.AskSize price_bid = NxCore.PriceToFloat(core_quote.BidPrice, core_quote.PriceType) price_ask = NxCore.PriceToFloat(core_quote.AskPrice, core_quote.PriceType) print("Quote for {} on Exchange {} at {:02d}:{:02d}:{:02d} Bid: {} lots at ${:.2f} Ask: {} lots at ${:.2f} " \ .format(symbol, exchange, timestamp.Hour, timestamp.Minute, timestamp.Second, size_bid, price_bid, size_ask, price_ask)) return NxCore.NxCALLBACKRETURN_CONTINUE if NxCore.LoadNxCore("NxCoreAPI64.dll"): returnValue = NxCore.ProcessTape("demo.XU.nx2", 0, 0, 0, OnNxCoreCallback) NxCore.ProcessReturnValue(returnValue) else: print("loading library failed")
Callback Function
Since we only want to process quotes we check that MessageType equals NxCore.NxMSG_EXGQUOTE. |
def OnNxCoreCallback(NxCoreSys, NxCoreMsg): if NxCoreMsg.MessageType == NxCore.NxMSG_EXGQUOTE: ... return NxCore.NxCALLBACKRETURN_CONTINUE |
Message Header
In addition to symbol and timestamp, the coreHeader also contains the exchange that sent the message. The exchange is sent as a number corresponding to NxST_EXCHANGE. The name of the exchange can be found using GetDefinedString. |
header = NxCoreMsg.coreHeader symbol = header.pnxStringSymbol.String timestamp = header.nxExgTimestamp exchange = NxCore.GetDefinedString( NxCore.NxST_EXCHANGE, header.ReportingExg) |
Quote Message
The ExgQuote object in the coreData object in NxCoreMessage contains details of the quote when MessageType is NxCore.NxMSG_EXGQUOTE. For this simple example we will just use the contents of the coreQuote object. The other parts of the ExgQuote object will be covered in the advanced quote guide. Note quote sizes sent by most feeds are the number of lots, not the number of shares. Lots are usually 100 shares. |
core_quote = NxCoreMsg.coreData.ExgQuote.coreQuote size_bid = core_quote.BidSize size_ask = core_quote.AskSize price_bid = NxCore.PriceToFloat( core_quote.BidPrice, core_quote.PriceType) price_ask = NxCore.PriceToFloat( core_quote.AskPrice, core_quote.PriceType) |
Next:
Category
Detailed Quote