![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
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>
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. | |
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.
|
inlinestatic |
Reads KIWOOM_DEMO.
| std::runtime_error | for any other value. |
Definition at line 268 of file config.hpp.
Referenced by from_env_impl(), and kiwoom_credentials::load().
|
inlinestatic |
Reads a credential file's "demo".
| doc | The file's contents. |
| filename | The file, for the error message. |
| std::runtime_error | if it is not a boolean. |
Definition at line 289 of file config.hpp.
Referenced by from_json_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.
| std::runtime_error | if a key variable is missing or KIWOOM_DEMO is invalid. |
Definition at line 209 of file config.hpp.
|
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.
| filename | The file. |
| std::runtime_error | if 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.
|
inlinestaticconstexprnoexcept |
The JSON field Kiwoom expects the application key under.
Definition at line 307 of file config.hpp.
|
inlinenoexcept |
The REST host for the selected environment.
Definition at line 319 of file config.hpp.
|
inlinenoexcept |
The REST port, which is the same for both environments.
Definition at line 327 of file config.hpp.
|
inlinestaticconstexprnoexcept |
The JSON field Kiwoom expects the application secret under.
Definition at line 313 of file config.hpp.
|
inline |
Returns a symbol with this configuration's tape suffix, for a market-data request.
| symbol | The six-digit symbol. |
Definition at line 348 of file config.hpp.
|
inlinenoexcept |
The WebSocket host for the selected environment.
Definition at line 333 of file config.hpp.
|
inlinenoexcept |
The WebSocket port, which is the same for both environments.
Definition at line 341 of file config.hpp.
| 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().
| 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.
| 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.
| 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().
| 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().