algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::network::ClientCredentials< BrokerType > Class Template Reference

OAuth client credentials (an app key and secret), the base of each broker's credentials class. More...

#include <algotradelib/src/network/oauth.hpp>

Inheritance diagram for algotradelib::network::ClientCredentials< BrokerType >:

Public Member Functions

void from_env ()
 Loads the credentials from the broker's environment variables.
void from_json (const std::string &filename)
 Loads the credentials from a JSON file, in the broker's format.
const std::string & key () const noexcept
 Returns the app key (client id).
const std::string & secret () const noexcept
 Returns the app secret.
std::string to_jsonbody () const
 Builds a JSON token-request body (grant type, key and secret under the broker's field names).
std::string to_form_urlencoded_body () const
 Builds a form-encoded token-request body (grant_type, client_id, client_secret).

Static Public Attributes

static constexpr std::string_view grant_type = "client_credentials"
 The OAuth grant type sent in a token request.

Protected Attributes

std::string key_
 The app key (client id).
std::string secret_
 The app secret.

Detailed Description

template<typename BrokerType>
class algotradelib::network::ClientCredentials< BrokerType >

OAuth client credentials (an app key and secret), the base of each broker's credentials class.

The broker class derives from it (CRTP) and provides from_env_impl(), from_json_impl(filename), and the static key_field() and secret_field() naming the token request's JSON fields.

Template Parameters
BrokerTypeThe derived broker credentials class.

Definition at line 36 of file oauth.hpp.

Member Function Documentation

◆ from_env()

template<typename BrokerType>
void algotradelib::network::ClientCredentials< BrokerType >::from_env ( )
inline

Loads the credentials from the broker's environment variables.

Exceptions
std::runtime_error(from the broker's implementation) if a variable is missing or invalid (such as a demo setting that is neither 0 nor 1).

Definition at line 46 of file oauth.hpp.

Referenced by kis_credentials::load(), and kiwoom_credentials::load().

◆ from_json()

template<typename BrokerType>
void algotradelib::network::ClientCredentials< BrokerType >::from_json ( const std::string & filename)
inline

Loads the credentials from a JSON file, in the broker's format.

Parameters
filenameThe file.
Exceptions
std::runtime_error(from the broker's implementation) if the file cannot be read or is not valid JSON, or a field is missing, of the wrong type or invalid.

Definition at line 54 of file oauth.hpp.

Referenced by kiwoom_credentials::load(), and kis_credentials::load_config().

◆ key()

template<typename BrokerType>
const std::string & algotradelib::network::ClientCredentials< BrokerType >::key ( ) const
inlinenoexcept

Returns the app key (client id).

Returns
The key.

Definition at line 62 of file oauth.hpp.

◆ secret()

template<typename BrokerType>
const std::string & algotradelib::network::ClientCredentials< BrokerType >::secret ( ) const
inlinenoexcept

Returns the app secret.

Returns
The secret; do not log it.

Definition at line 68 of file oauth.hpp.

◆ to_form_urlencoded_body()

template<typename BrokerType>
std::string algotradelib::network::ClientCredentials< BrokerType >::to_form_urlencoded_body ( ) const
inline

Builds a form-encoded token-request body (grant_type, client_id, client_secret).

Returns
The body, values percent-encoded.

Definition at line 87 of file oauth.hpp.

◆ to_jsonbody()

template<typename BrokerType>
std::string algotradelib::network::ClientCredentials< BrokerType >::to_jsonbody ( ) const
inline

Builds a JSON token-request body (grant type, key and secret under the broker's field names).

Returns
The body.

Definition at line 75 of file oauth.hpp.

Member Data Documentation

◆ grant_type

template<typename BrokerType>
std::string_view algotradelib::network::ClientCredentials< BrokerType >::grant_type = "client_credentials"
staticconstexpr

The OAuth grant type sent in a token request.

Definition at line 39 of file oauth.hpp.

Referenced by to_jsonbody().

◆ key_

template<typename BrokerType>
std::string algotradelib::network::ClientCredentials< BrokerType >::key_
protected

The app key (client id).

Definition at line 94 of file oauth.hpp.

Referenced by key(), to_form_urlencoded_body(), and to_jsonbody().

◆ secret_

template<typename BrokerType>
std::string algotradelib::network::ClientCredentials< BrokerType >::secret_
protected

The app secret.

Definition at line 96 of file oauth.hpp.

Referenced by secret(), to_form_urlencoded_body(), and to_jsonbody().


The documentation for this class was generated from the following file: