7#include <algotradelib/kiwoom>
9#include <boost/asio/io_context.hpp>
10#include <boost/asio/ssl/context.hpp>
18namespace net = boost::asio;
19namespace ssl = net::ssl;
21int main(
int argc,
char* argv[]) {
27 const std::string symbol = argc > 1 ? argv[1] :
"005930";
31 std::cout <<
"environment: " << (config.
is_demo_ ?
"demo" :
"live") <<
'\n';
32 std::cout <<
"symbol: " << symbol <<
'\n';
38 ssl::context tls(ssl::context::tls_client);
39 tls.set_default_verify_paths();
40 tls.set_verify_mode(ssl::verify_peer);
42 auto client = std::make_shared<algotradelib::kiwoom::KiwoomClient>(
43 ioc.get_executor(), tls, std::move(config)
47 {algotradelib::Country::KR, algotradelib::Venue::COMBINED, symbol},
50 const auto& error = result.error();
51 std::cerr <<
"quote failed";
52 if (!error.broker_code_.empty()) {
53 std::cerr <<
" [" << error.broker_code_ <<
']';
55 if (error.http_status_ != 0) {
56 std::cerr <<
" HTTP " << error.http_status_;
58 if (!error.message_.empty()) {
59 std::cerr <<
": " << error.message_;
65 const auto&
quote = result.value();
66 std::cout <<
quote.instrument_.symbol_ <<
' ' <<
quote.last_price_.str() <<
' '
67 <<
quote.currency_.str() <<
'\n';
69 std::cout <<
"volume: " <<
quote.volume_->str() <<
'\n';
71 if (
quote.top_of_book_) {
72 const auto& top = *
quote.top_of_book_;
73 std::cout <<
"bid: " << (top.bid_price_ ? top.bid_price_->str() :
"-") <<
" x "
74 << (top.bid_quantity_ ? top.bid_quantity_->str() :
"-") <<
'\n';
75 std::cout <<
"ask: " << (top.ask_price_ ? top.ask_price_->str() :
"-") <<
" x "
76 << (top.ask_quantity_ ? top.ask_quantity_->str() :
"-") <<
'\n';
83 }
catch (
const std::exception& exception) {
84 std::cerr <<
"example failed: " << exception.what() <<
'\n';
Either a value or a BrokerError.
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...
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...
constexpr const char * tape_suffix(MarketTape tape) noexcept
Returns the symbol suffix for a tape.
void quote(S &strategy, Ctx &context, const QuoteEvent &event)
Calls strategy.on_quote(context, event) if the strategy declares on_quote; otherwise does nothing.
Kiwoom credentials (app key and secret key), demo or real account, the market-data tape,...
bool is_demo_
Whether to use Kiwoom's demo (모의투자) endpoints; true unless stated otherwise.
MarketTape market_tape_
Which venue's prices every Kiwoom market-data request reads (quotes, depth, trades,...