pub struct AlorConfig {
pub refresh_token: String,
pub request_timeout: Duration,
pub env: AlorEnv,
pub http_base_url: String,
pub auth_base_url: String,
pub ws_base_url: String,
pub portfolio: Option<String>,
pub exchange: String,
}Expand description
Configuration of the HTTP and WebSocket clients.
The one secret in it is the refresh token, which you issue on the developer portal after binding a trade account (it lives a year in the production contour and a month in the test one). The broker has no separate read and trade tokens: the access token made from it reaches everything the account may do.
The Debug output hides the refresh token (<redacted>), so a config can be logged.
§Examples
use brokapi_alor_protocol::config::{AlorConfig, AlorEnv};
let cfg = AlorConfig::new("my-refresh-token".to_string()).with_portfolio("D12345");
assert_eq!(cfg.env, AlorEnv::Production);
assert_eq!(cfg.portfolio.as_deref(), Some("D12345"));
assert_eq!(cfg.exchange, "MOEX");
assert_eq!(cfg.request_timeout.as_secs(), 30);
// The test contour switches all three addresses at once.
let test = cfg.with_env(AlorEnv::Test);
assert_eq!(test.http_base_url, "https://apidev.alor.ru");
assert_eq!(test.auth_base_url, "https://oauthdev.alor.ru");Fields§
§refresh_token: StringThe long-lived refresh token from the developer portal.
request_timeout: DurationTimeout of one REST request, from sending to the end of the body (default 30 seconds). A request
that times out ends with AlorApiError::Http and no status.
For an order command that is an unknown outcome: ask the broker before you send it again.
env: AlorEnvThe contour. Set by AlorConfig::with_env, which also sets the three addresses below.
http_base_url: StringBase URL of the REST API, without a trailing slash.
auth_base_url: StringBase URL of the authorization server, without a trailing slash.
ws_base_url: StringBase URL of the WebSocket API, without a trailing slash. The channels are /ws and /cws.
portfolio: Option<String>The portfolio the user data connector works with (for example D12345). If it is empty, the connector
takes the only portfolio named in the access token, and refuses to start when the token names several.
exchange: StringThe exchange of the portfolio: MOEX (default) or SPBX. Orders, positions and trades are read per
exchange, so one connector works with one.
Implementations§
Source§impl AlorConfig
impl AlorConfig
Sourcepub fn new(refresh_token: String) -> Self
pub fn new(refresh_token: String) -> Self
A configuration for the production contour from a refresh token.
§Examples
use brokapi_alor_protocol::config::AlorConfig;
let cfg = AlorConfig::new("t".to_string());
assert!(cfg.http_base_url.starts_with("https://"));
assert!(cfg.ws_base_url.starts_with("wss://"));Sourcepub fn from_env() -> Result<Self, VarError>
pub fn from_env() -> Result<Self, VarError>
Reads the configuration from the environment (and from a .env file of the working directory, if
there is one; variables that are already set win).
ALOR_REFRESH_TOKEN: required.ALOR_PORTFOLIO: optional, seeAlorConfig::portfolio.ALOR_EXCHANGE: optional,MOEX(default) orSPBX.ALOR_ENV: optional, the exact texttestselects the test contour.
No network call is made.
§Errors
std::env::VarError::NotPresent when ALOR_REFRESH_TOKEN is not set. A wrong or expired token shows
up as AlorApiError::Auth at the first request.
§Examples
use brokapi_alor_protocol::config::AlorConfig;
match AlorConfig::from_env() {
Ok(cfg) => assert_eq!(cfg.request_timeout.as_secs(), 30),
Err(std::env::VarError::NotPresent) => { /* ALOR_REFRESH_TOKEN is not set */ }
Err(other) => panic!("unexpected: {other}"),
}Sourcepub fn from_env_file(path: impl AsRef<Path>) -> Result<Self, VarError>
pub fn from_env_file(path: impl AsRef<Path>) -> Result<Self, VarError>
Like AlorConfig::from_env, but loads the .env file at path (a file that is not there is skipped).
§Errors
The same as AlorConfig::from_env.
Sourcepub fn with_env(self, env: AlorEnv) -> Self
pub fn with_env(self, env: AlorEnv) -> Self
Points all three addresses at the production or the test contour. Returns the changed config.
Sourcepub fn with_portfolio(self, portfolio: impl Into<String>) -> Self
pub fn with_portfolio(self, portfolio: impl Into<String>) -> Self
Sets the portfolio (see AlorConfig::portfolio). Returns the changed config.
Sourcepub fn with_exchange(self, exchange: impl Into<String>) -> Self
pub fn with_exchange(self, exchange: impl Into<String>) -> Self
Sets the exchange, MOEX or SPBX (see AlorConfig::exchange). Returns the changed config.
Sourcepub fn for_mock(
refresh_token: impl Into<String>,
http_base_url: impl Into<String>,
) -> Self
pub fn for_mock( refresh_token: impl Into<String>, http_base_url: impl Into<String>, ) -> Self
Points the REST, authorization and WebSocket clients at one local server, for tests and examples.
http_base_url is the base of the local server (for example http://127.0.0.1:34567). The
authorization server is the same host, and the WebSocket base is derived by swapping the scheme. The token
is only a label for the imitation, it is never sent to the real broker. The portfolio is D00001.
§Examples
use brokapi_alor_protocol::config::AlorConfig;
let cfg = AlorConfig::for_mock("mock-refresh-token", "http://127.0.0.1:9000");
assert_eq!(cfg.auth_base_url, "http://127.0.0.1:9000");
assert_eq!(cfg.ws_base_url, "ws://127.0.0.1:9000");Trait Implementations§
Source§impl Clone for AlorConfig
impl Clone for AlorConfig
Source§fn clone(&self) -> AlorConfig
fn clone(&self) -> AlorConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more