This event is fired when any of the instrument quotes or dynamic instrument properties are changed.
Visual Basic |
---|
Public Event InstrumentChanged( _ ByVal cqg_instrument As CQGInstrument, _ ByVal cqg_quotes As CQGQuotes, _ ByVal cqg_instrument_properties As CQGInstrumentProperties _ ) |
- cqg_instrument
Name of updated instrument.
- cqg_quotes
Collection of changed quotes.
The contents of cqg_quotes depends on how the CQGAPIConfig.NewInstrumentChangeMode property is set, as the following:
- If CQGAPIConfig.NewInstrumentChangeMode is set to True:
cqg_quotes contains prior values and current values must be obtained from CQGInstrument.Quotes; or explicitly using CQGInstrument.Trade, CQGInstrument.Bid, and CQGInstrument.Ask properties.
However, cqg_quotes must be used to determine, which values have changed. - If CQGAPIConfig.NewInstrumentChangeMode is set to False:
cqg_quotes contains the current values.
- If CQGAPIConfig.NewInstrumentChangeMode is set to True:
- cqg_instrument_properties
Collection of changed dynamic properties.
This event will not be fired if the data subscription level of the instrument is set to dsNone. All other data subscription level settings control the information that will be sent via the InstrumentChanged event.
If the data subscription level is set to dsQuotes, trades information and dynamic properties about trades will be delivered to the user. Updates of asks or bids will not be available.
To receive ask/bid updates, set the subscription level to dsQuotesAndBBA.
In order to receive DOM data updates set subscription level to dsQuotesAndDOM
In versions earlier than v. 3.0, the Quotes and props parameters contained collections with new values of the changed quotes/properties. Starting from CQG API v.3.0 the content can be configured to contain the old values of the changed quotes/properties. See NewInstrumentChangeMode for details.
This example demonstrates how to handle the InstrumentChanged event and how to use CQGInstrumentProperties and CQGQuotes collection objects.
See the implementation of CQGCEL events handling in the AccountChanged event's example section.
Private Sub cel_InstrumentChanged(ByVal Instrument As CQG.ICQGInstrument, _ ByVal Quotes As CQG.ICQGQuotes, _ ByVal Props As CQG.ICQGInstrumentProperties) Dim cellName As String Dim cellRow As Integer Dim currentQuote As CQGQuote ' Processing updated quotes. For Each currentQuote In Quotes cellRow = GetQuoteRowByType(currentQuote.Type) ' Fill updated quote name into some Excel cell. cellName = "C" & CStr(cellRow) Range(cellName) = currentQuote.Name ' Fill updated quote price data into some Excel cell. cellName = "D" & CStr(cellRow) Range(cellName) = IIf(currentQuote.IsValid, currentQuote.Price, "Unavailable") ' Fill updated quote volume data into some Excel cell. cellName = "E" & CStr(cellRow) Range(cellName) = IIf(currentQuote.IsValid, currentQuote.Volume, "Unavailable") Next Dim currentInstrumentProp As CQGInstrumentProperty ' Processing updated properties. For Each currentInstrumentProp In Props cellRow = GetInstrumentPropertyRowByType(currentInstrumentProp.Type) ' Fill updated instrument property name into some Excel cell. cellName = "G" & CStr(cellRow) Range(cellName) = currentInstrumentProp.Name ' Fill updated quote price data into some Excel cell. cellName = "H" & CStr(cellRow) Range(cellName) = currentInstrumentProp.Value Next End Sub Private Function GetQuoteRowByType(Qt As eQuoteType) As Integer Dim quoteRowIndex As Integer quoteRowIndex = CInt(Qt) + 1 GetQuoteRowByType = quoteRowIndex End Function Private Function GetInstrumentPropertyRowByType(It As eInstrumentProperty) As Integer Dim instrumentPropertyRowIndex As Integer instrumentPropertyRowIndex = CInt(It) + 1 GetInstrumentPropertyRowByType = instrumentPropertyRowIndex End Function
private void m_cel_InstrumentChanged(CQGInstrument Instrument, CQGQuotes Quotes, CQGInstrumentProperties Props) { // Processing updated quotes. foreach( CQGQuote currentQuote in Quotes ) { // Write updated quote name to console. Console.WriteLine( currentQuote.Name + " : " ) ; // Write updated quote price data to console. Console.WriteLine( ( currentQuote.IsValid ) ? currentQuote.Price.ToString() : "Unavailable") ; // Write updated quote volume data to console. Console.WriteLine( ( currentQuote.IsValid ) ? currentQuote.Volume.ToString() : "Unavailable" ) ; } // Processing updated properties. foreach( CQGInstrumentProperty currentInstrumentProp in Props ) { // Write updated instrument property name into to console. Console.WriteLine( currentInstrumentProp.Name ) ; // Write updated quote price data to console. Console.WriteLine( currentInstrumentProp.Value.ToString() ) ; } }