stellar_rs/order_book/
mod.rs1pub mod details_request;
2pub mod response;
3
4static ORDER_BOOK_PATH: &str = "order_book";
5
6pub mod prelude {
7 pub use super::details_request::*;
8 pub use super::response::*;
9}
10
11pub mod tests {
12
13 #[tokio::test]
14 async fn get_order_bookdetails() {
15 use crate::horizon_client;
16 use crate::models::prelude::*;
17 use crate::order_book::prelude::DetailsRequest;
18
19 const BIDS_N: &u32 = &1;
20 const BIDS_D: &u32 = &5;
21 const BIDS_PRICE: &str = "0.2000000";
22 const ASKS_N: &u32 = &5;
23 const ASKS_D: &u32 = &1;
24 const ASKS_PRICE: &str = "5.0000000";
25 const BASE_ASSET_TYPE: &str = "native";
26 const BASE_ASSET_CODE: &str = "IOM";
27 const BASE_ASSET_ISSUER: &str = "GCDE6MVFIOYF7YZCSVA6V7MDCFTNWMIOF5PQU3DWPH27AHNX4ERY6AKS";
28 const COUNTER_ASSET_TYPE: &str = "credit_alphanum4";
29
30 let horizon_client =
31 horizon_client::HorizonClient::new("https://horizon-testnet.stellar.org").unwrap();
32
33 let details_request = DetailsRequest::new()
34 .set_selling_asset(AssetType::Native)
35 .unwrap()
36 .set_buying_asset(AssetType::Alphanumeric4(AssetData {
37 asset_code: "IOM".to_string(),
38 asset_issuer: "GCDE6MVFIOYF7YZCSVA6V7MDCFTNWMIOF5PQU3DWPH27AHNX4ERY6AKS"
39 .to_string(),
40 }))
41 .unwrap();
42
43 let details_response = horizon_client
44 .get_order_book_details(&details_request)
45 .await;
46
47 assert!(details_response.is_ok());
48
49 let binding = details_response.unwrap();
50
51 assert_eq!(binding.bids()[0].price_ratio().numenator(), BIDS_N);
52 assert_eq!(binding.bids()[0].price_ratio().denominator(), BIDS_D);
53 assert_eq!(binding.bids()[0].price(), BIDS_PRICE);
54
55 assert_ne!(binding.bids()[0].amount(), "0");
57
58 assert_eq!(binding.asks()[0].price_ratio().numenator(), ASKS_N);
59 assert_eq!(binding.asks()[0].price_ratio().denominator(), ASKS_D);
60 assert_eq!(binding.asks()[0].price(), ASKS_PRICE);
61 assert_ne!(binding.asks()[0].amount(), "0");
63
64 assert_eq!(
65 binding.base().asset_type().as_deref(),
66 Some(BASE_ASSET_TYPE)
67 );
68 assert_eq!(binding.base().asset_code().as_deref(), None);
69 assert_eq!(binding.base().asset_issuer().as_deref(), None);
70
71 assert_eq!(
72 binding.counter().asset_type().as_deref(),
73 Some(COUNTER_ASSET_TYPE)
74 );
75
76 assert_eq!(
77 binding.counter().asset_code().as_deref(),
78 Some(BASE_ASSET_CODE)
79 );
80
81 assert_eq!(
82 binding.counter().asset_issuer().as_deref(),
83 Some(BASE_ASSET_ISSUER)
84 );
85 }
86}