Skip to main content

Module raw

Module raw 

Source
Expand description

Direct access to any BCS 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 (quotes snapshot, non-trade operations, limits, instrument discounts, the limits and marginal-indicators WebSockets, …) 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 ("GetOperationHistory"), 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 [BcsHttpClient]: it holds the access token, refreshes it and repeats a request 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 of the WebSocket channels 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 quotes snapshot, through the market data connector:

use brokapi_bcs_protocol::http::models::{QuoteInstrument, QuotesRequest};
use brokapi_bcs::limits::default_limits;
use brokapi_bcs::{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, "bcs-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(&QuotesRequest { instruments: vec![QuoteInstrument::new("SBER", "TQBR")] }).await
    })
    .await?;
for q in &quotes.records {
    println!("{:?} bid {:?} offer {:?}", q.ticker, q.bid, q.offer);
}
md.shutdown(ShutdownMode::Immediate).await;

Structs§

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