noah_sdk/api/
transactions.rs1use crate::client::NoahClient;
4use crate::error::Result;
5use crate::models::common::*;
6use crate::models::transactions::{
7 GetTransactionsResponse, PrepareSellRequest, PrepareSellResponse, SellRequest, SellResponse,
8 Transaction,
9};
10
11impl NoahClient {
12 #[cfg(feature = "async")]
14 pub async fn get_transactions(
15 &self,
16 page_size: Option<u32>,
17 page_token: Option<&str>,
18 sort_direction: Option<&SortDirection>,
19 ) -> Result<GetTransactionsResponse> {
20 let mut path = "/transactions".to_string();
21 let mut query_params = Vec::new();
22
23 if let Some(size) = page_size {
24 query_params.push(format!("PageSize={size}"));
25 }
26 if let Some(token) = page_token {
27 query_params.push(format!("PageToken={token}"));
28 }
29 if let Some(sort) = sort_direction {
30 query_params.push(format!("SortDirection={sort:?}"));
31 }
32
33 if !query_params.is_empty() {
34 path.push('?');
35 path.push_str(&query_params.join("&"));
36 }
37
38 self.get(&path).await
39 }
40
41 #[cfg(feature = "sync")]
43 pub fn get_transactions_blocking(
44 &self,
45 page_size: Option<u32>,
46 page_token: Option<&str>,
47 sort_direction: Option<&SortDirection>,
48 ) -> Result<GetTransactionsResponse> {
49 let mut path = "/transactions".to_string();
50 let mut query_params = Vec::new();
51
52 if let Some(size) = page_size {
53 query_params.push(format!("PageSize={size}"));
54 }
55 if let Some(token) = page_token {
56 query_params.push(format!("PageToken={token}"));
57 }
58 if let Some(sort) = sort_direction {
59 query_params.push(format!("SortDirection={sort:?}"));
60 }
61
62 if !query_params.is_empty() {
63 path.push('?');
64 path.push_str(&query_params.join("&"));
65 }
66
67 self.get_blocking(&path)
68 }
69
70 #[cfg(feature = "async")]
72 pub async fn get_transaction(&self, transaction_id: &str) -> Result<Transaction> {
73 let path = format!("/transactions/{transaction_id}");
74 self.get(&path).await
75 }
76
77 #[cfg(feature = "sync")]
79 pub fn get_transaction_blocking(&self, transaction_id: &str) -> Result<Transaction> {
80 let path = format!("/transactions/{transaction_id}");
81 self.get_blocking(&path)
82 }
83
84 #[cfg(feature = "async")]
86 pub async fn prepare_sell(&self, request: &PrepareSellRequest) -> Result<PrepareSellResponse> {
87 self.post("/transactions/sell/prepare", request).await
88 }
89
90 #[cfg(feature = "sync")]
92 pub fn prepare_sell_blocking(
93 &self,
94 request: &PrepareSellRequest,
95 ) -> Result<PrepareSellResponse> {
96 self.post_blocking("/transactions/sell/prepare", request)
97 }
98
99 #[cfg(feature = "async")]
101 pub async fn sell(&self, request: &SellRequest) -> Result<SellResponse> {
102 self.post("/transactions/sell", request).await
103 }
104
105 #[cfg(feature = "sync")]
107 pub fn sell_blocking(&self, request: &SellRequest) -> Result<SellResponse> {
108 self.post_blocking("/transactions/sell", request)
109 }
110}