Following on from Why I love Apache Velocity where we discussed the use of meta-programming, code that writes code...
Github has some repositories from the FIX Trading Community - one of them includes an example of three FIX messages:
- BusinessMessageReject
- ExecutionReport
- NewOrderSingle
All three expressed in XML for use with Simple Binary Encoding. Not included within the FIX GitHub repository is a way to render that XML into something useful, such as a NewOrderSingle.java class definition file. In this implementation Apache Velocity takes three inputs:
As the Apache Velocity website states:
At AlignmentSystems/CodeGen you can find a Java project that uses the XML and XSD files from the FIX Trading Community to naively create three Java class definition files. The use of the word naive is accurate, in the sense that if you download the code and run it** you see that the datatypes from SBE are not accurately mapped to sensible options to create the correct bytes. This is a demonstration of proof-of-concept, rather than production ready.
In future posts this will be extended and enhanced to show a polyglot approach - to create binary messages and the kdb+/Shakti database tables to store that binary data.
Why is this useful?
This CodeGen project was built for MQTT. The MQTT implementation is proprietary, but this SBE implementation is free and open-source software. The underlying concepts and design patterns are entirely relevant for any Electronic Trading project - whether using old fashioned FIXT session layer and tag=value or a FIXP-SBE-SOFH paradigm.
As an example:
public ${className}($foo){
#if( $foreach.hasNext )
this.$property.fieldName$space$equals$space$property.getFieldNameLowercaseFirstLetter()$space$comma
#else
this.$property.fieldName$space$equals$space$property.getFieldNameLowercaseFirstLetter()
#end
#end
}
Is the code from the class.vm that creates the constructor:
public NewOrderSingle(String clOrdId , String account , String symbol , sideEnum side , timestampEncoding transactTime , qtyEncoding orderQty , ordTypeEnum ordType , optionalDecimalEncoding price , optionalDecimalEncoding stopPx){
The entire set of class definition files are available on GitHub
Along with all of the source code.
**
It's a Gradle project using Java 10
All dependencies are packaged into a "FatJar" and can be downloaded by Gradle from mavenCentral.
Dependencies are logback, Apache Velocity and sl4j
There's a batch file to run called MQTT_ClassGen_Start.bat
See also:
Comments
Post a Comment