algotradelib
0.0.0.9000
C++ header-only library for algorithmic trading
Toggle main menu visibility
Loading...
Searching...
No Matches
example-tossinvest-quote.cpp
1
#include <algotradelib/tossinvest>
2
3
#include <boost/asio/io_context.hpp>
4
#include <boost/asio/ssl/context.hpp>
5
6
#include <exception>
7
#include <iostream>
8
#include <memory>
9
#include <string>
10
#include <utility>
11
12
namespace
net = boost::asio;
13
namespace
ssl = net::ssl;
14
15
int
main(
int
argc,
char
* argv[]) {
16
const
std::string symbol = argc > 1 ? argv[1] :
"005930"
;
17
18
try
{
19
algotradelib::tossinvest::TossConfig
config;
20
config.
from_env
();
21
22
std::cout <<
"broker: Toss Securities"
<<
"\n"
;
23
std::cout <<
"symbol: "
<< symbol <<
'\n'
;
24
25
net::io_context ioc;
26
ssl::context tls(ssl::context::tls_client);
27
tls.set_default_verify_paths();
28
tls.set_verify_mode(ssl::verify_peer);
29
30
auto
client = std::make_shared<algotradelib::tossinvest::TossClient>(ioc.get_executor(), tls, std::move(config));
31
int
exit_code = 1;
32
client->async_quote(
33
{algotradelib::Country::KR, algotradelib::Venue::COMBINED, symbol},
34
[&exit_code](
algotradelib::Result<algotradelib::QuoteSnapshot>
result) {
35
if
(!result) {
36
const
auto
& error = result.error();
37
std::cerr <<
"quote failed"
;
38
if
(!error.broker_code_.empty()) {
39
std::cerr <<
" ["
<< error.broker_code_ <<
']'
;
40
}
41
if
(!error.request_id_.empty()) {
42
std::cerr <<
" request="
<< error.request_id_;
43
}
44
if
(error.http_status_ != 0) {
45
std::cerr <<
" HTTP "
<< error.http_status_;
46
}
47
if
(!error.message_.empty()) {
48
std::cerr <<
": "
<< error.message_;
49
}
50
std::cerr <<
'\n'
;
51
return
;
52
}
53
54
const
auto
&
quote
= result.value();
55
std::cout
56
<<
quote
.instrument_.symbol_ <<
' '
<<
quote
.last_price_.str() <<
' '
<<
quote
.currency_.str() <<
'\n'
;
57
exit_code = 0;
58
}
59
);
60
ioc.run();
61
return
exit_code;
62
}
catch
(
const
std::exception& exception) {
63
std::cerr <<
"example failed: "
<< exception.what() <<
'\n'
;
64
return
1;
65
}
66
}
algotradelib::Result
Either a value or a BrokerError.
Definition
types.hpp:1058
algotradelib::network::ClientCredentials::from_env
void from_env()
Loads the credentials from the broker's environment variables.
Definition
oauth.hpp:47
algotradelib::strategy::dispatch::quote
void quote(S &strategy, Ctx &context, const QuoteEvent &event)
Calls strategy.on_quote(context, event) if the strategy declares on_quote; otherwise does nothing.
Definition
concept.hpp:331
algotradelib::tossinvest::TossConfig
Toss Securities credentials (client id and secret). Toss has no demo environment.
Definition
config.hpp:27
examples
example-tossinvest-quote.cpp
Generated by
1.18.0