Struct MarketDataConnector
pub struct MarketDataConnector { /* private fields */ }Expand description
The market data connector of ALOR: implements [OrderBookSource], [MarketDataSource] and
[InstrumentSource]. It is not tied to an account.
Start it with MarketDataConnector::start; commands return their answer directly and subscriptions deliver
[Envelope]s into the channel given at start. The data comes over one WebSocket session that reconnects on its
own and restores the subscriptions (an order book is then marked with Event::Resync).
An instrument is named by NativeId::TickerClass { ticker, class_code }, where the class code is the trading
mode (the board, for example TQBR). The exchange follows from it: the board SPBX is the exchange SPBX,
every other board is MOEX.
§Examples
use brokapi_alor::limits::default_limits;
use brokapi_alor::util::instrument_id;
use brokapi_alor::{MarketDataConfig, MarketDataConnector};
use brokapi_core::{OrderBook, OrderBookSource, ShutdownMode};
use brokapi_runtime::BrokerLimiter;
use tokio::sync::mpsc;
let (tx, _events) = mpsc::channel(256);
let md = MarketDataConnector::start(
MarketDataConfig::new(cfg, "alor-md"),
BrokerLimiter::new(&default_limits()),
tx,
)
.await?;
let book = md.order_book(&instrument_id("SBER", "TQBR"), 5).await?;
let OrderBook::Snapshot { bids, .. } = book else { unreachable!() };
assert!(!bids.is_empty());
md.shutdown(ShutdownMode::Immediate).await;Implementations§
§impl MarketDataConnector
impl MarketDataConnector
pub async fn start(
cfg: MarketDataConfig,
limiter: Arc<BrokerLimiter>,
out: Sender<Envelope>,
) -> Result<MarketDataConnector, Error>
pub async fn start( cfg: MarketDataConfig, limiter: Arc<BrokerLimiter>, out: Sender<Envelope>, ) -> Result<MarketDataConnector, Error>
Starts the connector: gets the first access token (so a refused token is an error here, not at the first call) and opens the WebSocket session in the background.
§Errors
[Error::Config] when the client cannot be built or the broker refuses the token; [Error::Transport]
when the authorization server cannot be reached.
pub fn raw(&self) -> AlorRaw
pub fn raw(&self) -> AlorRaw
Direct access to any API method with this connector’s token and rate limiter. See AlorRaw.
pub fn caps(&self) -> MarketDataCaps
pub fn caps(&self) -> MarketDataCaps
What the connector can do: books of up to 50 levels (always whole books), all four streams.
pub async fn shutdown(self, mode: ShutdownMode) -> ShutdownReport
pub async fn shutdown(self, mode: ShutdownMode) -> ShutdownReport
Stops the connector. Unless the mode is Immediate, it cancels the subscriptions at the broker first;
Graceful also lets the bot’s channel take what is still buffered.
Trait Implementations§
§impl Connector for MarketDataConnector
impl Connector for MarketDataConnector
§fn caps(&self) -> MarketDataCaps
fn caps(&self) -> MarketDataCaps
§fn shutdown<'async_trait>(
self,
mode: ShutdownMode,
) -> Pin<Box<dyn Future<Output = ShutdownReport> + Send + 'async_trait>>where
MarketDataConnector: 'async_trait,
fn shutdown<'async_trait>(
self,
mode: ShutdownMode,
) -> Pin<Box<dyn Future<Output = ShutdownReport> + Send + 'async_trait>>where
MarketDataConnector: 'async_trait,
Error::Unknown], see [ShutdownReport]) and ends its tasks. Takes the connector by value, so it
cannot be used afterwards.§impl InstrumentSource for MarketDataConnector
impl InstrumentSource for MarketDataConnector
§fn find<'life0, 'async_trait>(
&'life0 self,
q: InstrumentQuery,
) -> Pin<Box<dyn Future<Output = Result<Vec<Instrument>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
MarketDataConnector: 'async_trait,
fn find<'life0, 'async_trait>(
&'life0 self,
q: InstrumentQuery,
) -> Pin<Box<dyn Future<Output = Result<Vec<Instrument>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
MarketDataConnector: 'async_trait,
§fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
) -> Pin<Box<dyn Future<Output = Result<Instrument, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
) -> Pin<Box<dyn Future<Output = Result<Instrument, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
§fn trading_params<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
) -> Pin<Box<dyn Future<Output = Result<TradingParams, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
fn trading_params<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
) -> Pin<Box<dyn Future<Output = Result<TradingParams, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
§fn trading_status<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
) -> Pin<Box<dyn Future<Output = Result<TradingStatus, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
fn trading_status<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
) -> Pin<Box<dyn Future<Output = Result<TradingStatus, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
§fn schedule<'life0, 'life1, 'async_trait>(
&'life0 self,
_exchange: &'life1 str,
_range: TimeRange,
) -> Pin<Box<dyn Future<Output = Result<Schedule, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
fn schedule<'life0, 'life1, 'async_trait>(
&'life0 self,
_exchange: &'life1 str,
_range: TimeRange,
) -> Pin<Box<dyn Future<Output = Result<Schedule, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
range. Read more§impl MarketDataSource for MarketDataConnector
impl MarketDataSource for MarketDataConnector
§fn last_trades<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
limit: u32,
) -> Pin<Box<dyn Future<Output = Result<Vec<MarketTrade>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
fn last_trades<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
limit: u32,
) -> Pin<Box<dyn Future<Output = Result<Vec<MarketTrade>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
limit deals of the public tape. Read more§fn subscribe_market_trades<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
opts: SubscribeOpts,
) -> Pin<Box<dyn Future<Output = Result<SubscriptionId, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
fn subscribe_market_trades<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
opts: SubscribeOpts,
) -> Pin<Box<dyn Future<Output = Result<SubscriptionId, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
§fn subscribe_quotes<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
opts: SubscribeOpts,
) -> Pin<Box<dyn Future<Output = Result<SubscriptionId, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
fn subscribe_quotes<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
opts: SubscribeOpts,
) -> Pin<Box<dyn Future<Output = Result<SubscriptionId, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
§fn candles<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
tf: Timeframe,
range: TimeRange,
) -> Pin<Box<dyn Future<Output = Result<Vec<Candle>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
fn candles<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
tf: Timeframe,
range: TimeRange,
) -> Pin<Box<dyn Future<Output = Result<Vec<Candle>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
§fn subscribe_candles<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
tf: Timeframe,
opts: SubscribeOpts,
) -> Pin<Box<dyn Future<Output = Result<SubscriptionId, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
fn subscribe_candles<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
tf: Timeframe,
opts: SubscribeOpts,
) -> Pin<Box<dyn Future<Output = Result<SubscriptionId, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
tf for one instrument. Read more§impl OrderBookSource for MarketDataConnector
impl OrderBookSource for MarketDataConnector
§fn order_book<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
depth: u32,
) -> Pin<Box<dyn Future<Output = Result<OrderBook, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
fn order_book<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
depth: u32,
) -> Pin<Box<dyn Future<Output = Result<OrderBook, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
depth levels per side. Read more§fn subscribe_order_book<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
opts: SubscribeOpts,
) -> Pin<Box<dyn Future<Output = Result<SubscriptionId, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
fn subscribe_order_book<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 InstrumentId,
opts: SubscribeOpts,
) -> Pin<Box<dyn Future<Output = Result<SubscriptionId, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MarketDataConnector: 'async_trait,
§fn unsubscribe<'life0, 'async_trait>(
&'life0 self,
sub: SubscriptionId,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
MarketDataConnector: 'async_trait,
fn unsubscribe<'life0, 'async_trait>(
&'life0 self,
sub: SubscriptionId,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
MarketDataConnector: 'async_trait,
Auto Trait Implementations§
impl !RefUnwindSafe for MarketDataConnector
impl !UnwindSafe for MarketDataConnector
impl Freeze for MarketDataConnector
impl Send for MarketDataConnector
impl Sync for MarketDataConnector
impl Unpin for MarketDataConnector
impl UnsafeUnpin for MarketDataConnector
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§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].