![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
The Kiwoom Securities REST API client. More...
Classes | |
| struct | Broker |
| The Kiwoom broker tag: order references are typed by it, so a Kiwoom reference works with both Kiwoom clients and with no other broker. More... | |
| struct | KiwoomAccount |
| The Kiwoom account selector, which is empty: no Kiwoom endpoint takes an account number, since the app key determines the account (ka00001 reports which). More... | |
| struct | KiwoomAccountInfo |
| One account Kiwoom's ka00001 reports for the bound credential. More... | |
| struct | KiwoomAmendment |
| An amendment or cancellation of a Kiwoom order. More... | |
| class | KiwoomAuth |
| Obtains and caches a Kiwoom access token with blocking requests; thread-safe. More... | |
| class | KiwoomBlockingClient |
| A blocking Kiwoom client: each call runs a KiwoomClient request on a private event loop and returns its result. Not thread-safe. Order references work with either client. More... | |
| class | KiwoomClient |
| The asynchronous Kiwoom REST client: market data, account inquiries and orders for domestic stocks. More... | |
| struct | KiwoomConfig |
| 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... | |
| struct | KiwoomDeposit |
| Kiwoom's deposit detail (kt00001), as reported; buying_power reads spendable_ from it, and the rest is reachable through session.client(). More... | |
| struct | KiwoomHistoryQuery |
| A Kiwoom order-history query: one date (kt00007 takes no range, so a multi-day query is refused). More... | |
| struct | KiwoomMarginTier |
| One margin tier of Kiwoom's kt00010 answer: what may be ordered at that 증거금률. More... | |
| struct | KiwoomOpenOrder |
| One Kiwoom order that is still open to modification or cancellation. More... | |
| struct | KiwoomOpenOrderPage |
| One page of Kiwoom orders that remain modifiable or cancellable. More... | |
| struct | KiwoomOrderableAmount |
| What may be ordered of one instrument, per margin tier (kt00010), reachable through session.client(). More... | |
| struct | KiwoomOrderAck |
| Kiwoom's acknowledgement of an accepted order, amendment or cancellation. More... | |
| struct | KiwoomOrderRef |
| A Kiwoom order's address: order number and symbol, both of which amendments and cancellations require. More... | |
| struct | KiwoomOrderShapeRow |
| One row of Kiwoom's order-type table: the numeric request code, the Korean names its listings report, and the normalized shape. More... | |
| struct | KiwoomRest |
| A Kiwoom REST access token (au10001's token) and its expiry (expires_dt). More... | |
Typedefs | |
| using | KiwoomHttpClient = network::HttpClient |
| The blocking HTTP client KiwoomAuth uses. | |
Enumerations | |
| enum class | MarketTape { CONSOLIDATED , KRX , NXT } |
| Which venue's prices Kiwoom market-data requests read (see KiwoomConfig::market_tape_). More... | |
| enum class | KiwoomPositionScope { UNSPECIFIED , VALUATION_ONLY } |
| What the venue named on a Kiwoom holdings request (kt00018's dmst_stex_tp) means for the positions it lists; Kiwoom does not document it, so you assert it (see KiwoomConfig::holdings_position_scope_). More... | |
| enum class | KiwoomSellableScope { UNSPECIFIED , WHOLE_HOLDING } |
| What a Kiwoom holdings row's tradable quantity (trde_able_qty) covers; undocumented, so you assert it (see KiwoomConfig::holdings_sellable_scope_). More... | |
| enum class | KiwoomRateLimitLayer { NONE , ENDPOINT , TOTAL , GROUP } |
| Which of Kiwoom's three rate limits a refusal reports (per API, account-wide, or per API group); backing off the wrong one does not help. More... | |
| enum class | KiwoomOrderOperation { UNCLASSIFIED , PLACE , AMEND , CANCEL } |
| Which order instruction a reply answers. More... | |
Functions | |
| Date | today_in_seoul () |
| Returns today's date in Korea (UTC+9), the date Kiwoom requests are made in. | |
| std::optional< BrokerError > | unestablished_holdings_scope () |
| Makes the error that refuses a new order or an amendment while KiwoomConfig::holdings_position_scope_ is not stated. | |
| std::optional< BrokerError > | unsupported_client_order_id (const OrderRequest &order) |
| Refuses an idempotency key, which Kiwoom does not offer (an order carrying client_order_id_ is refused before sending). | |
| bool | valid_trigger_value (const Decimal64 &trigger) |
| Tests whether a trigger price is one Kiwoom can carry (cond_uv, mdfy_cond_uv). | |
| std::optional< BrokerError > | invalid_trigger (OrderType type, const std::optional< Decimal64 > &trigger) |
| Checks that a trigger price is present exactly when the order type takes one (only STOP_LIMIT, Kiwoom's 28) and is a positive whole number of won. | |
| std::optional< BrokerError > | order_division (OrderType type, TimeInForce time_in_force, OrderSession session, std::string &division) |
| Finds Kiwoom's order-type code for an order shape. | |
| const KiwoomOrderShapeRow * | shape_by_name (std::string_view name) noexcept |
| Looks up an order shape by the Korean name a response gives (either listing's spelling). | |
| const KiwoomOrderShapeRow * | shape_by_code (std::string_view code) noexcept |
| Looks up an order shape by Kiwoom's numeric trde_tp code. | |
| const char * | exchange_code (Venue venue) noexcept |
| Returns Kiwoom's dmst_stex_tp value for a venue. | |
| constexpr Venue | kiwoom_effective_route (Venue asked) noexcept |
| Returns the venue a Kiwoom order reaches: the one it names (Kiwoom requires one, so an order naming none is refused before sending). | |
| Venue | normalized_venue (std::string_view code) noexcept |
| Converts a venue Kiwoom names on a response (stex_tp, dmst_stex_tp). | |
| Venue | listed_venue (std::string_view stex_tp, std::string_view sor_yn) noexcept |
| Returns the venue of a working-order row (ka10075) from its stex_tp and sor_yn. | |
| std::optional< OrderSide > | normalized_order_side (std::string_view text) noexcept |
| Reads the side from Kiwoom's free-text io_tp_nm (such as +매수, 현금매도, 매수정정), by whether it contains 매수 or 매도. | |
| OrderStatus | normalized_order_status (std::string_view text) noexcept |
| Reads an order status from Kiwoom's Korean word. | |
| constexpr const char * | chart_api_id (BarInterval interval) noexcept |
| Returns the api-id of the chart endpoint for a bar interval. | |
| constexpr const char * | chart_rows_field (BarInterval interval) noexcept |
| Returns the array field a bar interval's chart endpoint returns its rows in. | |
| std::optional< BrokerError > | unsupported_bar_interval (BarInterval interval) |
| Refuses a bar interval this client requests no chart for (chart_api_id). | |
| constexpr const char * | tape_suffix (MarketTape tape) noexcept |
| Returns the symbol suffix for a tape. | |
| std::chrono::system_clock::time_point | parse_compact_expiry (std::string_view text) |
| Reads Kiwoom's token expiry, yyyyMMddHHmmss in Korean time. | |
| constexpr bool | kiwoom_position_scope_asserted (KiwoomPositionScope scope) noexcept |
| Tests whether a holdings scope states what Kiwoom's holdings figure covers, so holdings may be read and orders checked against them. | |
| KiwoomRateLimitLayer | kiwoom_rate_limit_layer (std::string_view code) noexcept |
| Classifies a Kiwoom return code as a rate-limit refusal. | |
| ErrorCategory | kiwoom_error_category (std::string_view code) noexcept |
| Classifies a Kiwoom return_code. | |
| std::optional< BrokerError > | kiwoom_declared_error (const boost::json::object &document) |
| Reads the failure a Kiwoom response declares in its body (Kiwoom reports business failures with HTTP 200 and a nonzero return_code). | |
| std::string_view | kiwoom_refusal_code (std::string_view message) noexcept |
| Reads the code inside an order refusal's return_msg, which Kiwoom writes as [2000](CODE:text) under the generic return_code 20. | |
| std::optional< BrokerError > | kiwoom_recognized_refusal (int http_status, const boost::json::object &document, KiwoomOrderOperation operation, bool demo) |
| Reads the refusal a cash-order reply states, for the replies this client recognizes as one. | |
Variables | |
| constexpr std::array< KiwoomOrderShapeRow, 21 > | kOrderShapes |
| Kiwoom's order-type (trde_tp) table, from its API specification. | |
The Kiwoom Securities REST API client.
The blocking HTTP client KiwoomAuth uses.
Definition at line 9 of file network.hpp.
|
strong |
Which order instruction a reply answers.
Fixed where the request is built and carried to the parser with it, never recovered from the reply. Everything that is not an order request is UNCLASSIFIED.
| Enumerator | |
|---|---|
| UNCLASSIFIED | Not an order request, or one this client does not classify. |
| PLACE | A placement (kt10000, kt10001). |
| AMEND | An amendment (kt10002). |
| CANCEL | A cancellation (kt10003). |
Definition at line 138 of file errors.hpp.
|
strong |
What the venue named on a Kiwoom holdings request (kt00018's dmst_stex_tp) means for the positions it lists; Kiwoom does not document it, so you assert it (see KiwoomConfig::holdings_position_scope_).
Definition at line 102 of file config.hpp.
|
strong |
Which of Kiwoom's three rate limits a refusal reports (per API, account-wide, or per API group); backing off the wrong one does not help.
| Enumerator | |
|---|---|
| NONE | Not a rate-limit code. |
| ENDPOINT | 1700: this API's own allowance. |
| TOTAL | 1701: the total allowance across every API. |
| GROUP | 1702: the allowance of the API group this endpoint belongs to. |
Definition at line 17 of file errors.hpp.
|
strong |
What a Kiwoom holdings row's tradable quantity (trde_able_qty) covers; undocumented, so you assert it (see KiwoomConfig::holdings_sellable_scope_).
| Enumerator | |
|---|---|
| UNSPECIFIED | Not stated: the sellable basis is unestablished, and a sell checked against it is refused. |
| WHOLE_HOLDING | Asserted: it covers every share held of the instrument, on any venue. |
Definition at line 138 of file config.hpp.
|
strong |
Which venue's prices Kiwoom market-data requests read (see KiwoomConfig::market_tape_).
Kiwoom encodes it as a suffix on the symbol: 005930 is KRX, 005930_NX NXT, 005930_AL both combined (SOR).
| Enumerator | |
|---|---|
| CONSOLIDATED | KRX and NXT combined, the SOR book (_AL). |
| KRX | KRX alone (no suffix). |
| NXT | NXT alone (_NX). |
Definition at line 33 of file config.hpp.
|
inlineconstexprnoexcept |
Returns the api-id of the chart endpoint for a bar interval.
| interval | The interval. |
Definition at line 745 of file client.hpp.
Referenced by chart_api_id(), and unsupported_bar_interval().
|
inlineconstexprnoexcept |
Returns the array field a bar interval's chart endpoint returns its rows in.
| interval | The interval. |
Definition at line 771 of file client.hpp.
Referenced by chart_rows_field(), and unsupported_bar_interval().
|
inlinenoexcept |
Returns Kiwoom's dmst_stex_tp value for a venue.
| venue | The venue. |
Definition at line 642 of file client.hpp.
Referenced by exchange_code().
|
inline |
Checks that a trigger price is present exactly when the order type takes one (only STOP_LIMIT, Kiwoom's 28) and is a positive whole number of won.
Its direction relative to the limit is not checked (Kiwoom documents none).
| type | The order type. |
| trigger | The trigger price. |
Definition at line 241 of file client.hpp.
Referenced by invalid_trigger().
|
inline |
Reads the failure a Kiwoom response declares in its body (Kiwoom reports business failures with HTTP 200 and a nonzero return_code).
| document | The response body. |
Definition at line 97 of file errors.hpp.
Referenced by kiwoom_declared_error().
Returns the venue a Kiwoom order reaches: the one it names (Kiwoom requires one, so an order naming none is refused before sending).
| asked | The order's venue. |
Definition at line 663 of file client.hpp.
Referenced by kiwoom_effective_route(), and algotradelib::kiwoom_route().
|
inlinenoexcept |
Classifies a Kiwoom return_code.
The client does not discard a token Kiwoom refuses: requests may keep failing until five minutes before the token's stated expiry.
| code | The code, as text. |
Definition at line 62 of file errors.hpp.
Referenced by kiwoom_declared_error(), and kiwoom_error_category().
|
inlineconstexprnoexcept |
Tests whether a holdings scope states what Kiwoom's holdings figure covers, so holdings may be read and orders checked against them.
It is the operator's assertion, not a fact the library checked.
| scope | The scope. |
Definition at line 124 of file config.hpp.
Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::holdings(), algotradelib::BrokerTraits< kiwoom::KiwoomClient >::holdings(), and kiwoom_position_scope_asserted().
|
inlinenoexcept |
Classifies a Kiwoom return code as a rate-limit refusal.
| code | Kiwoom's return_code, as text. |
Definition at line 33 of file errors.hpp.
Referenced by kiwoom_error_category(), and kiwoom_rate_limit_layer().
|
inline |
Reads the refusal a cash-order reply states, for the replies this client recognizes as one.
From the demo server: a placement answered 800033 (not enough to sell), RC4057 (the market has not opened) or RC4058 (the market has closed), and a cancellation answered RC4033 (nothing left to amend or cancel). From the real server: a placement answered 571445 (no securities balance) and a cancellation answered 506550 (no quantity left to cancel). Such a reply is INVALID_ARGUMENT with reached_broker_ set, which a runner reads as a rejection; any other reply with return_code 20 stays PROTOCOL, an unknown outcome.
Each code is recognized from the server it was seen from only: a demo code from the real server, or a real code from the demo server, is not. The reply must be HTTP 200 with return_code 20 (a JSON integer, or the string "20"), a return_msg of the shape kiwoom_refusal_code reads, and none of what an acknowledgement carries: ord_no absent or empty, and cncl_qty and mdfy_qty absent, empty or all zeros. A reply acknowledging a new order is never read as a refusal (the original order's number, echoed in base_orig_ord_no, is not an acknowledgement). A refused cancellation says only that the cancellation did nothing, not what became of the order it named.
| http_status | The reply's HTTP status. |
| document | The reply body. |
| operation | The instruction the reply answers. |
| demo | Whether the request went to the demo server. |
Definition at line 204 of file errors.hpp.
Referenced by kiwoom_recognized_refusal().
|
inlinenoexcept |
Reads the code inside an order refusal's return_msg, which Kiwoom writes as [2000](CODE:text) under the generic return_code 20.
The whole message must have that shape, from its first character to its last: the literal [2000](, a code of one or more of A-Z and 0-9, a colon, some text, and a closing parenthesis as the last character. A code that only appears somewhere in a message is not read.
| message | Kiwoom's return_msg. |
Definition at line 160 of file errors.hpp.
Referenced by kiwoom_recognized_refusal(), and kiwoom_refusal_code().
|
inlinenoexcept |
Returns the venue of a working-order row (ka10075) from its stex_tp and sor_yn.
sor_yn Y means Venue::COMBINED (SOR) whatever stex_tp says; otherwise stex_tp decides. How Kiwoom lists a resting SOR order has not been observed.
| stex_tp | The row's stex_tp. |
| sor_yn | The row's sor_yn. |
Definition at line 693 of file client.hpp.
Referenced by listed_venue().
|
inlinenoexcept |
Reads the side from Kiwoom's free-text io_tp_nm (such as +매수, 현금매도, 매수정정), by whether it contains 매수 or 매도.
| text | The text. |
Definition at line 707 of file client.hpp.
Referenced by normalized_order_side().
|
inlinenoexcept |
Reads an order status from Kiwoom's Korean word.
| text | The word (ord_stt or acpt_tp). |
Definition at line 723 of file client.hpp.
Referenced by normalized_order_status().
|
inlinenoexcept |
Converts a venue Kiwoom names on a response (stex_tp, dmst_stex_tp).
| code | The value. |
Definition at line 670 of file client.hpp.
Referenced by listed_venue(), and normalized_venue().
|
inline |
Finds Kiwoom's order-type code for an order shape.
| type | The order type. |
| time_in_force | The execution condition. |
| session | The session. |
| division | Set to the code on success. |
Definition at line 571 of file client.hpp.
Referenced by order_division().
|
inline |
Reads Kiwoom's token expiry, yyyyMMddHHmmss in Korean time.
| text | The text. |
Definition at line 65 of file config.hpp.
Referenced by algotradelib::kiwoom::KiwoomRest::from_json_impl(), and parse_compact_expiry().
|
inlinenoexcept |
Looks up an order shape by Kiwoom's numeric trde_tp code.
| code | The code. |
Definition at line 628 of file client.hpp.
Referenced by shape_by_code().
|
inlinenoexcept |
Looks up an order shape by the Korean name a response gives (either listing's spelling).
| name | The name. |
Definition at line 611 of file client.hpp.
Referenced by shape_by_name().
|
inlineconstexprnoexcept |
Returns the symbol suffix for a tape.
| tape | The tape. |
Definition at line 47 of file config.hpp.
Referenced by tape_suffix(), and algotradelib::kiwoom::KiwoomConfig::tape_symbol().
|
inline |
Returns today's date in Korea (UTC+9), the date Kiwoom requests are made in.
Definition at line 154 of file client.hpp.
Referenced by today_in_seoul().
|
inline |
Makes the error that refuses a new order or an amendment while KiwoomConfig::holdings_position_scope_ is not stated.
Without it the library cannot establish what the account holds, so an order could be sized against an empty portfolio. An amendment is refused too, since repricing can make a resting order fill. Cancellations, including cancel_quantity(), are never refused. The client applies it to every placement and amendment, however they arrive.
Definition at line 183 of file client.hpp.
Referenced by unestablished_holdings_scope().
|
inline |
Refuses a bar interval this client requests no chart for (chart_api_id).
| interval | The interval. |
Definition at line 797 of file client.hpp.
Referenced by unsupported_bar_interval().
|
inline |
Refuses an idempotency key, which Kiwoom does not offer (an order carrying client_order_id_ is refused before sending).
| order | The order. |
Definition at line 208 of file client.hpp.
Referenced by unsupported_client_order_id().
|
inline |
Tests whether a trigger price is one Kiwoom can carry (cond_uv, mdfy_cond_uv).
| trigger | The trigger price. |
Definition at line 227 of file client.hpp.
Referenced by invalid_trigger(), and valid_trigger_value().
|
inlineconstexpr |
Kiwoom's order-type (trde_tp) table, from its API specification.
시간외단일가 (after-hours single price) has no request code: it can be read, not placed. Kiwoom publishes no per-venue restriction, so a venue-specific refusal comes from Kiwoom with its own code.
Definition at line 537 of file client.hpp.
Referenced by order_division(), shape_by_code(), and shape_by_name().