solana_trader_client_rust/provider/grpc/
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
use anyhow::Result;
use solana_trader_proto::api;
use tonic::Request;
use tonic::Streaming;

use super::GrpcClient;

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

        let response = self
            .client
            .get_prices_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetPricesStream error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_block_stream(&mut self) -> Result<Streaming<api::GetBlockStreamResponse>> {
        let request = Request::new(api::GetBlockStreamRequest {});

        let response = self
            .client
            .get_block_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetBlockStream error: {}", e))?;

        Ok(response.into_inner())
    }

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

        let response = self
            .client
            .get_orderbooks_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetOrderbooksStream error: {}", e))?;

        Ok(response.into_inner())
    }

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

        let response = self
            .client
            .get_market_depths_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetMarketDepthsStream error: {}", e))?;

        Ok(response.into_inner())
    }

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

        let response = self
            .client
            .get_tickers_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetTickersStream error: {}", e))?;

        Ok(response.into_inner())
    }

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

        let response = self
            .client
            .get_trades_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetTradesStream error: {}", e))?;

        Ok(response.into_inner())
    }

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

        let response = self
            .client
            .get_swaps_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetSwapsStream error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_new_raydium_pools_stream(
        &mut self,
        include_cpmm: bool,
    ) -> Result<Streaming<api::GetNewRaydiumPoolsResponse>> {
        let request = Request::new(api::GetNewRaydiumPoolsRequest {
            include_cpmm: Some(include_cpmm),
        });

        let response = self
            .client
            .get_new_raydium_pools_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetNewRaydiumPoolsStream error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_new_raydium_pools_by_transaction_stream(
        &mut self,
    ) -> Result<Streaming<api::GetNewRaydiumPoolsByTransactionResponse>> {
        let request = Request::new(api::GetNewRaydiumPoolsByTransactionRequest {});

        let response = self
            .client
            .get_new_raydium_pools_by_transaction_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetNewRaydiumPoolsByTransactionStream error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_recent_block_hash_stream(
        &mut self,
    ) -> Result<Streaming<api::GetRecentBlockHashResponse>> {
        let request = Request::new(api::GetRecentBlockHashRequest {});

        let response = self
            .client
            .get_recent_block_hash_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetRecentBlockHashStream error: {}", e))?;

        Ok(response.into_inner())
    }

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

        let response = self
            .client
            .get_pool_reserves_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetPoolReservesStream error: {}", e))?;

        Ok(response.into_inner())
    }

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

        let response = self
            .client
            .get_priority_fee_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetPriorityFeeStream error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_bundle_tip_stream(&mut self) -> Result<Streaming<api::GetBundleTipResponse>> {
        let request = Request::new(api::GetBundleTipRequest {});

        let response = self
            .client
            .get_bundle_tip_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetBundleTipStream error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_pump_fun_new_tokens_stream(
        &mut self,
    ) -> Result<Streaming<api::GetPumpFunNewTokensStreamResponse>> {
        let request = Request::new(api::GetPumpFunNewTokensStreamRequest {});

        let response = self
            .client
            .get_pump_fun_new_tokens_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetPumpFunNewTokensStream error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_pump_fun_swaps_stream(
        &mut self,
        tokens: Vec<String>,
    ) -> Result<Streaming<api::GetPumpFunSwapsStreamResponse>> {
        let request = Request::new(api::GetPumpFunSwapsStreamRequest { tokens });

        let response = self
            .client
            .get_pump_fun_swaps_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetPumpFunSwapsStream error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_priority_fee_by_program_stream(
        &mut self,
        projects: Vec<String>,
    ) -> Result<Streaming<api::GetPriorityFeeByProgramResponse>> {
        let request = Request::new(api::GetPriorityFeeByProgramRequest { programs: projects });

        let response = self
            .client
            .get_priority_fee_by_program_stream(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetPriorityFeeByProjectStream error: {}", e))?;

        Ok(response.into_inner())
    }
}