|
Binance C++ Connector 2.0.0
Official C++ connectors for the Binance APIs
|
Directories | |
| include | |
binance::gift_card is the official C++ connector for the Binance Gift Card REST API. Create, redeem, and check the value of Binance crypto gift cards.
It is one component of the Binance C++ Connector, built on the shared binance::common library.
With vcpkg, as an overlay port of this repository (see the root README):
From source, building only this connector:
Then, in your CMakeLists.txt:
#include <binance/gift_card/gift_card.hpp> includes every client of the connector; include <binance/gift_card/rest_api.hpp> for just one of them.
Each call returns a common::RestApiResponse<T>: data() is the decoded response, status() the HTTP status, headers() the response headers and rate_limits() the request weight and order counts Binance reported for the call.
The client is configured with a common::RestApiConfig:
| Option | Default | Description |
|---|---|---|
| api_key, api_secret | none | Credentials for signed endpoints (HMAC). |
| private_key, private_key_passphrase | none | An RSA or Ed25519 key instead of api_secret: common::PrivateKey::from_file(path) or from_pem(text). |
| base_path | set by the factory | Another endpoint for the client (see Environments). |
| timeout | 1000 ms | How long a request attempt may take as a whole (connect, write, read the response); a retry starts a new one. |
| retries, backoff | 3, 1000 ms | Attempts for GET and DELETE on a network error or a 5xx response, with a linear backoff. |
| keep_alive | true | Reuses connections. |
| compression | true | Asks for gzip / deflate responses. |
| max_response_size | 128 MiB | Larger responses fail with ConnectorClientError. |
| proxy, proxy_from_env | none, true | An HTTP(S) proxy with Basic auth, or a SOCKS5 proxy (ProxyProtocol::Socks5 / Socks5h); without one, HTTPS_PROXY / HTTP_PROXY / ALL_PROXY / NO_PROXY are used. |
| custom_headers | none | Headers added to every request. |
| agent | none | A hook on the TLS context: add CAs, client certificates, or pin certificates. |
| timestamp_provider | host clock | The timestamp of signed requests, e.g. the host clock corrected by its offset from serverTime (error -1021). |
| executor | own thread | An Asio executor to share one event loop between many clients. |
An example for each option:
See common/README.md for the details.
Every error derives from common::Error, with the Binance code() and msg() when there is one. REST errors are subclasses of common::ConnectorError and carry the HTTP response():
The full list is in common/README.md.
send_request and send_signed_request call an endpoint the connector does not have a method for yet, and decode the response into any type, for example boost::json::value:
The client is created with GiftCardRestApi::production(cfg), or with from_config(cfg) for the endpoint in cfg.base_path.
Every method has an async_ variant that takes a completion token as its last argument:
Callbacks run on the client's executor, so they should not block. Errors are delivered as a std::exception_ptr.
The connector logs through common::Logger. Set the level with common::Logger::set_level or the LOG_LEVEL environment variable (debug, info, warn, error, none), and send the messages elsewhere with common::Logger::set_sink. Configurations printed with operator<< have their secrets redacted.
examples/gift_card/ has one runnable program for every endpoint. See its README to build and run them.
The tests run the connector against local mock servers, with the example responses of the API. From the root of the repository:
Tests cover:
Since this repository contains auto-generated code using OpenAPI Generator, we encourage you to:
Manual edits to the generated connectors under clients/ and examples/ will be overwritten.
This SDK is provided by Binance on an "as is" and "as available" basis for use at your own risk. Binance makes no representations or warranties of any kind, whether express or implied, as to the operation of the SDK, its accuracy, reliability, completeness, or fitness for any particular purpose.
To the fullest extent permitted by law, Binance shall not be liable for any losses, damages, or expenses of any kind arising from or in connection with your use of, or inability to use, this SDK, including but not limited to any financial losses resulting from errors, bugs, interruptions, or inaccuracies in the SDK.
Your use of this SDK to access the Binance Platform is subject to the Binance API Key Terms and the Binance Terms of Use, which shall prevail in the event of any conflict with this disclaimer. You are solely responsible for any orders or transactions executed through the Binance Platform using this SDK.
This SDK is not intended to constitute investment advice or a recommendation to buy, sell, or hold any digital asset. You should independently evaluate and verify all information before acting.
This project is licensed under the MIT License - see the LICENCE file for details.