Process for creating price subscriptions
To create a price subscription and start receiving updates, you:
Warning : TT strongly recommends users maintain their price subscriptions. To prevent issues, users must avoid unsubscribing and immediately resubscribing to market updates.
Subscribing for market data
Typically, you start a price subscription for an Instrument when TT .NET SDK fires the Update event for the InstrumentLookup object you created to find the Instrument.
The following snippet modifies the OnData event handler to start a price subscription for market depth data.
Creating the subscription event handler
After the subscription starts, TT .NET SDK retrieves all of the market data for the Instrument and invokes the event handler method you registered with the subscription. TT .NET SDK fires the FieldsUpdated event with the FieldsUpdatedEventArgs.UpdateType property set to UpdateType.Snapshot for the initial market data snapshot. You can use the PriceSubscriptionFields.GetFieldIds method to process all of market data. Subsequently, when any of the market data fields change, TT .NET SDK sets the FieldsUpdatedEventArgs.UpdateType property to UpdateType.Incremental to indicate that only some of the market data changed. In this case, you can use the PriceSubscriptionFields.GetChangedFieldIds method to retrieve the ids of only the fields whose values changed.
The following code snippet shows the structure of a sample price subscription event handler method.
FieldId is an enumerated type defining the set of valid market data fields, such as DirectBidPrice, DirectBidQuantity, etc. When used as an index to extract market data fields from the Fields property of the FieldsUpdatedEventArgs object, it returns a Field object.
To extract the actual value, you can call the FormattedValue property of the tt_net_sdk.Field object, for example:
You can also use the FormattedValue property of the tt_net_sdk.Field object object to reference to the Object storing the value. You can then cast it to its real type. For example:
Alternatively, you can access specific tt_net_sdk.Field values directly without needing to cast the return value, as follows: