{"id":18895658,"url":"https://github.com/binance/binance-sbe-cpp-sample-app","last_synced_at":"2025-04-15T01:13:47.770Z","repository":{"id":211414806,"uuid":"724051493","full_name":"binance/binance-sbe-cpp-sample-app","owner":"binance","description":"Sample app in CPP that decodes Binance API SBE","archived":false,"fork":false,"pushed_at":"2024-10-03T06:48:06.000Z","size":237,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T01:13:42.537Z","etag":null,"topics":["binance-api","cpp","crypto","decoder","sample-app","sbe"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/binance.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-11-27T09:49:00.000Z","updated_at":"2025-04-04T03:51:48.000Z","dependencies_parsed_at":"2024-03-08T08:36:00.734Z","dependency_job_id":null,"html_url":"https://github.com/binance/binance-sbe-cpp-sample-app","commit_stats":null,"previous_names":["binance/binance-sbe-cpp-sample-app"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-sbe-cpp-sample-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-sbe-cpp-sample-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-sbe-cpp-sample-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-sbe-cpp-sample-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binance","download_url":"https://codeload.github.com/binance/binance-sbe-cpp-sample-app/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248986315,"owners_count":21194025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binance-api","cpp","crypto","decoder","sample-app","sbe"],"created_at":"2024-11-08T08:29:15.917Z","updated_at":"2025-04-15T01:13:47.753Z","avatar_url":"https://github.com/binance.png","language":"C++","readme":"# C++ SBE Sample Application\n\nThis sample application is designed to decode responses from multiple endpoints, when using [Binance Spot API Simple Binary Encoding (SBE)](https://github.com/binance/binance-spot-api-docs/blob/master/faqs/sbe_faq.md):\n\n- [`REST GET /api/v3/exchangeInfo`](#pipe-rest-exchangeinfo-sbe-response-into-sbe-sample-app)\n- [`REST GET /api/v3/account`](#pipe-rest-account-sbe-response-into-sbe-sample-app)\n- [`REST POST /api/v3/order`](#pipe-rest-new-order-sbe-response-into-sbe-sample-app)\n- [`REST GET /api/v3/order`](#pipe-rest-query-order-info-sbe-response-into-sbe-sample-app)\n- [`WebSocket exchangeInfo method`](#pipe-websocket-exchangeinfo-sbe-response-into-sbe-sample-app)\n\nIt decodes a payload from STDIN and prints it as JSON to STDOUT.\nThis sample application is currently supported on Linux and macOS.\n\n## Getting Started\n\n1. Clone the source code:\n\n```shell\ngit clone git@github.com:binance/binance-sbe-cpp-sample-app.git\n```\n\n2. Navigate to the directory where the `main.cpp` file is located and use the following command to generate `sbe-sample-app`:\n\n```shell\nc++ -std=c++20 -Wextra -Wall -o sbe-sample-app ./main.cpp\n```\n\n## Usage\n\n### Pipe REST ExchangeInfo SBE response into sbe-sample-app\n\nThe following command fetches the `exchangeInfo` SBE response from the REST API and has `sbe-sample-app` decode it and output it as JSON to STDOUT:\n\n```shell\ncurl -X GET -H 'Accept: application/sbe' -H 'X-MBX-SBE: 1:0' \\\n    'https://api.binance.com/api/v3/exchangeInfo' \\\n    | ./sbe-sample-app\n```\n\n### Pipe REST Account SBE response into sbe-sample-app\n\nThe following commands fetch the `account` SBE response from the REST API and have `sbe-sample-app` decode it and output it as JSON to STDOUT:\n\n#### HMAC keys\n\n```shell\nhmac_api_key=\"\u003cyour_api_key\u003e\"; \\\n    hmac_secret_key=\"\u003cyour_secret_key\u003e\"; \\\n    url_sans_query=\"https://api.binance.com/api/v3/account\"; \\\n    query=\"timestamp=$(date +%s000)\"; \\\n    signature=$(echo -n \"${query}\" | openssl dgst -sha256 -hmac \"${hmac_secret_key}\"); \\\n    signature=${signature#*= }; \\\n    curl -X GET -H \"X-MBX-APIKEY: ${hmac_api_key}\" -H \"Accept: application/sbe\" -H \"X-MBX-SBE: 1:0\" \\\n    \"${url_sans_query}?${query}\u0026signature=${signature}\" \\\n    | ./sbe-sample-app\n```\n\n#### RSA keys\n\n```shell\nrsa_api_key=\"\u003cyour_api_key\u003e\"; \\\n    rsa_secret_path=\"\u003cpem_file_path\u003e\"; \\\n    url_sans_query=\"https://api.binance.com/api/v3/account\"; \\\n    query=\"timestamp=$(date +%s000)\"; \\\n    signature=$(echo -n \"${query}\" | openssl dgst -sha256 -sign \"${rsa_secret_path}\" | openssl enc -base64 -A); \\\n    signature=${signature#*= }; \\\n    curl -X GET -H \"X-MBX-APIKEY: ${rsa_api_key}\" -H \"Accept: application/sbe\" -H \"X-MBX-SBE: 1:0\" \\\n    \"${url_sans_query}?${query}\u0026signature=${signature}\" \\\n    | ./sbe-sample-app\n```\n\n#### ED25519 keys\n\n```shell\ned25519_api_key=\"\u003cyour_api_key\u003e\"; \\\n    ed25519_secret_path=\"\u003cpem_file_path\u003e\"; \\\n    url_sans_query=\"https://api.binance.com/api/v3/account\"; \\\n    query=\"timestamp=$(date +%s000)\"; \\\n    echo -n \"${query}\" \u003e to_be_signed.txt; \\\n    signature=$(openssl pkeyutl -sign -inkey \"${ed25519_secret_path}\" -rawin -in to_be_signed.txt | openssl enc -base64 -A); \\\n    signature=${signature#*= }; \\\n    curl -X GET -H \"X-MBX-APIKEY: ${ed25519_api_key}\" -H \"Accept: application/sbe\" -H \"X-MBX-SBE: 1:0\" \\\n    \"${url_sans_query}?${query}\u0026signature=${signature}\" \\\n    | ./sbe-sample-app\n```\n\n### Pipe REST New Order SBE response into sbe-sample-app\n\nThe following commands fetch the new `order` SBE response from the REST API when the `newOrderRespType` parameter is set to `RESULT` and have `sbe-sample-app` decode it and output it as JSON to STDOUT:\n\n#### HMAC keys\n\n```shell\nhmac_api_key=\"\u003cyour_api_key\u003e\"; \\\n    hmac_secret_key=\"\u003cyour_secret_key\u003e\"; \\\n    url_sans_query=\"https://api.binance.com/api/v3/order\"; \\\n    query=\"symbol=BNBUSDT\u0026side=BUY\u0026type=LIMIT\u0026timeInForce=GTC\u0026quantity=1\u0026price=250\u0026newOrderRespType=RESULT\u0026timestamp=$(date +%s000)\"; \\\n    signature=$(echo -n \"${query}\" | openssl dgst -sha256 -hmac \"${hmac_secret_key}\"); \\\n    signature=${signature#*= }; \\\n    curl -X POST -H \"X-MBX-APIKEY: ${hmac_api_key}\" -H \"Accept: application/sbe\" -H \"X-MBX-SBE: 1:0\" \\\n    \"${url_sans_query}?${query}\u0026signature=${signature}\" \\\n    | ./sbe-sample-app\n```\n\n#### RSA keys\n\n```shell\nrsa_api_key=\"\u003cyour_api_key\u003e\"; \\\n    rsa_secret_path=\"\u003cpem_file_path\u003e\"; \\\n    url_sans_query=\"https://api.binance.com/api/v3/order\"; \\\n    query=\"symbol=BNBUSDT\u0026side=BUY\u0026type=LIMIT\u0026timeInForce=GTC\u0026quantity=1\u0026price=250\u0026newOrderRespType=RESULT\u0026timestamp=$(date +%s000)\"; \\\n    signature=$(echo -n \"${query}\" | openssl dgst -sha256 -sign \"${rsa_secret_path}\" | openssl enc -base64 -A); \\\n    signature=${signature#*= }; \\\n    curl -X POST -H \"X-MBX-APIKEY: ${rsa_api_key}\" -H \"Accept: application/sbe\" -H \"X-MBX-SBE: 1:0\" \\\n    \"${url_sans_query}?${query}\u0026signature=${signature}\" \\\n    | ./sbe-sample-app\n```\n\n#### ED25519 keys\n\n```shell\ned25519_api_key=\"\u003cyour_api_key\u003e\"; \\\n    ed25519_secret_path=\"\u003cpem_file_path\u003e\"; \\\n    url_sans_query=\"https://api.binance.com/api/v3/order\"; \\\n    query=\"symbol=BNBUSDT\u0026side=BUY\u0026type=LIMIT\u0026timeInForce=GTC\u0026quantity=1\u0026price=250\u0026newOrderRespType=RESULT\u0026timestamp=$(date +%s000)\"; \\\n    echo -n \"${query}\" \u003e to_be_signed.txt; \\\n    signature=$(openssl pkeyutl -sign -inkey \"${ed25519_secret_path}\" -rawin -in to_be_signed.txt | openssl enc -base64 -A); \\\n    signature=${signature#*= }; \\\n    curl -X POST -H \"X-MBX-APIKEY: ${ed25519_api_key}\" -H \"Accept: application/sbe\" -H \"X-MBX-SBE: 1:0\" \\\n    \"${url_sans_query}?${query}\u0026signature=${signature}\" \\\n    | ./sbe-sample-app\n```\n\n### Pipe REST Query Order info SBE response into sbe-sample-app\n\nThe following commands fetch the `order` info SBE response from the REST API and have `sbe-sample-app` decode it and output it as JSON to STDOUT:\n\n#### HMAC keys\n\n```shell\nhmac_api_key=\"\u003cyour_api_key\u003e\"; \\\n    hmac_secret_key=\"\u003cyour_secret_key\u003e\"; \\\n    order_id=\"\u003cyour order ID\u003e\"; \\\n    url_sans_query=\"https://api.binance.com/api/v3/order\"; \\\n    query=\"symbol=BNBUSDT\u0026orderId=${order_id}\u0026timestamp=$(date +%s000)\"; \\\n    signature=$(echo -n \"${query}\" | openssl dgst -sha256 -hmac \"${hmac_secret_key}\"); \\\n    signature=${signature#*= }; \\\n    curl -X GET -H \"X-MBX-APIKEY: ${hmac_api_key}\" -H \"Accept: application/sbe\" -H \"X-MBX-SBE: 1:0\" \\\n    \"${url_sans_query}?${query}\u0026signature=${signature}\" \\\n    | ./sbe-sample-app\n```\n\n#### RSA keys\n\n```shell\nrsa_api_key=\"\u003cyour_api_key\u003e\"; \\\n    rsa_secret_path=\"\u003cpem_file_path\u003e\"; \\\n    order_id=\"\u003cyour order ID\u003e\"; \\\n    url_sans_query=\"https://api.binance.com/api/v3/order\"; \\\n    query=\"symbol=BNBUSDT\u0026orderId=${order_id}\u0026timestamp=$(date +%s000)\"; \\\n    signature=$(echo -n \"${query}\" | openssl dgst -sha256 -sign \"${rsa_secret_path}\" | openssl enc -base64 -A); \\\n    signature=${signature#*= }; \\\n    curl -X GET -H \"X-MBX-APIKEY: ${rsa_api_key}\" -H \"Accept: application/sbe\" -H \"X-MBX-SBE: 1:0\" \\\n    \"${url_sans_query}?${query}\u0026signature=${signature}\" \\\n    | ./sbe-sample-app\n```\n\n#### ED25519 keys\n\n```shell\ned25519_api_key=\"\u003cyour_api_key\u003e\"; \\\n    ed25519_secret_path=\"\u003cpem_file_path\u003e\"; \\\n    order_id=\"\u003cyour order ID\u003e\"; \\\n    url_sans_query=\"https://api.binance.com/api/v3/order\"; \\\n    query=\"symbol=BNBUSDT\u0026orderId=${order_id}\u0026timestamp=$(date +%s000)\"; \\\n    echo -n \"${query}\" \u003e to_be_signed.txt; \\\n    signature=$(openssl pkeyutl -sign -inkey \"${ed25519_secret_path}\" -rawin -in to_be_signed.txt | openssl enc -base64 -A); \\\n    signature=${signature#*= }; \\\n    curl -X GET -H \"X-MBX-APIKEY: ${ed25519_api_key}\" -H \"Accept: application/sbe\" -H \"X-MBX-SBE: 1:0\" \\\n    \"${url_sans_query}?${query}\u0026signature=${signature}\" \\\n    | ./sbe-sample-app\n```\n\n### Pipe WebSocket ExchangeInfo SBE response into sbe-sample-app\n\nThe following command fetches the `exchangeInfo` SBE response from the WebSocket API and has `sbe-sample-app` decode it and output it as JSON to STDOUT:\n\n```shell\necho '{\"id\":\"93fb61ef-89f8-4d6e-b022-4f035a3fadad\",\"method\":\"exchangeInfo\",\"params\":{\"symbol\":\"BTCUSDT\"}}' \\\n    | ./tools/websocket_send.py  'wss://ws-api.binance.com:443/ws-api/v3?responseFormat=sbe\u0026sbeSchemaId=1\u0026sbeSchemaVersion=0' \\\n    | ./sbe-sample-app\n```\n\n### Notes\n\n- The code in the `main.cpp` file, along with the accompanying header files, is designed specifically for decoding the responses from the `exchangeInfo`, `account`, and `order` endpoints.\n- There are additional decoder classes in the `spot_sbe` folder that can be useful for decoding SBE responses from other endpoints in the Binance Spot API.\n\n### Testnet\n\nTo use the Spot Testnet API, you only need to replace:\n- `api.binance.com` with `testnet.binance.vision` for the REST API\n- `ws-api.binance.com` with `testnet.binance.vision` for the WebSocket API\n\n### Code formatting\n\nThe C++ code in this repository was formatted by running:\n\n```shell\nclang-format-15 -i --style '{BasedOnStyle: chromium, IndentWidth: 4, ColumnLimit: 100}' *.h *.cpp\n```\n\n## Updates\n\n### C++ decoders\n\nThe `spot_sbe` directory contains code generated by [simple-binary-encoding](https://github.com/real-logic/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:\n\n1) Download the schema file ([spot_prod_latest.xml](https://github.com/binance/binance-spot-api-docs/blob/master/sbe/schemas/spot_prod_latest.xml)):\n\n```shell\ncurl -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)\n```\n\n**Note:** If you are using the Spot Testnet API, replace `spot_prod_latest.xml` with `spot_testnet_latest.xml` in the above `curl ` command.\n\n2) Clone \u0026 build [simple-binary-encoding](https://github.com/real-logic/simple-binary-encoding):\n\n```shell\ngit clone https://github.com/real-logic/simple-binary-encoding.git --branch 1.30.0 \\\n    \u0026\u0026 cd simple-binary-encoding \\\n    \u0026\u0026 ./gradlew \\\n    \u0026\u0026 cd ..\n```\n\n3) Run the SBE tool code generator built in the previous step:\n\n```shell\njava \\\n    -Dsbe.output.dir=. \\\n    -Dsbe.target.language=Cpp \\\n    -jar simple-binary-encoding/sbe-all/build/libs/sbe-all-1.30.0.jar \\\n    spot_latest.xml\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinance%2Fbinance-sbe-cpp-sample-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinance%2Fbinance-sbe-cpp-sample-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinance%2Fbinance-sbe-cpp-sample-app/lists"}