Schemas¶
You will learn how to use Roq’s schemas to auto-generate language specific code useful for communicating with Roq’s gateway bridges.
Conda¶
Install the “roq-schema” package
$ conda install -y -c https://roq-trading.com/conda/unstable roq-schema
You can now find protocol specific schemas in the $CONDA_PREFIX/share/roq/schema directory.
In particular
flatbuffers →
$CONDA_PREFIX/share/roq/schema/flatbuffers/api.fbsprotobuf →
$CONDA_PREFIX/share/roq/schema/protobuf/api.protosbe →
$CONDA_PREFIX/share/roq/schema/protobuf/api.xml
GitHub¶
You can also fetch the schemas directly from GitHub.
Flatbuffers¶
Install the flatbuffers compiler
$ conda install -y flatbuffers
We can now auto-generate bindings
$ flatc --python \
-o . \
$CONDA_PREFIX/share/roq/schema/flatbuffers/api.fbs
Note
Files are written relative to current directory due to -o ..
We can verify the files are indeed written
$ find . -name "*.py"
./roq/schema/flatbuffers/UpdateAction.py
./roq/schema/flatbuffers/Quote.py
...
./roq/schema/flatbuffers/StatisticsType.py
./roq/schema/flatbuffers/QuantityType.py
./roq/schema/__init__.py
./roq/__init__.py
Protobuf¶
Install the protobuf compiler
$ conda install -y libprotobuf
We can now auto-generate bindings
$ protoc --python_out=. \
--proto_path $CONDA_PREFIX/share/roq/schema/protobuf \
api.proto
Note
Files are written relative to current directory due to --python_out=..
There is a single output file
$ find . -name "*.py"
./api_pb2.py
SBE¶
You can install the “roq-oss-simple-binary-encoding” packaged by Roq
$ conda install -y -c https://roq-trading.com/conda/unstable roq-oss-simple-binary-encoding
Note
This package distributes the “sbe-all.jar” from GitHub.
You can find the “jar” file here
$ ls -1 $CONDA_PREFIX/share/java/
sbe-all-1.40.1.jar
sbe-all.jar
We also need a Java runtime, e.g.
$ conda install -y openjdk
Checking
$ which java
/home/thraneh/tmp/opt/conda/envs/hans/bin/java
We can now generate the SBE bindings
$ java -Dsbe.target.language=java \
-Dsbe.output.dir=. \
-jar $CONDA_PREFIX/share/java/sbe-all.jar \
$CONDA_PREFIX/share/roq/schema/sbe/api.xml
Note
We demonstrate auto-generated Java code because SBE has no generator for Python.
Note
Files are written relative to current directory due to -Dsbe.output.dir=..
Checking
$ find . -name "*.java"
./com/roq-trading/TradeSummaryEncoder.java
./com/roq-trading/ControlDecoder.java
...
./com/roq-trading/OrderCancelPolicy.java
./com/roq-trading/State.java
Summary¶
We have demonstrated how to
Fetch Roq’s schemas as a conda package (and we have pointed to the source on GitHub).
Download protocol specific generators (flatbuffers, protobuf and simple-binary-encoding).
Auto-generate language-specific binding code.
With this you are able to write language-specific code to communicate with Roq’s gateway bridges.
In the next blog post we will demonstrate how to use the auto-generated language bindings to communicate with a Roq gateway bridge.