finam 0.8.0

SDK для работы с API Финам
Documentation
// This file is @generated by prost-build.
/// Запрос авторизации
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct AuthRequest {
    /// API токен (secret key)
    #[prost(string, tag = "1")]
    pub secret: ::prost::alloc::string::String,
}
/// Информация об авторизации
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct AuthResponse {
    /// Полученный JWT-токен
    #[prost(string, tag = "1")]
    pub token: ::prost::alloc::string::String,
}
/// Запрос информации о токене
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct TokenDetailsRequest {
    /// JWT-токен
    #[prost(string, tag = "1")]
    pub token: ::prost::alloc::string::String,
}
/// Информация о токене
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct TokenDetailsResponse {
    /// Дата и время создания
    #[prost(message, optional, tag = "1")]
    pub created_at: ::core::option::Option<::prost_types::Timestamp>,
    /// Дата и время экспирации
    #[prost(message, optional, tag = "2")]
    pub expires_at: ::core::option::Option<::prost_types::Timestamp>,
    /// Информация о доступе к рыночным данным
    #[prost(message, repeated, tag = "3")]
    pub md_permissions: ::prost::alloc::vec::Vec<MdPermission>,
    /// Идентификаторы аккаунтов
    #[prost(string, repeated, tag = "4")]
    pub account_ids: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
    /// Сессия и торговые счета в токене будут помечены readonly
    #[prost(bool, tag = "5")]
    pub readonly: bool,
}
/// Информация о доступе к рыночным данным
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct MdPermission {
    /// Уровень котировок
    #[prost(enumeration = "md_permission::QuoteLevel", tag = "1")]
    pub quote_level: i32,
    /// Задержка в минутах
    #[prost(int32, tag = "2")]
    pub delay_minutes: i32,
    #[prost(oneof = "md_permission::Condition", tags = "3, 4, 5, 6")]
    pub condition: ::core::option::Option<md_permission::Condition>,
}
/// Nested message and enum types in `MDPermission`.
pub mod md_permission {
    /// Уровень котировок
    #[derive(
        Clone,
        Copy,
        Debug,
        PartialEq,
        Eq,
        Hash,
        PartialOrd,
        Ord,
        ::prost::Enumeration
    )]
    #[repr(i32)]
    pub enum QuoteLevel {
        /// Значение не указано
        Unspecified = 0,
        /// Последняя цена
        LastPrice = 1,
        /// Бид аск
        BestBidOffer = 2,
        /// Агрегированный стакан
        DepthOfMarket = 3,
        /// Полный стакан
        DepthOfBook = 4,
        /// Доступ запрещен
        AccessForbidden = 5,
    }
    impl QuoteLevel {
        /// String value of the enum field names used in the ProtoBuf definition.
        ///
        /// The values are not transformed in any way and thus are considered stable
        /// (if the ProtoBuf definition does not change) and safe for programmatic use.
        pub fn as_str_name(&self) -> &'static str {
            match self {
                Self::Unspecified => "QUOTE_LEVEL_UNSPECIFIED",
                Self::LastPrice => "QUOTE_LEVEL_LAST_PRICE",
                Self::BestBidOffer => "QUOTE_LEVEL_BEST_BID_OFFER",
                Self::DepthOfMarket => "QUOTE_LEVEL_DEPTH_OF_MARKET",
                Self::DepthOfBook => "QUOTE_LEVEL_DEPTH_OF_BOOK",
                Self::AccessForbidden => "QUOTE_LEVEL_ACCESS_FORBIDDEN",
            }
        }
        /// Creates an enum from field names used in the ProtoBuf definition.
        pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
            match value {
                "QUOTE_LEVEL_UNSPECIFIED" => Some(Self::Unspecified),
                "QUOTE_LEVEL_LAST_PRICE" => Some(Self::LastPrice),
                "QUOTE_LEVEL_BEST_BID_OFFER" => Some(Self::BestBidOffer),
                "QUOTE_LEVEL_DEPTH_OF_MARKET" => Some(Self::DepthOfMarket),
                "QUOTE_LEVEL_DEPTH_OF_BOOK" => Some(Self::DepthOfBook),
                "QUOTE_LEVEL_ACCESS_FORBIDDEN" => Some(Self::AccessForbidden),
                _ => None,
            }
        }
    }
    #[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)]
    pub enum Condition {
        /// Идентификатор биржи mic
        #[prost(string, tag = "3")]
        Mic(::prost::alloc::string::String),
        /// Страна
        #[prost(string, tag = "4")]
        Country(::prost::alloc::string::String),
        /// Континент
        #[prost(string, tag = "5")]
        Continent(::prost::alloc::string::String),
        /// Весь мир
        #[prost(bool, tag = "6")]
        Worldwide(bool),
    }
}
/// Запрос подписки на обновление JWT токена
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct SubscribeJwtRenewalRequest {
    /// API токен (secret key)
    #[prost(string, tag = "1")]
    pub secret: ::prost::alloc::string::String,
}
/// Обновленный токен. Стрим
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct SubscribeJwtRenewalResponse {
    /// Полученный JWT-токен
    #[prost(string, tag = "1")]
    pub token: ::prost::alloc::string::String,
}
/// Generated client implementations.
pub mod auth_service_client {
    #![allow(
        unused_variables,
        dead_code,
        missing_docs,
        clippy::wildcard_imports,
        clippy::let_unit_value,
    )]
    use tonic::codegen::*;
    use tonic::codegen::http::Uri;
    /// Сервис аутентификации
    #[derive(Debug, Clone)]
    pub struct AuthServiceClient<T> {
        inner: tonic::client::Grpc<T>,
    }
    impl AuthServiceClient<tonic::transport::Channel> {
        /// Attempt to create a new client by connecting to a given endpoint.
        pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
        where
            D: TryInto<tonic::transport::Endpoint>,
            D::Error: Into<StdError>,
        {
            let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
            Ok(Self::new(conn))
        }
    }
    impl<T> AuthServiceClient<T>
    where
        T: tonic::client::GrpcService<tonic::body::Body>,
        T::Error: Into<StdError>,
        T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
        <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
    {
        pub fn new(inner: T) -> Self {
            let inner = tonic::client::Grpc::new(inner);
            Self { inner }
        }
        pub fn with_origin(inner: T, origin: Uri) -> Self {
            let inner = tonic::client::Grpc::with_origin(inner, origin);
            Self { inner }
        }
        pub fn with_interceptor<F>(
            inner: T,
            interceptor: F,
        ) -> AuthServiceClient<InterceptedService<T, F>>
        where
            F: tonic::service::Interceptor,
            T::ResponseBody: Default,
            T: tonic::codegen::Service<
                http::Request<tonic::body::Body>,
                Response = http::Response<
                    <T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
                >,
            >,
            <T as tonic::codegen::Service<
                http::Request<tonic::body::Body>,
            >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
        {
            AuthServiceClient::new(InterceptedService::new(inner, interceptor))
        }
        /// Compress requests with the given encoding.
        ///
        /// This requires the server to support it otherwise it might respond with an
        /// error.
        #[must_use]
        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
            self.inner = self.inner.send_compressed(encoding);
            self
        }
        /// Enable decompressing responses.
        #[must_use]
        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
            self.inner = self.inner.accept_compressed(encoding);
            self
        }
        /// Limits the maximum size of a decoded message.
        ///
        /// Default: `4MB`
        #[must_use]
        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
            self.inner = self.inner.max_decoding_message_size(limit);
            self
        }
        /// Limits the maximum size of an encoded message.
        ///
        /// Default: `usize::MAX`
        #[must_use]
        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
            self.inner = self.inner.max_encoding_message_size(limit);
            self
        }
        /// Получение JWT токена из API токена
        /// Пример HTTP запроса:
        /// POST /v1/sessions
        /// Content-Type: application/json
        ///
        /// {
        /// "secret": "your-api-secret-key"
        /// }
        ///
        /// Все поля передаются в теле запроса
        pub async fn auth(
            &mut self,
            request: impl tonic::IntoRequest<super::AuthRequest>,
        ) -> std::result::Result<tonic::Response<super::AuthResponse>, tonic::Status> {
            self.inner
                .ready()
                .await
                .map_err(|e| {
                    tonic::Status::unknown(
                        format!("Service was not ready: {}", e.into()),
                    )
                })?;
            let codec = tonic_prost::ProstCodec::default();
            let path = http::uri::PathAndQuery::from_static(
                "/grpc.tradeapi.v1.auth.AuthService/Auth",
            );
            let mut req = request.into_request();
            req.extensions_mut()
                .insert(GrpcMethod::new("grpc.tradeapi.v1.auth.AuthService", "Auth"));
            self.inner.unary(req, path, codec).await
        }
        /// Получение информации о токене сессии
        /// Пример HTTP запроса:
        /// POST /v1/sessions/details
        /// Content-Type: application/json
        ///
        /// {
        /// "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
        /// }
        ///
        /// Токен передается в теле запроса для безопасности
        /// Получение информации о токене. Также включает список доступных счетов.
        pub async fn token_details(
            &mut self,
            request: impl tonic::IntoRequest<super::TokenDetailsRequest>,
        ) -> std::result::Result<
            tonic::Response<super::TokenDetailsResponse>,
            tonic::Status,
        > {
            self.inner
                .ready()
                .await
                .map_err(|e| {
                    tonic::Status::unknown(
                        format!("Service was not ready: {}", e.into()),
                    )
                })?;
            let codec = tonic_prost::ProstCodec::default();
            let path = http::uri::PathAndQuery::from_static(
                "/grpc.tradeapi.v1.auth.AuthService/TokenDetails",
            );
            let mut req = request.into_request();
            req.extensions_mut()
                .insert(
                    GrpcMethod::new("grpc.tradeapi.v1.auth.AuthService", "TokenDetails"),
                );
            self.inner.unary(req, path, codec).await
        }
        /// Подписка на обновление JWT токена. Стрим метод
        pub async fn subscribe_jwt_renewal(
            &mut self,
            request: impl tonic::IntoRequest<super::SubscribeJwtRenewalRequest>,
        ) -> std::result::Result<
            tonic::Response<tonic::codec::Streaming<super::SubscribeJwtRenewalResponse>>,
            tonic::Status,
        > {
            self.inner
                .ready()
                .await
                .map_err(|e| {
                    tonic::Status::unknown(
                        format!("Service was not ready: {}", e.into()),
                    )
                })?;
            let codec = tonic_prost::ProstCodec::default();
            let path = http::uri::PathAndQuery::from_static(
                "/grpc.tradeapi.v1.auth.AuthService/SubscribeJwtRenewal",
            );
            let mut req = request.into_request();
            req.extensions_mut()
                .insert(
                    GrpcMethod::new(
                        "grpc.tradeapi.v1.auth.AuthService",
                        "SubscribeJwtRenewal",
                    ),
                );
            self.inner.server_streaming(req, path, codec).await
        }
    }
}