Skip to main content

Crate brokapi_tbank_protocol

Crate brokapi_tbank_protocol 

Source
Expand description

Low-level T-Bank (T-Invest) API wire protocol: the gRPC client generated from the official .proto.

This is the protocol layer of the T-Bank connector. It knows how to talk to the broker and nothing about orders, books or events. The connector crate brokapi-tbank sits on top of it and turns these messages into the shared brokapi-core types. Use this crate directly only when you need a call the connectors do not wrap.

  • v1 - generated messages, enums and gRPC clients. Every service and method of the official contract is generated. Their documentation comes from the .proto comments.
  • TbankConfig - endpoint (production, sandbox or a local mock), token, account, timeouts.
  • TbankClient - one shared HTTP/2 channel with Bearer-token authorization. Each accessor (for example TbankClient::orders) returns a ready generated client.
  • AuthInterceptor - the piece that adds authorization: Bearer <token> to every request.
  • money - Quotation and MoneyValue (units and nano) converted to and from Decimal, without f64 on the way.
  • ProtocolError - configuration and transport errors raised while building the channel.

The full guide is in the book: https://brokapi.ru/docs/.

§Examples

The example below starts the in-process T-Bank mock, builds a client for it and lists the accounts the token can see. Nothing touches the network and no money is involved.

use brokapi_tbank_protocol::{TbankClient, TbankConfig};

// In real code: `TbankConfig::sandbox("t.your-token")` or `TbankConfig::production(..)`.
let client = TbankClient::new(&cfg)?;
let accounts = client.list_accounts().await?;
assert!(!accounts.is_empty());
for account in &accounts {
    println!("account {}", account.id);
}

Re-exports§

pub use client::AuthInterceptor;
pub use client::Authed;
pub use client::TbankClient;
pub use config::PROD_ENDPOINT;
pub use config::SANDBOX_ENDPOINT;
pub use config::TbankConfig;
pub use error::ProtocolError;

Modules§

client
gRPC channel with Bearer-token authorization.
config
Client configuration: endpoint, token, account.
error
Protocol-level errors.
money
Quotation / MoneyValue (units + nano) <-> [Decimal], exactly.
v1
Messages, enums and gRPC clients generated from the official T-Bank .proto files.

Constants§

FILE_DESCRIPTOR_SET
The descriptors of every service and message of the API, as a serialized FileDescriptorSet (the .proto files this crate is built from, with their imports). Load it into a descriptor pool to call a method by its name, see TbankClient::grpc.