Crate yatis

Source
Expand description

§YATIS - Yet Another TBank Investment Sdk

§Usage

use yatis::*;
use t_types::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let token = std::env::var("SANDBOX_TOKEN").expect("need to set env var 'TOKEN'");
    let api = SandboxApi::create_invest_service(token)?; //creating sandbox api
    //let api = Api::create_invest_service(token)?; //or production api
    trading(api).await
}
async fn trading(api: impl InvestApi) -> Result<(), Box<dyn std::error::Error>> {
    // You can execute unary requests:
    let share: ShareResponse = api.request(InstrumentRequest{ //use native types from investAPI
        id_type:InstrumentIdType::Ticker.into(),
        class_code:Some("TQBR".to_string()),
        id:"T".to_string()
    }).await?;
    println!("T: {share:?}\n");
    let figi = "TCS80A107UL4".to_string(); //T-Techno shares

    // Or create streams:
    let (s, mut r) = futures::channel::mpsc::channel::<StreamResponse>(10);
    api.start_stream(MarketDataServerSideStreamRequest {
        subscribe_last_price_request: Some(SubscribeLastPriceRequest {
            subscription_action: SubscriptionAction::Subscribe.into(),
            instruments: vec![LastPriceInstrument {figi,..Default::default()}],
            ..Default::default()
        }),
        ping_settings: Some(PingDelaySettings {ping_delay_ms: Some(5000)}), //used by yatis to detect hung connections
        subscribe_candles_request: None, subscribe_order_book_request: None, subscribe_trades_request: None, subscribe_info_request: None,
    }, s).await?;
    use futures::StreamExt;
    if let Some(response) = r.next().await { //or while instead of if
        println!("{response:?}");
    }

    Ok(())
}

§Targets

  • more usability
  • easy to use any types of generated proto of investAPI
  • ability to create your own implementation of common traits, like InvestService, OwnedSender and StartStream
  • easy to use pool objects

§Goals

  • Investing api implementation
  • Single api trait for all operations InvestApi
    • Single method for all unary request: request
    • Single method for all serverside streams: start_stream
  • Pool of reusable connections
  • Sandbox API with polymorphism (see examples)
  • Server side streams
    • Authomatic reconnect on stucked connections
    • Resubscribtion on reconnect
    • Connections limitation by tariff
  • Bidirecional streams
    • Balanced pool of streams
    • Authomatic reconnect on stucked connections
    • Resubscribtion on reconnect
  • Arithmetic opertions with Quotation

Re-exports§

pub use pool::ApiPool;
pub use requestor::Requestor;
pub use stream::StartStream;
pub use stream_response::StreamResponse;

Modules§

pool
Simple rounding pool implementation
requestor
Traits and implementations for unary requests to API. Target is implement single method Requestor::request for all Requests and Responses.
stream
Traits and implementations for opening server-side streams to API. Implements single method StartStream::start_stream for any possible stream-requests
stream_response
Container for all stream responses with From implementation
t_types
Prost-generated grpc-bindings

Structs§

SandboxApi
sandbox implementation of api. Also implements crate::InvestApi Not that Sandbox maniputlation operations not implemented in trait crate::InvestApi, but implemented in type SandboxApi
TokenInterceptor

Traits§

InvestApi
trait for use some methods of investing api.
InvestService
Self creator
QuotationExt

Type Aliases§

Api
reused tonic’s Grpc type, with implementation of crate::InvestApi
IService