algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
kis_credentials.hpp File Reference

The examples' KIS credentials: one JSON file per account, or the environment. More...

#include <algotradelib/kis>
#include <cstdlib>
#include <filesystem>
#include <optional>
#include <ostream>
#include <stdexcept>
#include <string>
#include <string_view>
Include dependency graph for kis_credentials.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::optional< std::filesystem::path > kis_credentials::environment_directory ()
 Returns ATL_CREDENTIALS_DIR, for an example that parses no arguments of its own.
std::optional< std::filesystem::path > kis_credentials::take_directory (int &argc, char **argv)
 Removes --credentials DIR from the command line and returns the directory, else ATL_CREDENTIALS_DIR.
algotradelib::network::HttpClientOptions kis_credentials::paced_options ()
 Returns transport options that pace a KIS client at one request a second.
std::filesystem::path kis_credentials::required_file (const std::filesystem::path &directory, const char *name)
 Returns the path of a credential file in the directory.
void kis_credentials::load_config (algotradelib::kis::KisConfig &config, const std::filesystem::path &path, bool demo)
 Loads a configuration from a file and refuses one whose "demo" contradicts its name.
void kis_credentials::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 variables", never a key).
std::optional< algotradelib::kis::KisConfig > kis_credentials::market_data_config (const std::optional< std::filesystem::path > &directory)
 Returns a configuration for market data alone, from DIR/kis/real.json.

Detailed Description

The examples' KIS credentials: one JSON file per account, or the environment.

Not part of the library. With a credentials directory – --credentials DIR on the command line, else ATL_CREDENTIALS_DIR – the examples read DIR/kis/demo.json or DIR/kis/real.json, as KIS_DEMO chooses (unset or 1: demo; 0: real). Without one they read the environment variables, as before. A directory that is given but lacks the file stops the program: it never falls back to the environment, which may hold the other account's keys.

Each file holds app_key, app_secret, account_number, account_product_code and demo (KisConfig::from_json, KisAccount::from_json). Keep it chmod 600.

Definition in file kis_credentials.hpp.

Function Documentation

◆ environment_directory()

std::optional< std::filesystem::path > kis_credentials::environment_directory ( )
inline

Returns ATL_CREDENTIALS_DIR, for an example that parses no arguments of its own.

Returns
The directory, or std::nullopt if the variable is unset.
Exceptions
std::runtime_errorif it is set but empty.

Definition at line 34 of file kis_credentials.hpp.

◆ load()

void kis_credentials::load ( const std::optional< std::filesystem::path > & directory,
algotradelib::kis::KisConfig & config,
algotradelib::kis::KisAccount * account,
std::ostream & out )
inline

Loads the credentials (and account) KIS_DEMO chooses, and prints where from (a path or "environment variables", never a key).

Parameters
directoryThe credentials directory, or std::nullopt to read the environment.
configThe configuration to load into.
accountThe account to load into, or null.
outWhere to print the source.
Exceptions
std::runtime_errorif the file or variables are missing or invalid.

Definition at line 129 of file kis_credentials.hpp.

◆ load_config()

void kis_credentials::load_config ( algotradelib::kis::KisConfig & config,
const std::filesystem::path & path,
bool demo )
inline

Loads a configuration from a file and refuses one whose "demo" contradicts its name.

Parameters
configThe configuration to load into.
pathThe file.
demoWhether the file is the demo one.
Exceptions
std::runtime_errorif the file cannot be loaded or contradicts its name.

Definition at line 110 of file kis_credentials.hpp.

◆ market_data_config()

std::optional< algotradelib::kis::KisConfig > kis_credentials::market_data_config ( const std::optional< std::filesystem::path > & directory)
inline

Returns a configuration for market data alone, from DIR/kis/real.json.

Pair it with an empty KisAccount, which refuses every account request and order before any I/O.

Parameters
directoryThe credentials directory.
Returns
The configuration, or std::nullopt if there is no directory or no such file.
Exceptions
std::runtime_errorif the file exists but cannot be loaded or is not a real-account file.

Definition at line 161 of file kis_credentials.hpp.

◆ paced_options()

algotradelib::network::HttpClientOptions kis_credentials::paced_options ( )
inline

Returns transport options that pace a KIS client at one request a second.

A KIS demo account refuses reads closer than about a second apart (EGW00201), and with real keys the holiday calendar was refused at eight a second. The library paces nothing unless asked (HttpClientOptions::rate_limit_), so these examples ask. A key with a larger allowance may raise it.

Returns
The options.

Definition at line 80 of file kis_credentials.hpp.

◆ required_file()

std::filesystem::path kis_credentials::required_file ( const std::filesystem::path & directory,
const char * name )
inline

Returns the path of a credential file in the directory.

Parameters
directoryThe credentials directory.
nameThe file name, such as "demo.json".
Returns
directory/kis/name.
Exceptions
std::runtime_errorif the file does not exist (the environment is not read instead).

Definition at line 93 of file kis_credentials.hpp.

◆ take_directory()

std::optional< std::filesystem::path > kis_credentials::take_directory ( int & argc,
char ** argv )
inline

Removes --credentials DIR from the command line and returns the directory, else ATL_CREDENTIALS_DIR.

Parameters
argcThe argument count; reduced by the arguments removed.
argvThe arguments; the rest are moved down.
Returns
The directory, or std::nullopt if neither names one.
Exceptions
std::runtime_errorif --credentials has no usable value (missing, empty, or another flag), so a mistyped command never falls back to another source, or if no --credentials is given and ATL_CREDENTIALS_DIR is set but empty.

Definition at line 52 of file kis_credentials.hpp.