brokapi_alor_protocol/lib.rs
1//! ALOR Broker wire protocol: REST and WebSocket clients, serde models and small helpers.
2//!
3//! This is the protocol layer for the ALOR OpenAPI (a Russian broker). It talks to the broker in the broker's
4//! own words and does nothing else: no order state, no mapping to common types, no retry of orders. The
5//! connector crate `brokapi-alor` sits on top of it and maps these types to the broker-independent ones. Use
6//! this crate directly when you want the raw API.
7//!
8//! The reference book is at <https://brokapi.ru/docs/>.
9//!
10//! # Parts
11//!
12//! * Module [`config`]: [`AlorConfig`](config::AlorConfig), the refresh token, the contour and the base URLs.
13//! * Module [`http`]: [`AlorHttpClient`](http::client::AlorHttpClient) with one method per REST endpoint, and
14//! the request and response models in [`http::models`].
15//! * Module [`ws`]: [`WsSession`](ws::session::WsSession), a background WebSocket session of the data channel
16//! that reconnects and restores subscriptions, the subscription messages in [`ws::models`], and the trading
17//! channel in [`ws::cws`].
18//! * Module [`error`]: [`AlorApiError`](error::AlorApiError).
19//!
20//! # Authorization in one paragraph
21//!
22//! The broker gives you a long-lived refresh token (a year in the production contour). The client trades it for
23//! an access token (it lives 30 minutes) at the first call, sends the access token as
24//! `Authorization: Bearer ...` (on the WebSocket data channel: in every message), and asks for a new one before
25//! it is spent. You never handle the access token yourself.
26//!
27//! # Example
28//!
29//! The example runs against the in-process imitation of the broker (`brokapi-mocks`), so it needs no network and
30//! no account. With a real account you build `cfg` with [`AlorConfig::from_env`](config::AlorConfig::from_env)
31//! or [`AlorConfig::new`](config::AlorConfig::new).
32//!
33//! ```
34//! # #[tokio::main(flavor = "current_thread")]
35//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
36//! # let server = brokapi_mocks::alor::MockServer::start(Default::default()).await;
37//! # let cfg = brokapi_alor_protocol::config::AlorConfig::for_mock("mock-refresh-token", &server.http_base);
38//! use brokapi_alor_protocol::http::client::AlorHttpClient;
39//!
40//! let client = AlorHttpClient::new(cfg)?;
41//! let book = client.get_order_book("MOEX", "SBER", Some("TQBR"), Some(5)).await?;
42//! assert!(!book.bids.is_empty());
43//! # Ok(())
44//! # }
45//! ```
46
47#![warn(missing_docs)]
48
49pub mod config;
50pub mod error;
51pub mod http;
52pub mod ws;