use serde_json::Value;
use crate::Result;
use crate::client::Client;
use crate::models::ListenKey;
const API_V3_USER_DATA_STREAM: &str = "/api/v3/userDataStream";
#[derive(Clone)]
pub struct UserStream {
client: Client,
}
impl UserStream {
pub(crate) fn new(client: Client) -> Self {
Self { client }
}
pub async fn start(&self) -> Result<String> {
let response: ListenKey = self
.client
.post_with_key(API_V3_USER_DATA_STREAM, &[])
.await?;
Ok(response.listen_key)
}
pub async fn keepalive(&self, listen_key: &str) -> Result<()> {
let params = [("listenKey", listen_key)];
let _: Value = self
.client
.put_with_key(API_V3_USER_DATA_STREAM, ¶ms)
.await?;
Ok(())
}
pub async fn close(&self, listen_key: &str) -> Result<()> {
let params = [("listenKey", listen_key)];
let _: Value = self
.client
.delete_with_key(API_V3_USER_DATA_STREAM, ¶ms)
.await?;
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_api_endpoint() {
assert_eq!(API_V3_USER_DATA_STREAM, "/api/v3/userDataStream");
}
}