pub struct DynamicSubscribers { /* private fields */ }Expand description
The subscribers DynamicStreams cannot build for itself.
Most venues are served by a stateless WebSocketSubscriber,
which DynamicStreams constructs on its own. A venue whose subscriber carries credentials —
or shares one connection among its streams — needs one built by the caller and supplied here,
through DynamicStreams::init_with. A subscription to such a venue with no subscriber
supplied fails with DataError::SubscriberRequired.
Venues that need one:
- Alpaca (
alpacafeature):AlpacaCrypto,AlpacaIexandAlpacaSip. - London Strategic Edge (
lsefeature): everyLse*dataset. - Massive (
massivefeature):MassiveStocks,MassiveCrypto,MassiveForexandMassiveOptions.
§Example
use rustrade_data::exchange::lse::live::LseSubscriber;
use rustrade_data::streams::builder::dynamic::{DynamicStreams, DynamicSubscribers};
use rustrade_data::subscription::SubKind;
use rustrade_instrument::{
exchange::ExchangeId, instrument::market_data::kind::MarketDataInstrumentKind,
};
let subscribers = DynamicSubscribers::default().with_lse(LseSubscriber::from_env()?);
// Two datasets and both kinds: four streams, one connection.
let streams = DynamicStreams::init_with(&subscribers, [[
(ExchangeId::LseCrypto, "btc", "usd", MarketDataInstrumentKind::Spot, SubKind::PublicTrades),
(ExchangeId::LseCrypto, "btc", "usd", MarketDataInstrumentKind::Spot, SubKind::OrderBooksL1),
(ExchangeId::LseEquities, "aapl", "usd", MarketDataInstrumentKind::Spot, SubKind::PublicTrades),
(ExchangeId::LseEquities, "aapl", "usd", MarketDataInstrumentKind::Spot, SubKind::OrderBooksL1),
]])
.await?;Implementations§
Source§impl DynamicSubscribers
impl DynamicSubscribers
Sourcepub fn with_alpaca(self, subscriber: AlpacaSubscriber) -> Self
pub fn with_alpaca(self, subscriber: AlpacaSubscriber) -> Self
Serve every Alpaca subscription — any feed, either kind — from clones of subscriber.
Alpaca allows an account one market data connection per feed and refuses a second on the
same feed with connection limit exceeded. Clones of one subscriber share one connection per
feed, so every Alpaca* group of every batch on a feed attaches to the same socket, and the
crypto, IEX and SIP feeds each get one of their own. Any other stream the caller opens on the
same account should take a clone of this subscriber too, rather than one built separately.
Quotes arrive as OrderBookL1: SubKind::OrderBooksL1 reads Alpaca’s quotes channel,
and a side quoted at a zero price is None. SubKind::Quotes is not served here; the
typed Streams builder serves it. A confirmed crypto
subscription may stay silent for minutes: Alpaca publishes a crypto quote only when the top
of book changes. See exchange::alpaca.
The (channel, symbol) pairs every stream on a feed holds count together against Alpaca’s
per-connection cap — 30 on the free IEX plan, as last measured. Trades and L1 on one symbol
are two pairs.
Sourcepub fn with_lse(self, subscriber: LseSubscriber) -> Self
pub fn with_lse(self, subscriber: LseSubscriber) -> Self
Serve every London Strategic Edge subscription — any dataset, either kind — from clones of
subscriber.
Clones share the subscriber’s one connection, which is the only way several streams can
coexist on this provider: it allows a key a single WebSocket and refuses a second with
TOO_MANY_CONNECTIONS. So every Lse* group of every batch attaches to the same socket,
and so should any other stream the caller opens for the same key — pass it a clone of this
subscriber rather than building another.
§Resumption
Configure it with LseSubscriber::with_resume before passing it here to resume every
London Strategic Edge stream this call opens; the one state then serves them all. Streams
are keyed by dataset, symbol and kind, and DynamicStreams::init_with removes duplicates
only within a batch — so repeating one subscription across two batches opens two streams
sharing one watermark, which LseSubscriber::with_resume warns against.
§⚠️ The data is not redistributable
London Strategic Edge permits use for your own research, trading and model training, but
prohibits redistributing the data it serves. See
exchange::lse and https://londonstrategicedge.com/terms.
Sourcepub fn with_massive(self, subscriber: MassiveSubscriber) -> Self
pub fn with_massive(self, subscriber: MassiveSubscriber) -> Self
Serve every Massive subscription — any cluster, any kind — from clones of subscriber.
Massive allows a key a fixed number of WebSocket connections per cluster, one on an
individual plan, and past it does not refuse the new connection: it closes the older
one. Clones of one subscriber share one connection per cluster, so every Massive* group
of every batch on a cluster attaches to the same socket, and the stocks, crypto, forex and
options clusters each get one of their own. Any other stream the caller opens on the same
key should take a clone of this subscriber too: one built separately evicts this one’s
connection, and the warning logged for the lost connection quotes Massive’s
max_connections status.
What each cluster serves:
SubKind::PublicTradeson every cluster but forex, which publishes no trades.SubKind::OrderBooksL1, read from the cluster’s quote channel. A side quoted at a zero price isNone, and a forex quote carries no sizes, so its amounts are zero.SubKind::Quotesis not served here; the typedStreamsbuilder serves it.SubKind::CandlesatCandleInterval::Sec1andMin1, the only intervals Massive aggregates at. Forex candles report no volume. Both intervals on one cluster arrive on its one candle stream; seeDynamicStreams::select_candles.
MassiveOptions takes option contracts only and has never been run against the live feed,
which needs an options subscription. An instrument given as
MarketInstrumentData is subscribed by its
name_exchange as given, so that must be the cluster’s own spelling: AAPL, BTC-USD,
EUR/USD or O:AAPL251219C00150000. See exchange::massive.
§⚠️ The data is not redistributable
Massive’s terms prohibit redistributing the data it serves. See https://massive.com/legal/market-data-terms-of-service (§5(c)).
Trait Implementations§
Source§impl Clone for DynamicSubscribers
impl Clone for DynamicSubscribers
Source§impl Debug for DynamicSubscribers
impl Debug for DynamicSubscribers
Auto Trait Implementations§
impl Freeze for DynamicSubscribers
impl RefUnwindSafe for DynamicSubscribers
impl Send for DynamicSubscribers
impl Sync for DynamicSubscribers
impl Unpin for DynamicSubscribers
impl UnsafeUnpin for DynamicSubscribers
impl UnwindSafe for DynamicSubscribers
Blanket Implementations§
Source§impl<T> AttachedTransformer<()> for T
impl<T> AttachedTransformer<()> for T
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> JsonSchemaMaybe for T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.