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

Kiwoom credentials (app key and secret key), demo or real account, the market-data tape, and the holdings settings an account must state before trading. More...

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

Inheritance diagram for algotradelib::kiwoom::KiwoomConfig:
Collaboration diagram for algotradelib::kiwoom::KiwoomConfig:

Public Member Functions

void from_env_impl ()
 Reads the credentials from KIWOOM_APP_KEY and KIWOOM_SECRET_KEY, and the environment from KIWOOM_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
 The REST host for the selected environment.
const char * rest_port () const noexcept
 The REST port, which is the same for both environments.
const char * ws_host () const noexcept
 The WebSocket host for the selected environment.
const char * ws_port () const noexcept
 The WebSocket port, which is the same for both environments.
std::string tape_symbol (std::string_view symbol) const
 Returns a symbol with this configuration's tape suffix, for a market-data request.
Public Member Functions inherited from algotradelib::network::ClientCredentials< KiwoomConfig >
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 KIWOOM_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
 The JSON field Kiwoom expects the application key under.
static constexpr std::string_view secret_field () noexcept
 The JSON field Kiwoom expects the application secret under.

Public Attributes

bool is_demo_ = true
 Whether to use Kiwoom's demo (모의투자) endpoints; true unless stated otherwise.
MarketTape market_tape_ = MarketTape::CONSOLIDATED
 Which venue's prices every Kiwoom market-data request reads (quotes, depth, trades, price bands, bars); KRX and NXT combined by default.
Venue holdings_venue_ = Venue::UNSPECIFIED
 The venue holdings requests (kt00018) name: Venue::KRX or Venue::NXT. No default: holdings requests are refused until it is set..
KiwoomPositionScope holdings_position_scope_ = KiwoomPositionScope::UNSPECIFIED
 Your assertion of what holdings_venue_ means for the positions listed. No default: until it is set, every new order and amendment is refused and the session reads no holdings (cancellations, including cancel_quantity(), still go).
KiwoomSellableScope holdings_sellable_scope_ = KiwoomSellableScope::UNSPECIFIED
 Your assertion of what a holdings row's tradable quantity covers; separate from the position scope, since Kiwoom documents neither.

Additional Inherited Members

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

Detailed Description

Kiwoom credentials (app key and secret key), demo or real account, the market-data tape, and the holdings settings an account must state before trading.

Load with from_env() (KIWOOM_APP_KEY, KIWOOM_SECRET_KEY, KIWOOM_DEMO) or from_json(filename). Holdings cannot be read until holdings_venue_ is set. Orders cannot be placed or amended, and the session (so a runner) reads no holdings, until holdings_position_scope_ is set; a checked sell also needs holdings_sellable_scope_.

Definition at line 154 of file config.hpp.

Member Function Documentation

◆ demo_from_env()

bool algotradelib::kiwoom::KiwoomConfig::demo_from_env ( )
inlinestatic

Reads KIWOOM_DEMO.

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

Definition at line 268 of file config.hpp.

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

◆ demo_from_json()

bool algotradelib::kiwoom::KiwoomConfig::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 289 of file config.hpp.

Referenced by from_json_impl().

◆ from_env_impl()

void algotradelib::kiwoom::KiwoomConfig::from_env_impl ( )
inline

Reads the credentials from KIWOOM_APP_KEY and KIWOOM_SECRET_KEY, and the environment from KIWOOM_DEMO (see demo_from_env); called by from_env(). Nothing changes if it throws.

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

Definition at line 209 of file config.hpp.

◆ from_json_impl()

