-
Notifications
You must be signed in to change notification settings - Fork 3
/
subscribe.rs
53 lines (50 loc) · 1.52 KB
/
subscribe.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use futuapi_rs::{
action::subscribe::SubscribeRequest, client, frame::Error, Qot_Common::SubType, Result,
UpdateResponse,
};
#[tokio::main]
pub async fn main() -> Result<()> {
let sub_client = client::sub_connect("127.0.0.1:11111").await?;
let mut sub = sub_client
.subscribe(SubscribeRequest::new(
vec!["HK.00700".try_into().unwrap()],
vec![
SubType::SubType_Basic,
SubType::SubType_RT,
SubType::SubType_KL_1Min,
],
true,
Some(true),
Vec::new(),
Some(true),
Some(false),
Some(false),
Some(true),
))
.await?;
loop {
match sub.next_data().await {
Ok(Some(update_resp)) => match update_resp {
UpdateResponse::BasicQot(update_basic_qot_resp) => {
println!("{:?}", update_basic_qot_resp);
}
UpdateResponse::RT(update_rt_resp) => {
println!("{:?}", update_rt_resp);
}
UpdateResponse::KL(update_kl_resp) => {
println!("{:?}", update_kl_resp);
}
},
Ok(None) => {
continue;
}
Err(e) => {
let err = e.downcast::<Error>()?;
if let Error::Timeout(_) = *err {
continue;
}
return Err(err.into());
}
}
}
}