![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
Alpaca API keys (key id and secret key), paper or live account. More...
#include <algotradelib/src/brokers/alpaca/config.hpp>
Public Member Functions | |
| void | from_env_impl () |
| Reads the keys from ALPACA_KEY and ALPACA_SECRET, and the environment from ALPACA_DEMO (see demo_from_env); called by from_env(). Nothing changes if it throws. | |
| void | from_json_impl (const std::string &filename) |
| Reads the keys from a JSON file; called by from_json(filename). Nothing changes if it throws. | |
| void | from_json_text_impl (std::string_view text, const std::string &origin) |
| Reads the keys from JSON text in the file's format; called by from_json_text. Nothing changes if it throws. | |
| const char * | trading_host () const noexcept |
| The trading host for the selected environment. | |
| const char * | data_host () const noexcept |
| The market-data host, the same for both environments. | |
| const char * | port () const noexcept |
| The HTTPS port, the same for every host. | |
| Public Member Functions inherited from algotradelib::network::ClientCredentials< AlpacaConfig > | |
| void | from_env () |
| Loads the credentials from the broker's environment variables. | |
| void | from_json (const std::string &filename) |
| Loads the credentials from a JSON file, in the broker's format. | |
| void | from_json_text (std::string_view text, const std::string &origin) |
| Loads the credentials from JSON text in the broker's format, as from_json reads a file's contents, for credentials kept somewhere other than a file (a system credential store). | |
| const std::string & | key () const noexcept |
| Returns the app key (client id). | |
| const std::string & | secret () const noexcept |
| Returns the app secret. | |
| std::string | to_jsonbody () const |
| Builds a JSON token-request body (grant type, key and secret under the broker's field names). | |
| std::string | to_form_urlencoded_body () const |
| Builds a form-encoded token-request body (grant_type, client_id, client_secret). | |
Static Public Member Functions | |
| static bool | demo_from_env () |
| Reads ALPACA_DEMO. | |
| static bool | demo_from_json (const json::object &doc, const std::string &origin) |
| Reads a credential document's "demo". | |
| static constexpr std::string_view | key_field () noexcept |
| The credential file's field for the key id; Alpaca has no token request behind it. | |
| static constexpr std::string_view | secret_field () noexcept |
| The credential file's field for the secret key; Alpaca has no token request behind it. | |
Public Attributes | |
| bool | is_demo_ = true |
| Whether to use Alpaca's paper trading host; true unless stated otherwise. | |
Additional Inherited Members | |
| Static Public Attributes inherited from algotradelib::network::ClientCredentials< AlpacaConfig > | |
| static constexpr std::string_view | grant_type |
| The OAuth grant type sent in a token request. | |
| Protected Attributes inherited from algotradelib::network::ClientCredentials< AlpacaConfig > | |
| std::string | key_ |
| The app key (client id). | |
| std::string | secret_ |
| The app secret. | |
Alpaca API keys (key id and secret key), paper or live account.
Load with from_env() (ALPACA_KEY, ALPACA_SECRET, ALPACA_DEMO), from_json(filename) or from_json_text(text, origin). Alpaca has no token: both keys go on every request as headers, so nothing is requested or stored before a call. Paper and live keys differ, and a key sent to the other environment's host is refused (HTTP 401) at its first request, so a forgotten setting fails rather than trades.
Definition at line 30 of file config.hpp.
|
inlinenoexcept |
The market-data host, the same for both environments.
Definition at line 172 of file config.hpp.
|
inlinestatic |
Reads ALPACA_DEMO.
| std::runtime_error | for any other value. |
Definition at line 108 of file config.hpp.
Referenced by from_env_impl().
|
inlinestatic |
Reads a credential document's "demo".
| doc | The document. |
| origin | What the error message calls the source. |
| std::runtime_error | if it is not a boolean. |
Definition at line 129 of file config.hpp.
Referenced by from_json_text_impl().
|
inline |
Reads the keys from ALPACA_KEY and ALPACA_SECRET, and the environment from ALPACA_DEMO (see demo_from_env); called by from_env(). Nothing changes if it throws.
| std::runtime_error | if a key variable is missing or ALPACA_DEMO is invalid. |
Definition at line 45 of file config.hpp.
|
inline |
Reads the keys from a JSON file; called by from_json(filename). Nothing changes if it throws.
Format: { "key_id": "...", "secret_key": "...", "demo": false }; without "demo" the config is paper.
| filename | The file. |
| std::runtime_error | if the file cannot be read or parsed, a key is missing or not a string, or "demo" is not a boolean. |
Definition at line 67 of file config.hpp.
|
inline |
Reads the keys from JSON text in the file's format; called by from_json_text. Nothing changes if it throws.
| text | The JSON document. |
| origin | What error messages call the source ("file creds.json"); not a secret. |
| std::runtime_error | if the text cannot be parsed, a key is missing or not a string, or "demo" is not a boolean. |
Definition at line 84 of file config.hpp.
Referenced by from_json_impl().
|
inlinestaticconstexprnoexcept |
The credential file's field for the key id; Alpaca has no token request behind it.
Definition at line 148 of file config.hpp.
|
inlinenoexcept |
|
inlinestaticconstexprnoexcept |
The credential file's field for the secret key; Alpaca has no token request behind it.
Definition at line 156 of file config.hpp.
|
inlinenoexcept |
The trading host for the selected environment.
Definition at line 164 of file config.hpp.
| bool algotradelib::alpaca::AlpacaConfig::is_demo_ = true |
Whether to use Alpaca's paper trading host; true unless stated otherwise.
Live trading must be stated: ALPACA_DEMO=0, "demo": false in the credential file, or is_demo_ = false. Live is the same code path as paper and differs only in the trading host; it is supported, but the library's own checks ran on paper only.
Definition at line 38 of file config.hpp.
Referenced by from_env_impl(), from_json_text_impl(), and trading_host().