Skip to main content

FinamApi

Struct FinamApi 

Source
pub struct FinamApi { /* private fields */ }
Expand description

One channel plus a shared token manager. Hands out service clients that attach the JWT to each call.

Cheap to clone (the channel is reference counted). Each accessor builds a new client over the same channel, so there is no need to keep clients around.

A streaming call keeps the JWT it was opened with. Open it again after the token is renewed (the connectors do this for their own streams).

See the module docs for a complete example.

Implementations§

Source§

impl FinamApi

Source

pub fn connect( ep: &ApiEndpoint, tokens: Arc<TokenManager>, bearer: bool, ) -> Result<Self, FinamError>

Opens a lazy channel to ep and uses tokens for authorization.

bearer selects the header format. false sends the bare JWT, which is what the official SDKs do. true sends Bearer <jwt>, which some examples in the broker documentation show. Which of the two the live broker accepts is not verified against the live API here.

§Errors

FinamError::Config when the endpoint URL is invalid (see connect_lazy).

§Examples
use brokapi_finam_protocol::{ApiEndpoint, FinamApi, FinamError, start_token_manager};

let api = FinamApi::connect(&endpoint, tokens.clone(), false)?;
assert!(std::sync::Arc::ptr_eq(api.tokens(), &tokens));

let bad = FinamApi::connect(&ApiEndpoint::new("not a url"), tokens, false);
assert!(matches!(bad, Err(FinamError::Config(_))));
Source

pub fn from_channel( channel: Channel, tokens: Arc<TokenManager>, bearer: bool, ) -> Self

Wraps a channel you built yourself (for example with custom TLS or a proxy).

Nothing is checked. bearer has the same meaning as in FinamApi::connect.

Source

pub fn tokens(&self) -> &Arc<TokenManager>

The token manager used by this client.

Use it to read the account list (TokenManager::account_ids) or to ask for a renewal.

Source

pub fn grpc(&self) -> Grpc<Authorized>

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.

Source

pub fn orders(&self) -> OrdersServiceClient<Authorized>

OrdersService: place, cancel and read orders, order and trade streams.

Source

pub fn accounts(&self) -> AccountsServiceClient<Authorized>

AccountsService: account state, own trades, account stream.

Source

pub fn market_data(&self) -> MarketDataServiceClient<Authorized>

MarketDataService: quotes, order books, trades, bars and their streams.

Source

pub fn assets(&self) -> AssetsServiceClient<Authorized>

AssetsService: instrument directory, schedules, exchange clock.

Source

pub fn usage_metrics(&self) -> UsageMetricsServiceClient<Authorized>

UsageMetricsService: how much of the request quota is left.

Source

pub fn auth(&self) -> AuthServiceClient<Authorized>

AuthService with the current JWT attached. Auth and SubscribeJwtRenewal are driven by the TokenManager; TokenDetails is reachable here.

Source

pub fn reports(&self) -> ReportsServiceClient<Authorized>

ReportsService: account reports.

Source

pub fn corporate_actions(&self) -> CorporateActionsServiceClient<Authorized>

CorporateActionsService: splits, dividends and bond events.

Trait Implementations§

Source§

impl Clone for FinamApi

Source§

fn clone(&self) -> FinamApi

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more