algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
example-tossinvest-auth.cpp
1#include <algotradelib/tossinvest>
2#include <iostream>
3#include <string>
4
5namespace beast = boost::beast;
6namespace http = boost::beast::http;
7namespace net = boost::asio;
8namespace ssl = net::ssl;
9
10int main() {
11 // Load credentials from environment variables:
12 // export TOSS_CLIENT_ID=c_01HXYZABCDEFG123456789
13 // export TOSS_CLIENT_SECRET=xxxxxxxx...
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}
void from_env()
Loads the credentials from the broker's environment variables.
Definition oauth.hpp:46
Obtains and caches a Toss access token with blocking requests; thread-safe.
Definition auth.hpp:18
Toss Securities credentials (client id and secret). Toss has no demo environment.
Definition config.hpp:24