SBE Java Sample Application
July 21, 2026 ยท View on GitHub
This sample application is designed to decode exchangeInfo endpoint's response to YAML, when using the Binance Spot API Simple Binary Encoding (SBE).
Moreover, there are additional decoder classes that can be useful for decoding SBE responses from other endpoints in the Binance Spot API.
Getting Started
- Clone the source code to your local end.
git clone git@github.com:binance/binance-sbe-java-sample-app
- Navigate to the directory where
pom.xmlfile is located and build the project withMavento generate./target/sbe-sample-app-1.0-SNAPSHOT.jar.
mvn clean install
Usage
The following commands use ./target/sbe-sample-app-1.0-SNAPSHOT.jar to output on STDOUT the exchangeInfo SBE response in YAML.
Via reading SBE-encoded HTTP response from STDIN
curl -X GET -H 'Accept: application/sbe' -H 'X-MBX-SBE: 3:4' 'https://api.binance.com/api/v3/exchangeInfo' | java -jar ./target/sbe-sample-app-1.0-SNAPSHOT.jar -
Via reading SBE-encoded WebSocket response from STDIN
echo '{"id":"93fb61ef-89f8-4d6e-b022-4f035a3fadad","method":"exchangeInfo","params":{}}' | ../../tools/websocket_send.py 'wss://ws-api.binance.com:443/ws-api/v3?responseFormat=sbe&sbeSchemaId=3&sbeSchemaVersion=4' | java -jar ./target/sbe-sample-app-1.0-SNAPSHOT.jar -
Note: To run websocket_send.py, your Python 3 environment should include the websocket-client package with the integrated create_connection function.
Via downloading SBE-encoded HTTP response within the app
java -jar ./target/sbe-sample-app-1.0-SNAPSHOT.jar 'https://api.binance.com/api/v3/exchangeInfo'
The spot_sbe directory contains the decoder classes, which you can consult to explore other endpoints.
Testnet
To use the Spot Testnet API, you only need to replace:
api.binance.comwithtestnet.binance.visionfor the REST APIws-api.binance.comwithtestnet.binance.visionfor the WebSocket API
Update
Java decoders
The src/main/java/spot_sbe directory contains code generated by simple-binary-encoding, which you will likely want to reuse verbatim. However, if you would like to update it, please navigate to the root of this project and follow these steps:
- Download the spot_prod_latest.xml schema file to
src/main/resources:
mkdir -p src/main/resources
cd src/main/resources
curl -o spot_latest.xml https://raw.githubusercontent.com/binance/binance-spot-api-docs/master/sbe/schemas/$(curl -s https://raw.githubusercontent.com/binance/binance-spot-api-docs/master/sbe/schemas/spot_prod_latest.xml)
cd -
Note: If you are using the Spot Testnet API, replace spot_prod_latest.xml with spot_testnet_latest.xml in the above curl command.
- Clone & build simple-binary-encoding:
git clone https://github.com/real-logic/simple-binary-encoding.git --branch '1.35.6'
cd simple-binary-encoding
./gradlew
cd ..
- Run the SBE tool code generator built in the previous step:
java \
-Dsbe.output.dir=src/main/java/ \
-Dsbe.target.language=Java \
-jar simple-binary-encoding/sbe-all/build/libs/sbe-all-1.35.6.jar \
src/main/resources/spot_latest.xml
- Remove unneeded encoder files:
find src/main/java/spot_sbe -type f -name '*Encoder.java' -exec rm '{}' \;