Security Definitions Cache | Table of Content | Replaying Log Files |
Strongly Typed Messages |
By default SBE messages and repeating groups can be accessed in Handler callbacks via IFieldSet interface. But there is a tool which allows to use pre-generated strongly typed messages.
IFieldSet style code:
int securityId = securityDefinition.DefinitionMessage.GetInteger(Tags.SecurityID); string symbol = securityDefinition.DefinitionMessage.GetString(Tags.Symbol); int contractMultiplier = securityDefinition.DefinitionMessage.GetInteger(Tags.ContractMultiplier);
Strongly typed messages code:
if (securityDefinition.DefinitionMessage.TemplateID == 27) { MDInstrumentDefinitionFuture27 definition = (MDInstrumentDefinitionFuture27)securityDefinition.DefinitionMessage; int securityId = definition.SecurityID; string symbol = definition.Symbol; int contractMultiplier = definition.ContractMultiplier; }
Note |
---|
Please note, that strongly typed messages assembly should be generated each time, when templates file will be changed. Also code, which depends on this assembly, should be rebuilded. |
There're are several steps which should be completed to use strongly typed messages:
Generate strongly typed messages assembly with tool, which is placed under tools\sbe-decoder-generator folder of the installation package:
OnixS.SimpleBinaryEncoding.DecoderGenerator.exePlease do not forget to place actual templates file to the folder, where this tool is located.
Add a reference to the generated OnixS.SimpleBinaryEncoding.Cme.dll to your project.
Set the Handler to load generated library:
handler.LoadDecoderLibrary = true;
Use template id to cast IMessage to the required message type:
if (securityDefinition.DefinitionMessage.TemplateID == 27) { MDInstrumentDefinitionFuture27 definition = (MDInstrumentDefinitionFuture27)securityDefinition.DefinitionMessage; }
Use properties of the strongly typed message:
int securityId = definition.SecurityID; string symbol = definition.Symbol; int contractMultiplier = definition.ContractMultiplier;