3#include <algotradelib/kis>
5#include <boost/asio/ssl/context.hpp>
12namespace ssl = boost::asio::ssl;
16void print_error(std::string_view operation,
const algotradelib::BrokerError& error) {
17 std::cerr << operation <<
" failed";
30void print_holdings(
const algotradelib::HoldingsSnapshot& snapshot) {
31 std::cout <<
"positions: " << snapshot.
positions_.size() <<
'\n';
32 for (
const auto& position : snapshot.
positions_) {
33 std::cout << position.instrument_.symbol_ <<
" " << position.name_ <<
'\n';
34 std::cout <<
" quantity: " << position.quantity_.str();
35 if (position.sellable_quantity_) {
36 std::cout <<
" (sellable " << position.sellable_quantity_->str() <<
')';
39 std::cout <<
" last price: " << position.last_price_.str() <<
' '
40 << position.market_value_.currency_.str() <<
'\n';
41 std::cout <<
" market value: " << position.market_value_.amount_.str() <<
' '
42 << position.market_value_.currency_.str() <<
'\n';
43 std::cout <<
" unrealized P/L: " << position.unrealized_profit_loss_.amount_.str() <<
' '
44 << position.unrealized_profit_loss_.currency_.str() <<
'\n';
47 std::cout <<
"totals: " << snapshot.
totals_.size() <<
'\n';
48 for (
const auto& total : snapshot.
totals_) {
49 std::cout << total.currency_.str() <<
" purchase=" << total.purchase_value_.str()
50 <<
" market=" << total.market_value_.str()
51 <<
" unrealized=" << total.unrealized_profit_loss_.str() <<
'\n';
57int main(
int argc,
char* argv[]) {
63 std::cout <<
"environment: " << (config.
is_demo_ ?
"demo" :
"live") <<
'\n';
65 ssl::context tls(ssl::context::tls_client);
66 tls.set_default_verify_paths();
67 tls.set_verify_mode(ssl::verify_peer);
70 auto result = client.holdings(std::move(account));
72 print_error(
"holdings request", result.error());
76 print_holdings(result.value());
78 }
catch (
const std::exception& exception) {
79 std::cerr <<
"example failed: " << exception.what() <<
'\n';
A blocking KIS client: each call runs a KisClient request on a private event loop and returns its res...
The examples' KIS credentials: one JSON file per account, or the environment.
algotradelib::network::HttpClientOptions paced_options()
Returns transport options that pace a KIS client at one request a second.
void load(const std::optional< std::filesystem::path > &directory, algotradelib::kis::KisConfig &config, algotradelib::kis::KisAccount *account, std::ostream &out)
Loads the credentials (and account) KIS_DEMO chooses, and prints where from (a path or "environment v...
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.
int http_status_
The HTTP status of the reply: set for an HTTP error and for a reply whose body is not a JSON object....
std::string message_
A human-readable description, for logs; do not parse it.
std::string broker_code_
The broker's own error code, verbatim (for example KIS's EGW00201).
std::vector< HoldingsTotals > totals_
One totals row per currency held.
std::vector< HoldingPosition > positions_
Every position row; one instrument may appear in more than one.
A KIS account: the account number and product code every account request names.
KIS credentials (app key and secret), demo or real account, and the market-data tape.
bool is_demo_
Whether to use KIS's demo (모의투자) endpoints; true unless stated otherwise.