renegade_sdk/external_match_client/
v1_client.rs1use crate::{
7 ExternalMatchOptions, RequestQuoteOptions,
8 api_types::v1_types::{
9 ExternalMatchResponse, ExternalOrder, GetDepthByMintResponse, GetDepthForAllPairsResponse,
10 GetSupportedTokensResponse, GetTokenPricesResponse, SignedExternalQuote,
11 },
12};
13
14use super::{
15 ExternalMatchClient, ExternalMatchClientError,
16 options::AssembleQuoteOptions,
17 v1_conversions::{
18 market_depth_to_v1, market_depths_to_v1, markets_to_supported_tokens,
19 markets_to_token_prices, v1_assemble_options_to_v2, v1_order_to_v2, v1_quote_to_v2,
20 v2_quote_to_v1, v2_response_to_v1_non_malleable,
21 },
22};
23
24impl ExternalMatchClient {
25 #[deprecated(
31 since = "2.0.0",
32 note = "Use get_markets instead, which returns all supported tokens along with their current price"
33 )]
34 pub async fn get_supported_tokens(
35 &self,
36 ) -> Result<GetSupportedTokensResponse, ExternalMatchClientError> {
37 let resp = self.get_markets().await?;
38 Ok(markets_to_supported_tokens(&resp))
39 }
40
41 #[deprecated(
43 since = "2.0.0",
44 note = "Use get_markets instead, which returns all supported tokens along with their current price"
45 )]
46 pub async fn get_token_prices(
47 &self,
48 ) -> Result<GetTokenPricesResponse, ExternalMatchClientError> {
49 let resp = self.get_markets().await?;
50 markets_to_token_prices(&resp)
51 }
52
53 #[deprecated(since = "2.0.0", note = "Use get_market_depth instead")]
57 pub async fn get_order_book_depth(
58 &self,
59 address: &str,
60 ) -> Result<GetDepthByMintResponse, ExternalMatchClientError> {
61 let resp = self.get_market_depth(address).await?;
62 market_depth_to_v1(&resp)
63 }
64
65 #[deprecated(since = "2.0.0", note = "Use get_market_depths_all_pairs instead")]
67 pub async fn get_order_book_depth_all_pairs(
68 &self,
69 ) -> Result<GetDepthForAllPairsResponse, ExternalMatchClientError> {
70 let resp = self.get_market_depths_all_pairs().await?;
71 market_depths_to_v1(&resp)
72 }
73
74 pub async fn request_quote(
80 &self,
81 order: ExternalOrder,
82 ) -> Result<Option<SignedExternalQuote>, ExternalMatchClientError> {
83 self.request_quote_with_options(order, RequestQuoteOptions::default()).await
84 }
85
86 pub async fn request_quote_with_options(
88 &self,
89 order: ExternalOrder,
90 options: RequestQuoteOptions,
91 ) -> Result<Option<SignedExternalQuote>, ExternalMatchClientError> {
92 let v2_order = v1_order_to_v2(&order);
93 let v2_quote = self.request_quote_with_options_v2(v2_order, options).await?;
94 v2_quote.map(|q| v2_quote_to_v1(q, &order)).transpose()
95 }
96
97 pub async fn assemble_quote(
101 &self,
102 quote: SignedExternalQuote,
103 ) -> Result<Option<ExternalMatchResponse>, ExternalMatchClientError> {
104 self.assemble_quote_with_options(quote, AssembleQuoteOptions::default()).await
105 }
106
107 pub async fn assemble_quote_with_options(
111 &self,
112 quote: SignedExternalQuote,
113 options: AssembleQuoteOptions,
114 ) -> Result<Option<ExternalMatchResponse>, ExternalMatchClientError> {
115 let direction = quote.quote.order.side.clone();
116 let v2_quote = v1_quote_to_v2("e);
117 let v2_options = v1_assemble_options_to_v2(&options);
118 let v2_resp = self.assemble_quote_with_options_v2(v2_quote, v2_options).await?;
119 v2_resp.map(|r| v2_response_to_v1_non_malleable(r, direction)).transpose()
120 }
121
122 pub async fn request_external_match(
130 &self,
131 order: ExternalOrder,
132 ) -> Result<Option<ExternalMatchResponse>, ExternalMatchClientError> {
133 self.request_external_match_with_options(order, Default::default()).await
134 }
135
136 pub async fn request_external_match_with_options(
140 &self,
141 order: ExternalOrder,
142 options: ExternalMatchOptions,
143 ) -> Result<Option<ExternalMatchResponse>, ExternalMatchClientError> {
144 let direction = order.side.clone();
145 let v2_order = v1_order_to_v2(&order);
146 let v2_resp = self.request_external_match_with_options_v2(v2_order, options).await?;
147 v2_resp.map(|r| v2_response_to_v1_non_malleable(r, direction)).transpose()
148 }
149}