pub struct UserStream { /* private fields */ }Expand description
User data stream API client.
Provides endpoints for managing user data streams. A listen key is required to connect to the user data WebSocket stream for real-time account updates.
§Listen Key Lifecycle
- Start a stream with
start()to get a listen key - Send keepalive every 30 minutes with
keepalive()to prevent expiration - Close the stream with
close()when done
Listen keys expire after 60 minutes without a keepalive.
Implementations§
Source§impl UserStream
impl UserStream
Sourcepub async fn start(&self) -> Result<String>
pub async fn start(&self) -> Result<String>
Start a new user data stream.
Returns a listen key that can be used to connect to the user data WebSocket stream.
§Example
ⓘ
let client = Binance::new("api_key", "secret_key")?;
let listen_key = client.user_stream().start().await?;
println!("Listen key: {}", listen_key);
// Connect to WebSocket using: wss://stream.binance.com:9443/ws/{listen_key}Sourcepub async fn keepalive(&self, listen_key: &str) -> Result<()>
pub async fn keepalive(&self, listen_key: &str) -> Result<()>
Send a keepalive for a user data stream.
This should be called every 30 minutes to prevent the listen key from expiring. Listen keys expire after 60 minutes without a keepalive.
§Arguments
listen_key- The listen key to keep alive
§Example
ⓘ
let client = Binance::new("api_key", "secret_key")?;
let listen_key = client.user_stream().start().await?;
// Every 30 minutes:
client.user_stream().keepalive(&listen_key).await?;Sourcepub async fn close(&self, listen_key: &str) -> Result<()>
pub async fn close(&self, listen_key: &str) -> Result<()>
Close a user data stream.
This invalidates the listen key and closes any WebSocket connections using it.
§Arguments
listen_key- The listen key to close
§Example
ⓘ
let client = Binance::new("api_key", "secret_key")?;
let listen_key = client.user_stream().start().await?;
// When done:
client.user_stream().close(&listen_key).await?;Trait Implementations§
Source§impl Clone for UserStream
impl Clone for UserStream
Source§fn clone(&self) -> UserStream
fn clone(&self) -> UserStream
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for UserStream
impl !RefUnwindSafe for UserStream
impl Send for UserStream
impl Sync for UserStream
impl Unpin for UserStream
impl !UnwindSafe for UserStream
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
Mutably borrows from an owned value. Read more