pub struct KrakenClient {
pub(crate) ws_url: String,
pub(crate) event_sender: Sender<KrakenEvent>,
pub(crate) command_sender: Sender<Command>,
pub(crate) command_receiver: Mutex<Option<Receiver<Command>>>,
}Fields§
§ws_url: String§event_sender: Sender<KrakenEvent>§command_sender: Sender<Command>§command_receiver: Mutex<Option<Receiver<Command>>>Implementations§
Source§impl KrakenClient
impl KrakenClient
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new KrakenClient instance.
This initializes the internal channels but does not connect to the WebSocket yet.
Call connect() to establish the connection.
Sourcepub fn subscribe_events(&self) -> Receiver<KrakenEvent>
pub fn subscribe_events(&self) -> Receiver<KrakenEvent>
Returns a broadcast receiver for Kraken events.
You can call this multiple times to create multiple subscribers (e.g., one for logging, one for trading).
Sourcepub async fn subscribe(
&self,
pairs: Vec<String>,
name: &str,
token: Option<String>,
) -> Result<()>
pub async fn subscribe( &self, pairs: Vec<String>, name: &str, token: Option<String>, ) -> Result<()>
Subscribes to a list of pairs on a specific channel.
§Arguments
pairs- A list of trading pairs (e.g.,vec!["XBT/USD".to_string()]).name- The channel name (e.g.,"trade","book","ticker").
§Example
let client = KrakenClient::new();
client.subscribe(vec!["XBT/USD".to_string()], "trade", None).await.unwrap();Sourcepub async fn connect(&self) -> Result<()>
pub async fn connect(&self) -> Result<()>
Connects to the Kraken WebSocket API and starts the event loop.
This spawns a background task that handles:
- WebSocket connection and reconnection.
- Parsing incoming messages.
- Sending outgoing commands.
- Broadcasting events to subscribers.
§Errors
Returns an error if the client has already connected (the command receiver is taken).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for KrakenClient
impl !RefUnwindSafe for KrakenClient
impl Send for KrakenClient
impl Sync for KrakenClient
impl Unpin for KrakenClient
impl !UnwindSafe for KrakenClient
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