Skip to main content

Module raw

Module raw 

Expand description

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

The connectors wrap what the shared traits can express. Everything else the API offers (bond coupons, forecasts, favorites, reports, signals, sandbox, …) is reachable here, so nothing the broker supports is out of reach.

§Examples

The example runs against the in-process mock. With a real connector the call is the same, only the config differs. For a method of your own, pass its proto name and call the generated client.

use brokapi_runtime::BrokerLimiter;
use brokapi_tbank::limits::default_limits;
use brokapi_tbank::{MarketDataConfig, MarketDataConnector};
use brokapi_tbank_protocol::v1 as pb;
use tokio::sync::mpsc;

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

// The quota is taken by the proto method name, then the call runs with the connector's token.
let accounts = raw
    .call("GetAccounts", |c| async move {
        c.users().get_accounts(pb::GetAccountsRequest { status: None }).await
    })
    .await?;
assert!(!accounts.accounts.is_empty());

Rules of a call:

  1. The quota is taken first, by the proto method name ("GetBondCoupons"), 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. One closure is one API method. Do not call several methods inside one closure: only one quota unit is taken for it.
  3. The answer is cut by the request timeout of the connector.
  4. Status codes become [brokapi_core::Error] like everywhere else in the connector.

call is for reads: timeout and transport trouble are retryable errors. call_command is for anything that changes the account: a timeout or a break is [Error::Unknown] (the broker may have acted), and the library never repeats it.

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

Structs§

TbankRaw
Direct access to any T-Bank API method, made by MarketDataConnector::raw or UserDataConnector::raw. See the module docs. Cheap to clone.