Skip to main content

Module raw

Module raw 

Source
Expand description

Direct access to any ALOR API method (the “back door”): same refresh token and access token, same endpoint, same [BrokerLimiter] as the connector it came from.

The connectors wrap what the shared traits can express. Everything else (quotations of many instruments, the summary and the risks of the portfolio, order groups, estimates, order cancel for all, the legacy stop-loss family, the other subscriptions of the data channel, the trading channel) is reachable here. Get a handle with raw() on either connector.

Rules of a call:

  1. The quota is taken first, by the operation name ("GetQuotes"), from the route in limits.toml. A name without a route spends the "*" default route, so a call is never free. A refusal is [Error::RateLimited] and the request is not sent.
  2. The closure gets the connector’s [AlorHttpClient]: it holds the access token, refreshes it and repeats a read once after a 401. One closure is one API method.
  3. call is for reads. call_command is for anything that changes the account: a break, a timeout or a 5xx is [Error::Unknown], and it is never retried.
  4. connect_ws opens one more session of the data channel and connect_cws one of the trading channel, with the same token.

The raw layer does not know about the connector’s order state: orders placed through it are not tracked (no events, no reconcile). Use the shared traits for orders.

§Examples

A read that no shared trait wraps, the quotations of several instruments, through the market data connector:

use brokapi_alor::limits::default_limits;
use brokapi_alor::{MarketDataConfig, MarketDataConnector};
use brokapi_core::ShutdownMode;
use brokapi_runtime::BrokerLimiter;
use tokio::sync::mpsc;

let (events_tx, _events) = mpsc::channel(256);
let limiter = BrokerLimiter::new(&default_limits());
let md = MarketDataConnector::start(MarketDataConfig::new(cfg, "alor-md"), limiter, events_tx).await?;

let raw = md.raw();
// "GetQuotes" is the name of the quota route. The closure is one API method.
let quotes = raw
    .call("GetQuotes", |http| async move { http.get_quotes(&[("MOEX", "SBER")]).await })
    .await?;
for q in &quotes {
    println!("{} bid {:?} ask {:?}", q.symbol, q.bid, q.ask);
}
md.shutdown(ShutdownMode::Immediate).await;

Structs§

AlorRaw
A handle for calling any ALOR API method with a connector’s token and rate limiter.