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.
- Clone the source code to your local end.
git clone [email protected]:binance/binance-sbe-java-sample-app
- Navigate to the directory where
pom.xml
file is located and build the project withMaven
to generate./target/sbe-sample-app-1.0-SNAPSHOT.jar
.
mvn clean install
The following commands use ./target/sbe-sample-app-1.0-SNAPSHOT.jar
to output on STDOUT the exchangeInfo
SBE response in YAML.
curl -X GET -H 'Accept: application/sbe' -H 'X-MBX-SBE: 1:0' 'https://api.binance.com/api/v3/exchangeInfo' | java -jar ./target/sbe-sample-app-1.0-SNAPSHOT.jar -
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=1&sbeSchemaVersion=0' | 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.
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.
To use the Spot Testnet API, you only need to replace:
api.binance.com
withtestnet.binance.vision
for the REST APIws-api.binance.com
withtestnet.binance.vision
for the WebSocket API
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.30.0'
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.30.0.jar \
src/main/resources/spot_latest.xml
- Remove unneeded encoder files:
find src/main/java/spot_sbe -type f -name '*Encoder.java' -exec rm '{}' \;