9#include <algotradelib/kiwoom>
11#include <boost/asio/ssl/context.hpp>
20namespace net = boost::asio;
21namespace ssl = net::ssl;
26std::string mask_account_number(std::string_view account_number) {
27 if (account_number.size() <= 4) {
28 return std::string(account_number.size(),
'*');
30 return std::string(account_number.size() - 4,
'*') +
31 std::string(account_number.substr(account_number.size() - 4));
36int main(
int argc,
char** argv) {
58 ssl::context tls(ssl::context::tls_client);
59 tls.set_default_verify_paths();
60 tls.set_verify_mode(ssl::verify_peer);
62 BlockingSession<KiwoomBlockingClient> session(
68 BrokerCaps<KiwoomBlockingClient>::has_account_discovery,
69 "Kiwoom publishes the account its credential drives"
71 const auto accounts = session.accounts();
73 std::cerr <<
"account listing failed: " << accounts.error().message_ <<
'\n';
76 for (
const auto& account : accounts.value()) {
77 std::cout <<
"account: " << mask_account_number(account.display_number_) <<
'\n';
93 std::cerr <<
"holdings failed: " << holdings.error().message_ <<
'\n';
96 std::cout <<
"holdings as Kiwoom reported them for one venue:\n";
97 for (
const auto& position : holdings.value().positions_) {
98 std::cout << position.instrument_.symbol_ <<
' ' << position.name_ <<
' '
99 << position.quantity_.str();
100 if (position.sellable_quantity_) {
101 std::cout <<
" (sellable " << position.sellable_quantity_->str() <<
')';
108 std::cerr <<
"buying power failed: " << budget.error().message_ <<
'\n';
113 std::cout <<
"spendable: " << budget.value().cash_.amount_.str() <<
' '
114 << budget.value().cash_.currency_.str() <<
'\n';
116 }
catch (
const std::exception& exception) {
117 std::cerr <<
"example failed: " << exception.what() <<
'\n';
A blocking broker client bound to one account, with the same broker operations as BrokerSession,...
static Currency krw()
Returns Korean won.
A blocking Kiwoom client: each call runs a KiwoomClient request on a private event loop and returns i...
std::optional< std::filesystem::path > take_directory(int &argc, char **argv)
Removes --credentials DIR from the command line and returns the directory, else ATL_CREDENTIALS_DIR.
The examples' Kiwoom credentials: one JSON file per key, or the environment.
void refuse_unknown_flags(int argc, char **argv)
Refuses any flag left on the command line after the credential flags were taken, so a mistyped --kiwo...
algotradelib::network::HttpClientOptions paced_options()
Returns transport options that pace a Kiwoom client at one request a second.
std::optional< std::string > take_label(int &argc, char **argv)
Removes --kiwoom-account LABEL from the command line and returns the label.
void load(const std::optional< std::filesystem::path > &directory, const std::optional< std::string > &label, algotradelib::kiwoom::KiwoomConfig &config, std::ostream &out)
Loads the credentials from DIR/kiwoom/{demo,real}-LABEL.json (as KIWOOM_DEMO chooses; label kr by def...
What one broker client implements, as compile-time constants.
The Kiwoom account selector, which is empty: no Kiwoom endpoint takes an account number,...
Kiwoom credentials (app key and secret key), demo or real account, the market-data tape,...
Venue holdings_venue_
The venue holdings requests (kt00018) name: Venue::KRX or Venue::NXT. No default: holdings requests a...