pub struct StreamBuilder<InstrumentKey, Kind>where
Kind: SubscriptionKind,{
pub channels: HashMap<ExchangeId, Channel<MarketStreamResult<InstrumentKey, Kind::Event>>>,
pub futures: Vec<SubscribeFuture>,
}Expand description
Builder to configure and initialise a Streams<MarketEvent<SubscriptionKind::Event> instance
for a specific SubscriptionKind.
Fields§
§channels: HashMap<ExchangeId, Channel<MarketStreamResult<InstrumentKey, Kind::Event>>>§futures: Vec<SubscribeFuture>Implementations§
Source§impl<InstrumentKey, Kind> StreamBuilder<InstrumentKey, Kind>where
Kind: SubscriptionKind,
impl<InstrumentKey, Kind> StreamBuilder<InstrumentKey, Kind>where
Kind: SubscriptionKind,
Sourcepub fn subscribe<SubIter, Sub, Exchange, Instrument>(
self,
subscriber: Exchange::Subscriber,
subscriptions: SubIter,
) -> Selfwhere
SubIter: IntoIterator<Item = Sub>,
Sub: Into<Subscription<Exchange, Instrument, Kind>>,
Exchange: StreamSelector<Instrument, Kind> + Ord + Send + Sync + 'static,
Instrument: InstrumentData<Key = InstrumentKey> + Ord + Display + 'static,
Instrument::Key: Debug + Clone + Send + 'static,
Kind: Ord + Display + Send + Sync + 'static,
Kind::Event: Clone + Send,
Subscription<Exchange, Instrument, Kind>: Identifier<Exchange::Channel> + Identifier<Exchange::Market>,
pub fn subscribe<SubIter, Sub, Exchange, Instrument>(
self,
subscriber: Exchange::Subscriber,
subscriptions: SubIter,
) -> Selfwhere
SubIter: IntoIterator<Item = Sub>,
Sub: Into<Subscription<Exchange, Instrument, Kind>>,
Exchange: StreamSelector<Instrument, Kind> + Ord + Send + Sync + 'static,
Instrument: InstrumentData<Key = InstrumentKey> + Ord + Display + 'static,
Instrument::Key: Debug + Clone + Send + 'static,
Kind: Ord + Display + Send + Sync + 'static,
Kind::Event: Clone + Send,
Subscription<Exchange, Instrument, Kind>: Identifier<Exchange::Channel> + Identifier<Exchange::Market>,
Add a collection of Subscriptions to the StreamBuilder that will be actioned on
a connection the subscriber provides.
For almost every exchange that is a distinct
WebSocket per call. A subscriber
whose clones share one connection — for a provider that allows a key a single connection —
instead serves each call over a view of it; see
Subscriber::Transport.
The subscriber handles the connection and authentication.
For unauthenticated exchanges, use WebSocketSubscriber.
For authenticated exchanges like Alpaca, use the exchange-specific subscriber with credentials.
Note that Subscriptions are not actioned until the
init() method is invoked.
Sourcepub async fn init(
self,
) -> Result<Streams<MarketStreamResult<InstrumentKey, Kind::Event>>, DataError>
pub async fn init( self, ) -> Result<Streams<MarketStreamResult<InstrumentKey, Kind::Event>>, DataError>
Spawn a MarketStreamResult<SubscriptionKind::Event> consumer loop
for each collection of Subscriptions added to StreamBuilder via the
subscribe() method.
Each consumer loop distributes consumed MarketStreamResult to
the Streams HashMap returned by this method.
Trait Implementations§
Source§impl<InstrumentKey, Kind> Debug for StreamBuilder<InstrumentKey, Kind>where
InstrumentKey: Debug,
Kind: SubscriptionKind,
impl<InstrumentKey, Kind> Debug for StreamBuilder<InstrumentKey, Kind>where
InstrumentKey: Debug,
Kind: SubscriptionKind,
Auto Trait Implementations§
impl<InstrumentKey, Kind> !RefUnwindSafe for StreamBuilder<InstrumentKey, Kind>
impl<InstrumentKey, Kind> !Send for StreamBuilder<InstrumentKey, Kind>
impl<InstrumentKey, Kind> !Sync for StreamBuilder<InstrumentKey, Kind>
impl<InstrumentKey, Kind> !UnwindSafe for StreamBuilder<InstrumentKey, Kind>
impl<InstrumentKey, Kind> Freeze for StreamBuilder<InstrumentKey, Kind>where
HashMap<ExchangeId, Channel<Event<ExchangeId, Result<MarketEvent<InstrumentKey, <Kind as SubscriptionKind>::Event>, DataError>>>>: Freeze,
impl<InstrumentKey, Kind> Unpin for StreamBuilder<InstrumentKey, Kind>where
HashMap<ExchangeId, Channel<Event<ExchangeId, Result<MarketEvent<InstrumentKey, <Kind as SubscriptionKind>::Event>, DataError>>>>: Unpin,
impl<InstrumentKey, Kind> UnsafeUnpin for StreamBuilder<InstrumentKey, Kind>where
HashMap<ExchangeId, Channel<Event<ExchangeId, Result<MarketEvent<InstrumentKey, <Kind as SubscriptionKind>::Event>, DataError>>>>: UnsafeUnpin,
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<Instrument> DynamicAlpacaInstrument for Instrument
impl<Instrument> DynamicHyperliquidInstrument for Instrument
impl<Instrument> DynamicLseInstrument for Instrument
impl<Instrument> DynamicMassiveInstrument for Instrument
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 more