Binance C++ Connector 2.0.0
Official C++ connectors for the Binance APIs
Loading...
Searching...
No Matches
binance::common::RestClient Class Reference

The REST transport shared by every product. More...

#include <rest.hpp>

Public Types

using Signature = void(std::exception_ptr, RawResponse)
using Handler = boost::asio::any_completion_handler<Signature>

Public Member Functions

 RestClient (RestApiConfig configuration, detail::ClientOptions options={})
 Throws ConfigError if base_path or proxy is invalid, or ConnectorClientError if the private key cannot be loaded.
 ~RestClient ()
 RestClient (const RestClient &)=delete
RestClient & operator= (const RestClient &)=delete
 RestClient (RestClient &&)=delete
RestClient & operator= (RestClient &&)=delete
const RestApiConfig & configuration () const noexcept
 The configuration, as given but without private_key_passphrase (the key is loaded).
const SignatureGenerator & signature_generator () const noexcept
boost::asio::any_io_executor get_executor () const noexcept
template<class CompletionToken>
auto async_send_request (RestRequest request, CompletionToken &&token)
 Asynchronous send.
RawResponse send_request (RestRequest request)
 Blocking send.

Detailed Description

The REST transport shared by every product.

It runs on its own I/O thread, or on configuration.executor when set, and keeps a keep-alive connection pool. It handles signing, retries, gzip / deflate decoding, rate-limit headers and error mapping.

Completion handlers run on the handler's associated executor. Without one, they run on the client's executor (get_executor()). Errors are delivered as std::exception_ptr, which holds a ConnectorError subclass.

Without configuration.executor, the executor from get_executor() belongs to the client's own I/O context: neither it nor I/O objects created on it may outlive the client. Destruction waits for the I/O thread, which may be held up by a DNS lookup in progress (getaddrinfo cannot be interrupted).

Member Typedef Documentation

◆ Signature

using binance::common::RestClient::Signature = void(std::exception_ptr, RawResponse)

◆ Handler

using binance::common::RestClient::Handler = boost::asio::any_completion_handler<Signature>

Constructor & Destructor Documentation

◆ RestClient() [1/3]

binance::common::RestClient::RestClient ( RestApiConfig configuration,
detail::ClientOptions options = {} )
explicit

Throws ConfigError if base_path or proxy is invalid, or ConnectorClientError if the private key cannot be loaded.

◆ ~RestClient()

binance::common::RestClient::~RestClient ( )

◆ RestClient() [2/3]

binance::common::RestClient::RestClient ( const RestClient & )
delete

◆ RestClient() [3/3]

binance::common::RestClient::RestClient ( RestClient && )
delete

Member Function Documentation

◆ operator=() [1/2]

RestClient & binance::common::RestClient::operator= ( const RestClient & )
delete

◆ operator=() [2/2]

RestClient & binance::common::RestClient::operator= ( RestClient && )
delete

◆ configuration()

const RestApiConfig & binance::common::RestClient::configuration ( ) const
nodiscardnoexcept

The configuration, as given but without private_key_passphrase (the key is loaded).

◆ signature_generator()

const SignatureGenerator & binance::common::RestClient::signature_generator ( ) const
nodiscardnoexcept

◆ get_executor()

boost::asio::any_io_executor binance::common::RestClient::get_executor ( ) const
nodiscardnoexcept

◆ async_send_request()

template<class CompletionToken>
auto binance::common::RestClient::async_send_request ( RestRequest request,
CompletionToken && token )
inline

Asynchronous send.

token may be a callback void(std::exception_ptr, RawResponse), boost::asio::use_future, boost::asio::use_awaitable, …

Supports per-operation cancellation (bind_cancellation_slot, parallel groups, or cancel_after(timer, duration, token) with a timer on the caller's executor): the request then completes with RequestCancelledError, whose request_sent() says whether it may have reached the server. Terminal and partial cancellation are always honoured; total cancellation only until the request starts to be written, and is ignored after that. A response that has already arrived is delivered instead. Destroying the client cancels every in-flight request the same way.

◆ send_request()

RawResponse binance::common::RestClient::send_request ( RestRequest request)

Blocking send.

Throws a ConnectorError subclass on failure. Must not be called from the client's executor, nor from a thread running a shared one.