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 std::task::Poll;
use std::ops::Drop;
use futures::{Stream, StreamExt};
use ib_tws_core::CommandChannel;
use ib_tws_core::message::response::*;
use ib_tws_core::message::request::*;
#[derive(Debug)]
pub struct TwsClient {
pub channel: CommandChannel<Request, Response>,
pub server_version: i32,
}
impl TwsClient {
pub fn send_request(&self, req: Request) {
trace!(?req, "sending request");
let _ = self.channel.tx.unbounded_send(req);
}
}
impl Stream for TwsClient {
type Item = Response;
fn poll_next(mut self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Option<Self::Item>> {
self.channel.rx.poll_next_unpin(cx)
}
}
impl Drop for TwsClient {
fn drop(&mut self) {
trace!("drop client");
}
}