Skip to content

Sample app in Java that decodes Binance "exchangeInfo" endpoint's SBE response to YAML.

License

Notifications You must be signed in to change notification settings

binance/binance-sbe-java-sample-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SBE Java Sample Application

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

  1. Clone the source code to your local end.
git clone [email protected]:binance/binance-sbe-java-sample-app
  1. Navigate to the directory where pom.xml file is located and build the project with Maven to 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: 1:0' '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=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.

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.com with testnet.binance.vision for the REST API
  • ws-api.binance.com with testnet.binance.vision for 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:

  1. 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.

  1. 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 ..
  1. 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
  1. Remove unneeded encoder files:
find src/main/java/spot_sbe -type f -name '*Encoder.java' -exec rm '{}' \;

About

Sample app in Java that decodes Binance "exchangeInfo" endpoint's SBE response to YAML.

Topics

Resources

License

Stars

Watchers

Forks

Languages