1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use KrakenClient;
use env;
async
// use std::env;
// use std::time::Duration;
// use tokio::time::sleep;
// use onise::error::KrakenResult;
// use onise::ws_client::KrakenWsClient; // or your own error module
// #[tokio::main]
// async fn main() -> KrakenResult<()> {
// // Read an environment variable for the WebSocket URL, default to Kraken Spot v2
// let url = env::var("WS_URL").unwrap_or_else(|_| "wss://ws.kraken.com/v2".to_string());
// // Optionally read an auth token for private streams
// let token = env::var("KRAKEN_WS_TOKEN").ok();
// // Connect to the WebSocket
// let client = KrakenWsClient::connect(&url).await?;
// // If you have a token, store it in the client or call `authorize(...)`
// if let Some(t) = token {
// client.authorize(&t, Some(1)).await?;
// // Optionally also store in client if you want:
// // client.token = Some(t);
// }
// // Send a ping to confirm we can write messages
// client.send_ping(Some(2)).await?;
// // Subscribe to a Ticker channel if we want market data
// client
// .subscribe(
// onise::ws_models::WsSubscriptionPayload::Ticker {
// symbol: "XBT/USD".into(),
// },
// Some(3),
// )
// .await?;
// // Let the process run so we can see inbound messages
// // In a production service, you might catch signals or run until cancelled.
// // For demonstration, we'll just loop every 10 seconds.
// println!("Connected to {url}. Listening for messages...");
// loop {
// sleep(Duration::from_secs(10)).await;
// // You could do more requests here, or just keep it running
// }
// }