-
Notifications
You must be signed in to change notification settings - Fork 11
/
ws_price_limit.rs
36 lines (32 loc) · 1.01 KB
/
ws_price_limit.rs
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
use anyhow::Error;
use fehler::throws;
use futures::{SinkExt, StreamExt};
use okex::websocket::{models::PriceLimit, Channel, Command, Message, OkExWebsocket};
use serde_json::from_value;
#[throws(Error)]
#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
env_logger::init();
let mut client = OkExWebsocket::new().await?;
client
.send(Command::subscribe(vec![Channel::price_limit(
"XCH-USDT-SWAP",
)]))
.await?;
while let Some(x) = client.next().await {
match x.unwrap() {
Message::Data { arg, mut data, .. } => {
assert!(matches!(arg, Channel::PriceLimit { .. }));
let data = data.pop().unwrap();
let x: PriceLimit = from_value(data).unwrap();
println!("{:?}", x)
}
Message::Error { code, msg, .. } => {
println!("Error {}: {}", code, msg)
}
Message::Event { .. } => {}
_ => unreachable!(),
}
}
}