pub struct TbankClient { /* private fields */ }Expand description
Shared HTTP/2 channel. Cheap to clone; each accessor returns a fresh generated client.
All generated clients made from one TbankClient share one connection and one token. The
channel connects lazily and reconnects on failure, so TbankClient::new never blocks and never
fails because the server is down.
This type does not limit the request rate and does not apply request_timeout. The connectors in
brokapi-tbank do both. If you call the generated clients directly, you must keep to the broker’s
rate limits yourself.
§Examples
use brokapi_tbank_protocol::v1::GetAccountsRequest;
use brokapi_tbank_protocol::{TbankClient, TbankConfig};
let client = TbankClient::new(&cfg)?;
// Any method of the API is reachable through the generated clients.
let reply = client.users().get_accounts(GetAccountsRequest { status: None }).await?;
assert!(!reply.into_inner().accounts.is_empty());Implementations§
Source§impl TbankClient
impl TbankClient
Sourcepub fn new(cfg: &TbankConfig) -> Result<Self, ProtocolError>
pub fn new(cfg: &TbankConfig) -> Result<Self, ProtocolError>
Builds the channel without touching the network (connects on first use, reconnects on failure).
An https:// endpoint gets TLS with the bundled web PKI roots, and the extra root certificate of
TbankConfig::root_certificate_pem if there is one. An http:// endpoint is plain text and meant
for a local mock. HTTP/2 keep-alive pings run every 5 minutes and only while a call or a stream is
open: a server counts pings on an idle connection as abuse and closes it (too_many_pings), so none
are sent when nothing is open. A dead stream is found by the silence limit of the connector.
§Errors
ProtocolError::Configwhen the token or app name is not a valid header value, or the endpoint is not a valid URL.ProtocolError::Transportwhen the TLS configuration is refused.
§Examples
use brokapi_tbank_protocol::{ProtocolError, TbankClient, TbankConfig};
// The sandbox endpoint is not contacted here: the channel is lazy.
assert!(TbankClient::new(&TbankConfig::sandbox("t.my-token")).is_ok());
// A bad endpoint is reported at once.
let mut cfg = TbankConfig::sandbox("t.my-token");
cfg.endpoint = "not a url".into();
assert!(matches!(TbankClient::new(&cfg), Err(ProtocolError::Config(_))));Sourcepub fn grpc(&self) -> Grpc<Authed>
pub fn grpc(&self) -> Grpc<Authed>
A generic gRPC client over the same channel and token, for a call that is not made through a
generated client: the method is named by a path (/package.Service/Method) and the messages are
whatever codec you give it. With FILE_DESCRIPTOR_SET it calls any
method of the API by name.
Sourcepub fn market_data(&self) -> MarketDataServiceClient<Authed>
pub fn market_data(&self) -> MarketDataServiceClient<Authed>
Client of MarketDataService: unary market data: order book snapshot, last trades, candles, trading status.
Returns a fresh generated client on the shared channel. It is cheap, create one per call.
Sourcepub fn market_data_stream(&self) -> MarketDataStreamServiceClient<Authed>
pub fn market_data_stream(&self) -> MarketDataStreamServiceClient<Authed>
Client of MarketDataStreamService: the bidirectional market data stream (order book, trades, candles subscriptions).
Returns a fresh generated client on the shared channel. It is cheap, create one per call.
Sourcepub fn orders(&self) -> OrdersServiceClient<Authed>
pub fn orders(&self) -> OrdersServiceClient<Authed>
Client of OrdersService: orders: place, cancel, replace, order state, active orders.
Returns a fresh generated client on the shared channel. It is cheap, create one per call.
Sourcepub fn orders_stream(&self) -> OrdersStreamServiceClient<Authed>
pub fn orders_stream(&self) -> OrdersStreamServiceClient<Authed>
Client of OrdersStreamService: server streams of own order states and own trades.
Returns a fresh generated client on the shared channel. It is cheap, create one per call.
Sourcepub fn operations(&self) -> OperationsServiceClient<Authed>
pub fn operations(&self) -> OperationsServiceClient<Authed>
Client of OperationsService: portfolio, positions, operation history.
Returns a fresh generated client on the shared channel. It is cheap, create one per call.
Sourcepub fn operations_stream(&self) -> OperationsStreamServiceClient<Authed>
pub fn operations_stream(&self) -> OperationsStreamServiceClient<Authed>
Client of OperationsStreamService: server streams of portfolio and positions changes.
Returns a fresh generated client on the shared channel. It is cheap, create one per call.
Sourcepub fn users(&self) -> UsersServiceClient<Authed>
pub fn users(&self) -> UsersServiceClient<Authed>
Client of UsersService: accounts, user info, tariff and limits.
Returns a fresh generated client on the shared channel. It is cheap, create one per call.
Sourcepub fn instruments(&self) -> InstrumentsServiceClient<Authed>
pub fn instruments(&self) -> InstrumentsServiceClient<Authed>
Client of InstrumentsService: the instrument directory: search, listings, schedules, reference data.
Returns a fresh generated client on the shared channel. It is cheap, create one per call.
Sourcepub fn sandbox(&self) -> SandboxServiceClient<Authed>
pub fn sandbox(&self) -> SandboxServiceClient<Authed>
Client of SandboxService: sandbox methods: open virtual accounts, top up virtual money (meant for the sandbox endpoint).
Returns a fresh generated client on the shared channel. It is cheap, create one per call.
Sourcepub fn stop_orders(&self) -> StopOrdersServiceClient<Authed>
pub fn stop_orders(&self) -> StopOrdersServiceClient<Authed>
Client of StopOrdersService: stop orders: place, cancel, list (unary only, no stream).
Returns a fresh generated client on the shared channel. It is cheap, create one per call.
Sourcepub fn signals(&self) -> SignalServiceClient<Authed>
pub fn signals(&self) -> SignalServiceClient<Authed>
Client of SignalService: signals and strategies.
Returns a fresh generated client on the shared channel. It is cheap, create one per call.
Source§impl TbankClient
impl TbankClient
Sourcepub async fn list_accounts(&self) -> Result<Vec<Account>, Status>
pub async fn list_accounts(&self) -> Result<Vec<Account>, Status>
UsersService/GetAccounts: every account the token can see (a token covers several accounts;
pick the id to put into the connector config as account_id).
No status filter is sent. Whether the broker then returns only open accounts or all of them is
not verified against the live API, so check status of each Account
before you trade on it. The call is not rate limited here.
§Errors
The tonic::Status of the failed call: Unauthenticated for a bad token, Unavailable or
DeadlineExceeded for network trouble. The call is a read, so repeating it is safe.
§Examples
use brokapi_tbank_protocol::{TbankClient, TbankConfig};
let client = TbankClient::new(&cfg)?;
let ids: Vec<String> = client.list_accounts().await?.into_iter().map(|a| a.id).collect();
// One connector per account: put each id into `TbankConfig::with_account`.
assert!(ids.len() >= 2);
// A wrong token is refused by the server and shows as a status, not a panic.
let bad = TbankClient::new(&TbankConfig::for_mock("wrong-token", &server.endpoint))?;
let status = bad.list_accounts().await.unwrap_err();
assert_eq!(status.code(), tonic::Code::Unauthenticated);Trait Implementations§
Source§impl Clone for TbankClient
impl Clone for TbankClient
Source§fn clone(&self) -> TbankClient
fn clone(&self) -> TbankClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for TbankClient
impl !RefUnwindSafe for TbankClient
impl !UnwindSafe for TbankClient
impl Send for TbankClient
impl Sync for TbankClient
impl Unpin for TbankClient
impl UnsafeUnpin for TbankClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].