algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::kis::KisConfig Struct Reference

KIS credentials (app key and secret), demo or real account, and the market-data tape. More...

#include <algotradelib/src/brokers/kis/config.hpp>

Inheritance diagram for algotradelib::kis::KisConfig:
Collaboration diagram for algotradelib::kis::KisConfig:

Public Member Functions

void from_env_impl ()
 Reads the credentials from KIS_APP_KEY and KIS_APP_SECRET, and the environment from KIS_DEMO (see demo_from_env); called by from_env(). Nothing changes if it throws.
void from_json_impl (const std::string &filename)
 Reads the credentials from a JSON file; called by from_json(filename). Nothing changes if it throws.
const char * rest_host () const noexcept
 Returns the REST host for the environment.
const char * rest_port () const noexcept
 Returns the REST port for the environment.
const char * ws_host () const noexcept
 Returns the WebSocket host (the same for both environments).
const char * ws_port () const noexcept
 Returns the WebSocket port for the environment.
std::string ws_to_jsonbody () const
 Builds the WebSocket approval-key request body (the secret under secretkey).
Public Member Functions inherited from algotradelib::network::ClientCredentials< KisConfig >
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 Member Functions

static bool demo_from_env ()
 Reads KIS_DEMO.
static bool demo_from_json (const json::object &doc, const std::string &filename)
 Reads a credential file's "demo".
static constexpr std::string_view key_field () noexcept
 Returns the token request's field for the app key.
static constexpr std::string_view secret_field () noexcept
 Returns the token request's field for the app secret.

Public Attributes

bool is_demo_ = true
 Whether to use KIS's demo (모의투자) endpoints; true unless stated otherwise.
MarketTape market_tape_ = MarketTape::CONSOLIDATED
 Which venue's prices every KIS market-data request reads (quotes, bars, depth, price bands, trades); KRX and NXT combined by default, as Toss reports.

Additional Inherited Members

Static Public Attributes inherited from algotradelib::network::ClientCredentials< KisConfig >
static constexpr std::string_view grant_type
 The OAuth grant type sent in a token request.
Protected Attributes inherited from algotradelib::network::ClientCredentials< KisConfig >
std::string key_
 The app key (client id).
std::string secret_
 The app secret.

Detailed Description

KIS credentials (app key and secret), demo or real account, and the market-data tape.

Load with from_env() (KIS_APP_KEY, KIS_APP_SECRET, KIS_DEMO) or from_json(filename).

Definition at line 90 of file config.hpp.

Member Function Documentation

◆ demo_from_env()

bool algotradelib::kis::KisConfig::demo_from_env ( )
inlinestatic

Reads KIS_DEMO.

Returns
true (demo) if unset or 1, false (real) if 0.
Exceptions
std::runtime_errorfor any other value.

Definition at line 179 of file config.hpp.

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

◆ demo_from_json()

bool algotradelib::kis::KisConfig::demo_from_json ( const json::object & doc,
const std::string & filename )
inlinestatic

Reads a credential file's "demo".

Parameters
docThe file's contents.
filenameThe file, for the error message.
Returns
true if absent, otherwise its value.
Exceptions
std::runtime_errorif it is not a boolean.

Definition at line 200 of file config.hpp.

Referenced by from_json_impl().

◆ from_env_impl()

void algotradelib::kis::KisConfig::from_env_impl ( )
inline

Reads the credentials from KIS_APP_KEY and KIS_APP_SECRET, and the environment from KIS_DEMO (see demo_from_env); called by from_env(). Nothing changes if it throws.

Exceptions
std::runtime_errorif a key variable is missing or KIS_DEMO is invalid.

Definition at line 116 of file config.hpp.

◆ from_json_impl()

void algotradelib::kis::KisConfig::from_json_impl ( const std::string & filename)
inline

Reads the credentials from a JSON file; called by from_json(filename). Nothing changes if it throws.

Format: { "app_key": "...", "app_secret": "...", "demo": false }; without "demo" the config is demo.

Parameters
filenameThe file.
Exceptions
std::runtime_errorif the file cannot be read or parsed, a key is missing or not a string, or "demo" is not a boolean.

Definition at line 140 of file config.hpp.

◆ key_field()

constexpr std::string_view algotradelib::kis::KisConfig::key_field ( )
inlinestaticconstexprnoexcept

Returns the token request's field for the app key.

Returns
"appkey".

Definition at line 218 of file config.hpp.

◆ rest_host()

const char * algotradelib::kis::KisConfig::rest_host ( ) const
inlinenoexcept

Returns the REST host for the environment.

Returns
The host name.

Definition at line 230 of file config.hpp.

◆ rest_port()

const char * algotradelib::kis::KisConfig::rest_port ( ) const
inlinenoexcept

Returns the REST port for the environment.

Returns
"29443" (demo) or "9443".

Definition at line 238 of file config.hpp.

◆ secret_field()

constexpr std::string_view algotradelib::kis::KisConfig::secret_field ( )
inlinestaticconstexprnoexcept

Returns the token request's field for the app secret.

Returns
"appsecret".

Definition at line 224 of file config.hpp.

◆ ws_host()

const char * algotradelib::kis::KisConfig::ws_host ( ) const
inlinenoexcept

Returns the WebSocket host (the same for both environments).

Returns
The host name.

Definition at line 244 of file config.hpp.

◆ ws_port()

const char * algotradelib::kis::KisConfig::ws_port ( ) const
inlinenoexcept

Returns the WebSocket port for the environment.

Returns
"31000" (demo) or "21000".

Definition at line 250 of file config.hpp.

◆ ws_to_jsonbody()

std::string algotradelib::kis::KisConfig::ws_to_jsonbody ( ) const
inline

Builds the WebSocket approval-key request body (the secret under secretkey).

Returns
The JSON body.

Definition at line 256 of file config.hpp.

Member Data Documentation

◆ is_demo_

bool algotradelib::kis::KisConfig::is_demo_ = true

Whether to use KIS's demo (모의투자) endpoints; true unless stated otherwise.

Real trading must be stated: KIS_DEMO=0, "demo": false in the credential file, or is_demo_ = false. Real-account keys sent to the demo endpoints are refused at the first token request, so a forgotten setting fails rather than trades.

Definition at line 101 of file config.hpp.

Referenced by from_env_impl(), from_json_impl(), kis_credentials::load_config(), rest_host(), rest_port(), and ws_port().

◆ market_tape_

MarketTape algotradelib::kis::KisConfig::market_tape_ = MarketTape::CONSOLIDATED

Which venue's prices every KIS market-data request reads (quotes, bars, depth, price bands, trades); KRX and NXT combined by default, as Toss reports.

It does not change the instrument's identity or where orders go.

Definition at line 109 of file config.hpp.


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