pub struct BetfairStreamClient { /* private fields */ }Expand description
Betfair Exchange Stream API client using raw TLS (CRLF-delimited JSON).
On connect, authenticates immediately. On reconnection, replays authentication
and any active subscriptions with the latest clk token for delta resumption.
The auth bytes are stored in a watch channel so the caller can push refreshed
session tokens via update_auth after keep-alive or HTTP
reconnect. The closed flag distinguishes permanent shutdown from transient
reconnect.
Implementations§
Source§impl BetfairStreamClient
impl BetfairStreamClient
Sourcepub async fn connect(
credential: &BetfairCredential,
session_token: String,
handler: TcpMessageHandler,
config: BetfairStreamConfig,
) -> Result<Self, BetfairStreamError>
pub async fn connect( credential: &BetfairCredential, session_token: String, handler: TcpMessageHandler, config: BetfairStreamConfig, ) -> Result<Self, BetfairStreamError>
Connects to the Betfair stream API and authenticates.
§Errors
Returns an error if the connection fails or authentication cannot be sent.
Sourcepub async fn subscribe_markets(
&self,
market_filter: StreamMarketFilter,
data_filter: MarketDataFilter,
heartbeat_ms: Option<u64>,
conflate_ms: Option<u64>,
) -> Result<(), BetfairStreamError>
pub async fn subscribe_markets( &self, market_filter: StreamMarketFilter, data_filter: MarketDataFilter, heartbeat_ms: Option<u64>, conflate_ms: Option<u64>, ) -> Result<(), BetfairStreamError>
Subscribes to market data for the given filter and data fields.
Stores the subscription for automatic replay on reconnection.
§Errors
Returns an error if serialization or sending fails.
Sourcepub async fn subscribe_orders(
&self,
order_filter: Option<OrderFilter>,
heartbeat_ms: Option<u64>,
) -> Result<(), BetfairStreamError>
pub async fn subscribe_orders( &self, order_filter: Option<OrderFilter>, heartbeat_ms: Option<u64>, ) -> Result<(), BetfairStreamError>
Subscribes to order updates.
Stores the subscription for automatic replay on reconnection.
§Errors
Returns an error if serialization or sending fails.
pub fn authentication_state(&self) -> StreamLifecycleState
pub fn market_subscription_state(&self) -> StreamLifecycleState
pub fn order_subscription_state(&self) -> StreamLifecycleState
Sourcepub async fn wait_for_authentication_state(
&self,
expected: StreamLifecycleState,
)
pub async fn wait_for_authentication_state( &self, expected: StreamLifecycleState, )
Waits for the authentication lifecycle component to equal expected.
Returns immediately if the component is already in the exact expected state;
otherwise waits for a later transition. A transient expected state that is
replaced before this task observes it can be missed because transitions are not
recorded as history. This method has no internal timeout; callers wanting a
bound should wrap it in [tokio::time::timeout].
Sourcepub async fn wait_for_market_subscription_state(
&self,
expected: StreamLifecycleState,
)
pub async fn wait_for_market_subscription_state( &self, expected: StreamLifecycleState, )
Waits for the market subscription lifecycle component to equal expected.
Returns immediately if the component is already in the exact expected state;
otherwise waits for a later transition. A transient expected state that is
replaced before this task observes it can be missed because transitions are not
recorded as history. This method has no internal timeout; callers wanting a
bound should wrap it in [tokio::time::timeout].
Sourcepub async fn wait_for_order_subscription_state(
&self,
expected: StreamLifecycleState,
)
pub async fn wait_for_order_subscription_state( &self, expected: StreamLifecycleState, )
Waits for the order subscription lifecycle component to equal expected.
Returns immediately if the component is already in the exact expected state;
otherwise waits for a later transition. A transient expected state that is
replaced before this task observes it can be missed because transitions are not
recorded as history. This method has no internal timeout; callers wanting a
bound should wrap it in [tokio::time::timeout].
pub fn is_authenticated(&self) -> bool
pub fn is_market_ready(&self) -> bool
pub fn is_order_ready(&self) -> bool
Sourcepub fn update_auth(&self, app_key: &str, session_token: String)
pub fn update_auth(&self, app_key: &str, session_token: String)
Pushes refreshed auth bytes so the next reconnection or subscription uses the current session token instead of the one from initial connect.
Sourcepub fn request_reconnect(&self) -> bool
pub fn request_reconnect(&self) -> bool
Requests replacement of the active stream transport.
Returns true only when this call starts a reconnect. Duplicate requests and requests after
close return false.
Trait Implementations§
Source§impl Debug for BetfairStreamClient
impl Debug for BetfairStreamClient
Source§impl Drop for BetfairStreamClient
impl Drop for BetfairStreamClient
Auto Trait Implementations§
impl !Freeze for BetfairStreamClient
impl !RefUnwindSafe for BetfairStreamClient
impl !UnwindSafe for BetfairStreamClient
impl Send for BetfairStreamClient
impl Sync for BetfairStreamClient
impl Unpin for BetfairStreamClient
impl UnsafeUnpin for BetfairStreamClient
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> ⓘ
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