solana_trader_client_rust/provider/ws/
stream.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
use super::WebSocketClient;
use anyhow::Result;
use solana_trader_proto::api;
use tokio_stream::Stream;

impl WebSocketClient {
    pub async fn get_prices_stream(
        &self,
        projects: Vec<api::Project>,
        tokens: Vec<String>,
    ) -> Result<impl Stream<Item = Result<api::GetPricesStreamResponse>>> {
        let request = api::GetPricesStreamRequest {
            projects: projects.iter().map(|&p| p as i32).collect(),
            tokens,
        };

        self.conn.stream_proto("GetPricesStream", &request).await
    }

    pub async fn get_block_stream(
        &self,
    ) -> Result<impl Stream<Item = Result<api::GetBlockStreamResponse>>> {
        let request = api::GetBlockStreamRequest {};

        self.conn.stream_proto("GetBlockStream", &request).await
    }

    pub async fn get_orderbook_stream(
        &self,
        markets: Vec<String>,
        limit: u32,
        project: api::Project,
    ) -> Result<impl Stream<Item = Result<api::GetOrderbooksStreamResponse>>> {
        let request = api::GetOrderbooksRequest {
            markets,
            limit,
            project: project as i32,
        };

        self.conn
            .stream_proto("GetOrderbooksStream", &request)
            .await
    }

    pub async fn get_market_depths_stream(
        &self,
        markets: Vec<String>,
        limit: u32,
        project: api::Project,
    ) -> Result<impl Stream<Item = Result<api::GetMarketDepthsStreamResponse>>> {
        let request = api::GetMarketDepthsRequest {
            markets,
            limit,
            project: project as i32,
        };

        self.conn
            .stream_proto("GetMarketDepthsStream", &request)
            .await
    }

    pub async fn get_ticker_stream(
        &self,
        markets: Vec<String>,
        project: api::Project,
    ) -> Result<impl Stream<Item = Result<api::GetTickersStreamResponse>>> {
        let request = api::GetTickersStreamRequest {
            markets,
            project: project as i32,
        };

        self.conn.stream_proto("GetTickersStream", &request).await
    }

    pub async fn get_trades_stream(
        &self,
        market: String,
        limit: u32,
        project: api::Project,
    ) -> Result<impl Stream<Item = Result<api::GetTradesStreamResponse>>> {
        let request = api::GetTradesRequest {
            market,
            limit,
            project: project as i32,
        };

        self.conn.stream_proto("GetTradesStream", &request).await
    }

    pub async fn get_swaps_stream(
        &self,
        projects: Vec<api::Project>,
        pools: Vec<String>,
        include_failed: bool,
    ) -> Result<impl Stream<Item = Result<api::GetSwapsStreamResponse>>> {
        let request = api::GetSwapsStreamRequest {
            projects: projects.iter().map(|&p| p as i32).collect(),
            pools,
            include_failed,
        };

        self.conn.stream_proto("GetSwapsStream", &request).await
    }

    pub async fn get_new_raydium_pools_stream(
        &self,
        include_cpmm: bool,
    ) -> Result<impl Stream<Item = Result<api::GetNewRaydiumPoolsResponse>>> {
        let request = api::GetNewRaydiumPoolsRequest {
            include_cpmm: Some(include_cpmm),
        };

        self.conn
            .stream_proto("GetNewRaydiumPoolsStream", &request)
            .await
    }

    pub async fn get_new_raydium_pools_by_transaction_stream(
        &self,
    ) -> Result<impl Stream<Item = Result<api::GetNewRaydiumPoolsByTransactionResponse>>> {
        let request = api::GetNewRaydiumPoolsByTransactionRequest {};

        self.conn
            .stream_proto("GetNewRaydiumPoolsByTransactionStream", &request)
            .await
    }

    pub async fn get_recent_block_hash_stream(
        &self,
    ) -> Result<impl Stream<Item = Result<api::GetRecentBlockHashResponse>>> {
        let request = api::GetRecentBlockHashRequest {};

        self.conn
            .stream_proto("GetRecentBlockHashStream", &request)
            .await
    }

    pub async fn get_pool_reserves_stream(
        &self,
        projects: Vec<api::Project>,
        pools: Vec<String>,
    ) -> Result<impl Stream<Item = Result<api::GetPoolReservesStreamResponse>>> {
        let request = api::GetPoolReservesStreamRequest {
            projects: projects.iter().map(|&p| p as i32).collect(),
            pools,
        };

        self.conn
            .stream_proto("GetPoolReservesStream", &request)
            .await
    }

    pub async fn get_priority_fee_stream(
        &self,
        project: api::Project,
        percentile: Option<f64>,
    ) -> Result<impl Stream<Item = Result<api::GetPriorityFeeResponse>>> {
        let request = api::GetPriorityFeeRequest {
            project: project as i32,
            percentile,
        };

        self.conn
            .stream_proto("GetPriorityFeeStream", &request)
            .await
    }

    pub async fn get_bundle_tip_stream(
        &self,
    ) -> Result<impl Stream<Item = Result<api::GetBundleTipResponse>>> {
        let request = api::GetBundleTipRequest {};

        self.conn.stream_proto("GetBundleTipStream", &request).await
    }

    pub async fn get_pump_fun_new_tokens_stream(
        &self,
    ) -> Result<impl Stream<Item = Result<api::GetPumpFunNewTokensStreamResponse>>> {
        let request = api::GetPumpFunNewTokensStreamRequest {};

        self.conn
            .stream_proto("GetPumpFunNewTokensStream", &request)
            .await
    }

    pub async fn get_pump_fun_swaps_stream(
        &self,
        tokens: Vec<String>,
    ) -> Result<impl Stream<Item = Result<api::GetPumpFunSwapsStreamResponse>>> {
        let request = api::GetPumpFunSwapsStreamRequest { tokens };

        self.conn
            .stream_proto("GetPumpFunSwapsStream", &request)
            .await
    }
}