Skip to main content

AlorConfig

Struct AlorConfig 

Source
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: String

The long-lived refresh token from the developer portal.

§request_timeout: Duration

Timeout 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: AlorEnv

The contour. Set by AlorConfig::with_env, which also sets the three addresses below.

§http_base_url: String

Base URL of the REST API, without a trailing slash.

§auth_base_url: String

Base URL of the authorization server, without a trailing slash.

§ws_base_url: String

Base 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: String

The 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

Source

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://"));
Source

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, see AlorConfig::portfolio.
  • ALOR_EXCHANGE: optional, MOEX (default) or SPBX.
  • ALOR_ENV: optional, the exact text test selects 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}"),
}
Source

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.

Source

pub fn with_env(self, env: AlorEnv) -> Self

Points all three addresses at the production or the test contour. Returns the changed config.

Source

pub fn with_portfolio(self, portfolio: impl Into<String>) -> Self

Sets the portfolio (see AlorConfig::portfolio). Returns the changed config.

Source

pub fn with_exchange(self, exchange: impl Into<String>) -> Self

Sets the exchange, MOEX or SPBX (see AlorConfig::exchange). Returns the changed config.

Source

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

Source§

fn clone(&self) -> AlorConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AlorConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more