algotradelib
0.0.0.9000
C++ header-only library for algorithmic trading
Toggle main menu visibility
Loading...
Searching...
No Matches
example-tossinvest-auth.cpp
1
#include <algotradelib/tossinvest>
2
#include <iostream>
3
#include <string>
4
5
namespace
beast = boost::beast;
6
namespace
http = boost::beast::http;
7
namespace
net = boost::asio;
8
namespace
ssl = net::ssl;
9
10
int
main() {
11
// Load credentials from environment variables:
12
// export TOSS_CLIENT_ID=c_01HXYZABCDEFG123456789
13
// export TOSS_CLIENT_SECRET=xxxxxxxx...
14
algotradelib::tossinvest::TossConfig
cfg;
15
try
{
16
cfg.
from_env
();
17
}
catch
(
const
std::exception& e) {
18
std::cerr <<
"[error] "
<< e.what() <<
"\n"
;
19
return
1;
20
}
21
22
net::io_context ioc;
23
ssl::context ctx(ssl::context::tlsv12_client);
// TLS 1.2 or 1.3
24
ctx.set_default_verify_paths();
25
ctx.set_verify_mode(ssl::verify_peer);
26
algotradelib::tossinvest::TossAuth
auth(ioc, ctx, cfg);
27
28
std::cout <<
"Fetching access token ..."
;
29
try
{
30
(void)auth.accessToken();
31
std::cout <<
" OK"
<<
"\n\n"
;
32
}
catch
(
const
std::exception& e) {
33
std::cerr <<
" FAIL: "
<< e.what() <<
"\n\n"
;
34
return
1;
35
}
36
37
return
0;
38
}
algotradelib::network::ClientCredentials::from_env
void from_env()
Loads the credentials from the broker's environment variables.
Definition
oauth.hpp:46
algotradelib::tossinvest::TossAuth
Obtains and caches a Toss access token with blocking requests; thread-safe.
Definition
auth.hpp:18
algotradelib::tossinvest::TossConfig
Toss Securities credentials (client id and secret). Toss has no demo environment.
Definition
config.hpp:24
examples
example-tossinvest-auth.cpp
Generated by
1.18.0