Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trade Aggregations endpoint #96

Merged
merged 9 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions stellar_rust_sdk/src/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ pub mod test {
#[tokio::test]
async fn test_get_all_assets() {
static ASSET_TYPE: &str = "credit_alphanum4";
static ASSET_CODE: &str = "004";
static ASSET_ISSUER: &str = "GDJUV2K6YBYUTI6GAA6P6BKVBQQDIOBZYDV2YOWOZI35LLSVMO6J4K7B";
static ASSET_CODE: &str = "001";
static ASSET_ISSUER: &str = "GAIX6Y5CRIH7A67IWGM26J6KIVPNXBHDPUP6KNHYSKFJ6VWABJKZYMKA";
static NUM_ACCOUNTS: &u32 = &1;
static NUM_CLAIMABLE_BALANCES: &u32 = &0;
static NUM_LIQUIDITY_POOLS: &u32 = &0;

static AMOUNT: &str = "999.0000000";
static AMOUNT: &str = "10.0000000";
static AUTHORIZED: &u32 = &1;
static AUTHORIZED_TO_MAINTAIN_LIABILITIES: &u32 = &0;
static UNAUTHORIZED: &u32 = &0;
static CLAIMABLE_BALANCES_AMOUNT: &str = "0.0000000";
static LIQUIDITY_POOLS_AMOUNT: &str = "0.0000000";
static CONTRACTS_AMOUNT: &str = "0.0000000";
static BALANCES_AUTHORIZED: &str = "999.0000000";
static BALANCES_AUTHORIZED: &str = "10.0000000";
static BALANCES_UNAUTHORIZED: &str = "0.0000000";
static AUTH_REQUIRED: &bool = &false;
static AUTH_REVOCABLE: &bool = &false;
Expand Down
47 changes: 47 additions & 0 deletions stellar_rust_sdk/src/horizon_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::{
details_request::{BuyingAsset, DetailsRequest, SellingAsset},
response::DetailsResponse,
},
trade_aggregations::prelude::*,
transactions::prelude::*,
trades::prelude::*,
};
Expand Down Expand Up @@ -1140,6 +1141,52 @@ impl HorizonClient {
self.get::<DetailsResponse>(request).await
}

/// Retrieves a list of trade aggregations from the Horizon server.
///
/// This asynchronous method fetches a list of trade aggregations from the Horizon server.
/// It requires a [`TradeAggregationsRequest`] to specify the parameters for the trade aggregations request.
///
/// # Arguments
/// * `request` - A reference to a [`TradeAggregationsRequest`] instance, containing the parameters for the order book details request.
///
/// # Returns
///
/// On successful execution, returns a `Result` containing a [`AllTradeAggregationsResponse`], which includes the list of order book details obtained from the Horizon server.
/// If the request fails, it returns an error within `Result`.
///
/// # Usage
/// To use this method, create an instance of [`TradeAggregationsRequest`] and set any desired filters or parameters.
///
/// ```rust
/// use stellar_rs::horizon_client::HorizonClient;
/// use stellar_rs::trade_aggregations::prelude::*;
/// use stellar_rs::models::Request;
///
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org".to_string())?;
///
/// // Example: Fetching trade aggregations
/// let request = TradeAggregationsRequest::new()
/// .set_base_asset(AssetType::Native).unwrap()
/// .set_counter_asset(AssetType::Alphanumeric4(AssetData {
/// asset_code: "USDC".to_string(),
/// asset_issuer: "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5".to_string(),
/// })).unwrap()
/// .set_resolution(Resolution(ResolutionData::Duration604800000)).unwrap();
/// let response = horizon_client.get_trade_aggregations(&request).await?;
///
/// // Process the response...
/// # Ok(())
/// # }
/// ```
///
pub async fn get_trade_aggregations(
&self,
request: &TradeAggregationsRequest<BaseAsset, CounterAsset, Resolution>,
) -> Result<AllTradeAggregationsResponse, String> {
self.get::<AllTradeAggregationsResponse>(request).await
}

/// Retrieves a list of all trades from the Horizon server.
///
/// This asynchronous method fetches a list of all trades from the Horizon server.
Expand Down
41 changes: 41 additions & 0 deletions stellar_rust_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,47 @@ pub mod operations;
///
pub mod order_book;

/// Provides `Request` and `Response` structs for retrieving trade aggregation details.
///
/// The `trade_aggregations` module in the Stellar Horizon SDK includes structures and methods that facilitate
/// querying trade aggregations data from the Horizon server.
///
/// # Usage
///
/// This module is used to construct requests for trade aggregations related data and to parse the responses
/// received from the Horizon server. It includes request and response structures for querying
/// trade aggregations.
///
/// # Example
///
/// To use this module, you can create an instance of a request struct, such as `TradeAggregationsRequest`,
/// set any desired query parameters, and pass the request to the `HorizonClient`. The client will
/// then execute the request and return the corresponding response struct, like `AllTradeAggregationsResponse`.
///
/// ```rust
/// use stellar_rs::horizon_client::HorizonClient;
/// use stellar_rs::trade_aggregations::prelude::*;
/// use stellar_rs::models::Request;
///
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org".to_string())?;
///
/// // Example: Fetching trade aggregations
/// let request = TradeAggregationsRequest::new()
/// .set_base_asset(AssetType::Native).unwrap()
/// .set_counter_asset(AssetType::Alphanumeric4(AssetData {
/// asset_code: "USDC".to_string(),
/// asset_issuer: "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5".to_string(),
/// })).unwrap()
/// .set_resolution(Resolution(ResolutionData::Duration604800000)).unwrap();
/// let response = horizon_client.get_trade_aggregations(&request).await?;
///
/// // Process the response...
/// # Ok(())
/// # }
/// ```
pub mod trade_aggregations;

/// Provides `Request` and `Response` structs for retrieving transactions.
///
/// This module provides a set of specialized request and response structures designed for
Expand Down
12 changes: 6 additions & 6 deletions stellar_rust_sdk/src/liquidity_pools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ async fn test_get_all_liquidity_pools() {
const RSP_2_LIQUIDITY_POOL_TOTAL_TRUSTLINES: &str = "1";
const RSP_2_LIQUIDITY_POOL_TOTAL_SHARES: &str = "249.0000000";
const RSP_2_LIQUIDITY_POOL_RESERVE_ASSET_0: &str = "native";
const RSP_2_LIQUIDITY_POOL_RESERVE_AMOUNT_0: &str = "249.0000000";
const RSP_2_LIQUIDITY_POOL_RESERVE_AMOUNT_0: &str = "1249.0000000";
const RSP_2_LIQUIDITY_POOL_RESERVE_ASSET_1: &str =
"FLUTTER:GCGTOQSNERFVVJ6Y7YZYDF3MTZIY63KIEFMKA26Q7YPV3AFYD2JSRNYN";
const RSP_2_LIQUIDITY_POOL_RESERVE_AMOUNT_1: &str = "249.0000000";
const RSP_2_LIQUIDITY_POOL_RESERVE_AMOUNT_1: &str = "49.7600322";

const RSP_3_LIQUIDITY_POOL_ID: &str =
"0b3c88caa5aeada296646c1810893e3b04cba0426cff8ff6a63cf6f35cc7f5b3";
Expand Down Expand Up @@ -294,12 +294,12 @@ async fn test_get_single_liquidity_pool() {
const LIQUIDITY_POOL_TOTAL_SHARES: &str = "249.0000000";
const LIQUIDITY_POOL_RESERVE_ASSET_0: &str =
"native";
const LIQUIDITY_POOL_RESERVE_AMOUNT_0: &str = "249.0000000";
const LIQUIDITY_POOL_RESERVE_AMOUNT_0: &str = "1249.0000000";
const LIQUIDITY_POOL_RESERVE_ASSET_1: &str =
"FLUTTER:GCGTOQSNERFVVJ6Y7YZYDF3MTZIY63KIEFMKA26Q7YPV3AFYD2JSRNYN";
const LIQUIDITY_POOL_RESERVE_AMOUNT_1: &str = "249.0000000";
const LIQUIDITY_POOL_LAST_MODIFIED_LEDGER: i64 = 258622;
const LIQUIDITY_POOL_LAST_MODIFIED_TIME: &str = "2024-06-27T14:27:46Z";
const LIQUIDITY_POOL_RESERVE_AMOUNT_1: &str = "49.7600322";
const LIQUIDITY_POOL_LAST_MODIFIED_LEDGER: i64 = 716080;
const LIQUIDITY_POOL_LAST_MODIFIED_TIME: &str = "2024-07-25T11:09:01Z";

let horizon_client =
HorizonClient::new("https://horizon-testnet.stellar.org".to_string()).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion stellar_rust_sdk/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl std::fmt::Display for Asset<IssuedAsset> {
/// * `Asc` - Indicates ascending order.
/// * `Desc` - Indicates descending order.
///
#[derive(PartialEq, Debug)]
#[derive(Clone, PartialEq, Debug)]
pub enum Order {
Asc,
Desc,
Expand Down
6 changes: 3 additions & 3 deletions stellar_rust_sdk/src/order_book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ pub mod tests {
use crate::horizon_client;
use crate::order_book::prelude::{Asset, AssetType, DetailsRequest};

const BIDS_N: &u32 = &2;
const BIDS_D: &u32 = &1;
const BIDS_PRICE: &str = "2.0000000";
const BIDS_N: &u32 = &3;
const BIDS_D: &u32 = &2;
const BIDS_PRICE: &str = "1.5000000";
const ASKS_N: &u32 = &5;
const ASKS_D: &u32 = &1;
const ASKS_PRICE: &str = "5.0000000";
Expand Down
Loading