void algotradelib::kiwoom::KiwoomConfig::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: { "appkey": "...", "secretkey": "...", "demo": false } (Kiwoom's own field names); 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 233 of file config.hpp.

◆ key_field()

constexpr std::string_view algotradelib::kiwoom::KiwoomConfig::key_field ( )
inlinestaticconstexprnoexcept

The JSON field Kiwoom expects the application key under.

Returns
"appkey".

Definition at line 307 of file config.hpp.

◆ rest_host()

const char * algotradelib::kiwoom::KiwoomConfig::rest_host ( ) const
inlinenoexcept

The REST host for the selected environment.

Returns
"mockapi.kiwoom.com" (demo) or "api.kiwoom.com".

Definition at line 319 of file config.hpp.

◆ rest_port()

const char * algotradelib::kiwoom::KiwoomConfig::rest_port ( ) const
inlinenoexcept

The REST port, which is the same for both environments.

Returns
"443".

Definition at line 327 of file config.hpp.

◆ secret_field()

constexpr std::string_view algotradelib::kiwoom::KiwoomConfig::secret_field ( )
inlinestaticconstexprnoexcept

The JSON field Kiwoom expects the application secret under.

Returns
"secretkey".

Definition at line 313 of file config.hpp.

◆ tape_symbol()

std::string algotradelib::kiwoom::KiwoomConfig::tape_symbol ( std::string_view symbol) const
inline

Returns a symbol with this configuration's tape suffix, for a market-data request.

Parameters
symbolThe six-digit symbol.
Returns
The suffixed symbol.

Definition at line 348 of file config.hpp.

◆ ws_host()

const char * algotradelib::kiwoom::KiwoomConfig::ws_host ( ) const
inlinenoexcept

The WebSocket host for the selected environment.

Returns
"mockapi.kiwoom.com" (demo) or "api.kiwoom.com".

Definition at line 333 of file config.hpp.

◆ ws_port()

const char * algotradelib::kiwoom::KiwoomConfig::ws_port ( ) const
inlinenoexcept

The WebSocket port, which is the same for both environments.

Returns
"10000".

Definition at line 341 of file config.hpp.

Member Data Documentation

◆ holdings_position_scope_

KiwoomPositionScope algotradelib::kiwoom::KiwoomConfig::holdings_position_scope_ = KiwoomPositionScope::UNSPECIFIED

Your assertion of what holdings_venue_ means for the positions listed. No default: until it is set, every new order and amendment is refused and the session reads no holdings (cancellations, including cancel_quantity(), still go).

Kiwoom does not document it, and two reads cannot settle it (the account can change between them). A wrong assertion undercounts the account: a buy can pass a ceiling already reached, and a sell can be refused or sized too small.

Definition at line 193 of file config.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::holdings(), and algotradelib::BrokerTraits< kiwoom::KiwoomClient >::holdings().

◆ holdings_sellable_scope_

KiwoomSellableScope algotradelib::kiwoom::KiwoomConfig::holdings_sellable_scope_ = KiwoomSellableScope::UNSPECIFIED

Your assertion of what a holdings row's tradable quantity covers; separate from the position scope, since Kiwoom documents neither.

UNSPECIFIED (the default) leaves the sellable basis unestablished, so RiskGuard refuses a checked sell. WHOLE_HOLDING supplies the coverage; resting sells are deducted either way.

Definition at line 202 of file config.hpp.

◆ holdings_venue_

Venue algotradelib::kiwoom::KiwoomConfig::holdings_venue_ = Venue::UNSPECIFIED

The venue holdings requests (kt00018) name: Venue::KRX or Venue::NXT. No default: holdings requests are refused until it is set..

kt00018 has no all-venue value, and the library does not request both and merge them: if the venue only selects the valuation price, merging would double every position. If instead it filters positions, one venue's request omits what is held on the other, so a position ceiling would see too little. Which it is, Kiwoom does not document; see holdings_position_scope_. Venue::COMBINED is refused.

Definition at line 182 of file config.hpp.

◆ is_demo_

bool algotradelib::kiwoom::KiwoomConfig::is_demo_ = true

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

Real trading must be stated: KIWOOM_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 162 of file config.hpp.

Referenced by from_env_impl(), from_json_impl(), kiwoom_credentials::load(), rest_host(), and ws_host().

◆ market_tape_

MarketTape algotradelib::kiwoom::KiwoomConfig::market_tape_ = MarketTape::CONSOLIDATED

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

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

Definition at line 170 of file config.hpp.

Referenced by tape_symbol().


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