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 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
use anyhow::Result;
use chrono::Utc;
use crate::{api_get_depth_and_price_history, api_get_earnings_history, api_get_liquidity_change_history, api_get_savers_units_and_depth_history, api_get_swaps_history, api_get_total_value_locked_history, DepthHistory, EarningsHistory, Interval, LiquidityChangeHistory, Midgard, SaversHistory, SwapHistory, TVLHistory};
impl Midgard {
/// Returns the asset and rune depths and price. The values report the state at the end of each interval.
/// History endpoint has two modes:
/// * With Interval parameter it returns a series of time buckets. From and To dates will be rounded to the Interval boundaries.
/// * Without Interval parameter a single From..To search is performed with exact timestamps.
/// * Interval: possible values: 5min, hour, day, week, month, quarter, year.
/// * count: [1..400]. Defines number of intervals. Don't provide if Interval is missing.
/// * from/to: optional int, unix second.
///
/// Possible usages with interval.
/// * last 10 days: ?interval=day&count=10
/// * last 10 days before to: ?interval=day&count=10&to=1608825600
/// * next 10 days after from: ?interval=day&count=10&from=1606780800
/// * Days between from and to. From defaults to start of chain, to defaults to now. Only the first 400 intervals are returned: interval=day&from=1606780800&to=1608825600
///
/// Pagination is possible with from&count and then using the returned meta.endTime as the From parameter of the next query.
///
/// Possible configurations without interval:
/// * exact search for one time frame: ?from=1606780899&to=1608825600
/// * one time frame until now: ?from=1606780899
/// * from chain start until now: no query parameters
///
/// # Example
///
/// ```rust
/// use midgard_rs::Midgard;
/// use midgard_rs::Interval;
///
/// # tokio_test::block_on(async {
/// // Create a new instance of Midgard
/// let mut midgard = Midgard::new();
///
/// // Get depth & price history
/// let depth_history = midgard.get_depth_and_price_history("BTC.BTC", Some(Interval::Day), Some(10), None, None).await.unwrap();
///
/// assert!(!depth_history.get_intervals().is_empty());
/// # });
/// ```
///
/// To get paginated responses, you can pass the `end_time` from the previous response to the next request.
///
/// ```
/// use midgard_rs::Midgard;
/// use midgard_rs::Interval;
///
/// # std::thread::sleep(std::time::Duration::from_secs(10));
/// # tokio_test::block_on(async {
/// // Create a new instance of Midgard
/// let mut midgard = Midgard::new();
///
/// // Get depth & price history
/// let depth_history = midgard.get_depth_and_price_history("BTC.BTC", Some(Interval::Day), Some(10), None, None).await.unwrap();
///
/// assert!(!depth_history.get_intervals().is_empty());
///
/// // Get the end time
/// let end_time = depth_history.get_meta().get_end_time().timestamp() as u64;
///
/// let depth_history = midgard.get_depth_and_price_history("BTC.BTC", Some(Interval::Day), Some(10), None, Some(end_time)).await.unwrap();
///
/// assert!(!depth_history.get_intervals().is_empty());
/// # });
/// ```
///
/// # Errors
/// todo
pub async fn get_depth_and_price_history(&mut self, pool: &str, interval: Option<Interval>, count: Option<usize>, to: Option<u64>, from: Option<u64>) -> Result<DepthHistory> {
// Wait for rate limit timer
self.sleep_until_ok_to_call().await;
self.set_last_call(Utc::now());
api_get_depth_and_price_history(self.get_config().get_base_url(), pool, interval, count, to, from).await
}
/// Returns earnings data for the specified interval.
///
/// History endpoint has two modes:
/// * With Interval parameter it returns a series of time buckets. From and To dates will be rounded to the Interval boundaries.
/// * Without Interval parameter a single From..To search is performed with exact timestamps.
/// * Interval: possible values: 5min, hour, day, week, month, quarter, year.
/// * count: [1..400]. Defines number of intervals. Don't provide if Interval is missing.
/// * from/to: optional int, unix second.
///
/// Possible usages with interval.
/// * last 10 days: ?interval=day&count=10
/// * last 10 days before to: ?interval=day&count=10&to=1608825600
/// * next 10 days after from: ?interval=day&count=10&from=1606780800
/// * Days between from and to. From defaults to start of chain, to defaults to now. Only the first 400 intervals are returned: interval=day&from=1606780800&to=1608825600
///
/// Pagination is possible with from&count and then using the returned meta.endTime as the From parameter of the next query.
///
/// Possible configurations without interval:
/// * exact search for one time frame: ?from=1606780899&to=1608825600
/// * one time frame until now: ?from=1606780899
/// * from chain start until now: no query parameters
///
/// # Example
///
/// ```rust
/// use midgard_rs::Midgard;
/// use midgard_rs::Interval;
///
/// # tokio_test::block_on(async {
/// // Create a new instance of Midgard
///let mut midgard = Midgard::new();
///
///// Get depth & price history
///let depth_history = midgard.get_depth_and_price_history("BTC.BTC", Some(Interval::Day), Some(10), None, None).await.unwrap();
///
///assert!(!depth_history.get_intervals().is_empty());
/// # });
/// ```
///
/// To get paginated responses, you can pass the `end_time` from the previous response to the next request.
/// ```rust
/// use midgard_rs::Midgard;
/// use midgard_rs::Interval;
///
/// # std::thread::sleep(std::time::Duration::from_secs(10));
/// # tokio_test::block_on(async {
/// // Create a new instance of Midgard
/// let mut midgard = Midgard::new();
///
/// // Get depth & price history
/// let depth_history = midgard.get_depth_and_price_history("BTC.BTC", Some(Interval::Day), Some(10), None, None).await.unwrap();
///
/// assert!(!depth_history.get_intervals().is_empty());
///
/// // Get the end time
/// let end_time = depth_history.get_meta().get_end_time().timestamp() as u64;
///
/// let depth_history = midgard.get_depth_and_price_history("BTC.BTC", Some(Interval::Day), Some(10), None, Some(end_time)).await.unwrap();
///
/// assert!(!depth_history.get_intervals().is_empty());
/// # });
/// ```
///
/// # Errors
/// todo
pub async fn get_earnings_history(&mut self, interval: Option<Interval>, count: Option<usize>, to: Option<u64>, from: Option<u64>) -> Result<EarningsHistory> {
// Wait for rate limit timer
self.sleep_until_ok_to_call().await;
self.set_last_call(Utc::now());
api_get_earnings_history(self.get_config().get_base_url(), interval, count, to, from).await
}
/// Returns withdrawals and deposits for given time interval. If pool is not specified returns for all pools
///
/// History endpoint has two modes:
/// * With Interval parameter it returns a series of time buckets. From and To dates will be rounded to the Interval boundaries.
/// * Without Interval parameter a single From..To search is performed with exact timestamps.
/// * Interval: possible values: 5min, hour, day, week, month, quarter, year.
/// * count: [1..400]. Defines number of intervals. Don't provide if Interval is missing.
/// * from/to: optional int, unix second.
///
/// Possible usages with interval.
/// * last 10 days: ?interval=day&count=10
/// * last 10 days before to: ?interval=day&count=10&to=1608825600
/// * next 10 days after from: ?interval=day&count=10&from=1606780800
/// * Days between from and to. From defaults to start of chain, to defaults to now. Only the first 400 intervals are returned: interval=day&from=1606780800&to=1608825600
///
/// Pagination is possible with from&count and then using the returned meta.endTime as the From parameter of the next query.
///
/// Possible configurations without interval:
/// * exact search for one time frame: ?from=1606780899&to=1608825600
/// * one time frame until now: ?from=1606780899
/// * from chain start until now: no query parameters
///
/// # Example
/// ```rust
/// use midgard_rs::Midgard;
/// use midgard_rs::Interval;
///
/// # tokio_test::block_on(async {
/// // Create a new instance of Midgard
/// let mut midgard = Midgard::new();
///
/// // Get liquidity change history
/// let liquidity_change_history = midgard.get_liquidity_change_history("BTC.BTC", Some(Interval::Day), Some(10), None, None).await.unwrap();
///
/// assert!(!liquidity_change_history.get_intervals().is_empty());
/// # });
/// ```
///
/// To get paginated responses, you can pass the `end_time` from the previous response to the next request.
/// ```rust
/// use midgard_rs::Midgard;
/// use midgard_rs::Interval;
///
/// # std::thread::sleep(std::time::Duration::from_secs(10));
/// # tokio_test::block_on(async {
/// // Create a new instance of Midgard
/// let mut midgard = Midgard::new();
///
/// // Get liquidity change history
/// let liquidity_change_history = midgard.get_liquidity_change_history("BTC.BTC", Some(Interval::Day), Some(10), None, None).await.unwrap();
///
/// assert!(!liquidity_change_history.get_intervals().is_empty());
///
/// // Get the end time
/// let end_time = liquidity_change_history.get_meta().get_end_time().timestamp() as u64;
///
/// let liquidity_change_history = midgard.get_liquidity_change_history("BTC.BTC", Some(Interval::Day), Some(10), None, Some(end_time)).await.unwrap();
///
/// assert!(!liquidity_change_history.get_intervals().is_empty());
/// # });
/// ```
///
/// # Errors
/// todo
pub async fn get_liquidity_change_history(&mut self, pool: &str, interval: Option<Interval>, count: Option<usize>, to: Option<u64>, from: Option<u64>) -> Result<LiquidityChangeHistory> {
// Wait for rate limit timer
self.sleep_until_ok_to_call().await;
self.set_last_call(Utc::now());
api_get_liquidity_change_history(self.get_config().get_base_url(), pool, interval, count, to, from).await
}
/// Returns savers depths and units. The values report the state at the end of each interval.
///
/// History endpoint has two modes:
/// * With Interval parameter it returns a series of time buckets. From and To dates will be rounded to the Interval boundaries.
/// * Without Interval parameter a single From..To search is performed with exact timestamps.
/// * Interval: possible values: 5min, hour, day, week, month, quarter, year.
/// * count: [1..400]. Defines number of intervals. Don't provide if Interval is missing.
/// * from/to: optional int, unix second.
///
/// Possible usages with interval.
/// * last 10 days: ?interval=day&count=10
/// * last 10 days before to: ?interval=day&count=10&to=1608825600
/// * next 10 days after from: ?interval=day&count=10&from=1606780800
/// * Days between from and to. From defaults to start of chain, to defaults to now. Only the first 400 intervals are returned: interval=day&from=1606780800&to=1608825600
///
/// Pagination is possible with from&count and then using the returned meta.endTime as the From parameter of the next query.
///
/// Possible configurations without interval:
/// * exact search for one time frame: ?from=1606780899&to=1608825600
/// * one time frame until now: ?from=1606780899
/// * from chain start until now: no query parameters
///
/// # Example
/// ```rust
/// use midgard_rs::Midgard;
/// use midgard_rs::Interval;
///
/// # tokio_test::block_on(async {
/// // Create a new instance of Midgard
/// let mut midgard = Midgard::new();
///
/// // Get savers units and depth history
/// let savers_history = midgard.get_savers_units_and_depth_history("BTC.BTC", Some(Interval::Day), Some(10), None, None).await.unwrap();
///
/// assert!(!savers_history.get_intervals().is_empty());
/// # });
/// ```
///
/// To get paginated responses, you can pass the `end_time` from the previous response to the next request.
/// ```rust
/// use midgard_rs::Midgard;
/// use midgard_rs::Interval;
///
/// # std::thread::sleep(std::time::Duration::from_secs(10));
/// # tokio_test::block_on(async {
/// // Create a new instance of Midgard
/// let mut midgard = Midgard::new();
///
/// // Get savers units and depth history
/// let savers_history = midgard.get_savers_units_and_depth_history("BTC.BTC", Some(Interval::Day), Some(10), None, None).await.unwrap();
/// assert!(!savers_history.get_intervals().is_empty());
///
/// // Get the end time
/// let end_time = savers_history.get_meta().get_end_time().timestamp() as u64;
/// let savers_history = midgard.get_savers_units_and_depth_history("BTC.BTC", Some(Interval::Day), Some(10), None, Some(end_time)).await.unwrap();
/// assert!(!savers_history.get_intervals().is_empty());
/// # });
/// ```
///
/// # Errors
/// todo
pub async fn get_savers_units_and_depth_history(&mut self, pool: &str, interval: Option<Interval>, count: Option<usize>, to: Option<u64>, from: Option<u64>) -> Result<SaversHistory> {
// Wait for rate limit timer
self.sleep_until_ok_to_call().await;
self.set_last_call(Utc::now());
api_get_savers_units_and_depth_history(self.get_config().get_base_url(), pool, interval, count, to, from).await
}
/// Returns swap count, volume, fees, slip in specified interval. If pool is not specified returns for all pools
///
/// History endpoint has two modes:
/// * With Interval parameter it returns a series of time buckets. From and To dates will be rounded to the Interval boundaries.
/// * Without Interval parameter a single From..To search is performed with exact timestamps.
/// * Interval: possible values: 5min, hour, day, week, month, quarter, year.
/// * count: [1..400]. Defines number of intervals. Don't provide if Interval is missing.
/// * from/to: optional int, unix second.
///
/// Possible usages with interval.
/// * last 10 days: ?interval=day&count=10
/// * last 10 days before to: ?interval=day&count=10&to=1608825600
/// * next 10 days after from: ?interval=day&count=10&from=1606780800
/// * Days between from and to. From defaults to start of chain, to defaults to now. Only the first 400 intervals are returned: interval=day&from=1606780800&to=1608825600
///
/// Pagination is possible with from&count and then using the returned meta.endTime as the From parameter of the next query.
///
/// Possible configurations without interval:
/// * exact search for one time frame: ?from=1606780899&to=1608825600
/// * one time frame until now: ?from=1606780899
/// * from chain start until now: no query parameters
///
/// # Example
/// ```rust
/// use midgard_rs::Midgard;
/// use midgard_rs::Interval;
///
/// # tokio_test::block_on(async {
/// // Create a new instance of Midgard
/// let mut midgard = Midgard::new();
/// // Get swaps history
/// let swaps_history = midgard.get_swaps_history(None, Some(Interval::Day), Some(10), None, None).await.unwrap();
/// assert!(!swaps_history.get_intervals().is_empty());
/// # });
/// ```
///
/// To get paginated responses, you can pass the `end_time` from the previous response to the next request.
/// ```rust
/// use midgard_rs::Midgard;
/// use midgard_rs::Interval;
///
/// # std::thread::sleep(std::time::Duration::from_secs(10));
/// # tokio_test::block_on(async {
/// // Create a new instance of Midgard
/// let mut midgard = Midgard::new();
/// // Get swaps history
/// let swaps_history = midgard.get_swaps_history(None, Some(Interval::Day), Some(10), None, None).await.unwrap();
/// assert!(!swaps_history.get_intervals().is_empty());
///
/// // Get the end time
/// let end_time = swaps_history.get_meta().get_end_time().timestamp() as u64;
/// let swaps_history = midgard.get_swaps_history(None, Some(Interval::Day), Some(10), None, Some(end_time)).await.unwrap();
/// assert!(!swaps_history.get_intervals().is_empty());
/// # });
/// ```
///
/// # Errors
/// todo
pub async fn get_swaps_history(&mut self, pool: Option<&str>, interval: Option<Interval>, count: Option<usize>, to: Option<u64>, from: Option<u64>) -> Result<SwapHistory> {
// Wait for rate limit timer
self.sleep_until_ok_to_call().await;
api_get_swaps_history(self.get_config().get_base_url(), pool, interval, count, to, from).await
}
/// Returns total pool depths, total bonds, and total value locked in specified interval.
///
/// Total Value Locked = Total Bonds + 2 * Total Pool Depths
///
/// History endpoint has two modes:
/// * With Interval parameter it returns a series of time buckets. From and To dates will be rounded to the Interval boundaries.
/// * Without Interval parameter a single From..To search is performed with exact timestamps.
/// * Interval: possible values: 5min, hour, day, week, month, quarter, year.
/// * count: [1..400]. Defines number of intervals. Don't provide if Interval is missing.
/// * from/to: optional int, unix second.
///
/// Possible usages with interval.
/// * last 10 days: ?interval=day&count=10
/// * last 10 days before to: ?interval=day&count=10&to=1608825600
/// * next 10 days after from: ?interval=day&count=10&from=1606780800
/// * Days between from and to. From defaults to start of chain, to defaults to now. Only the first 400 intervals are returned: interval=day&from=1606780800&to=1608825600
///
/// Pagination is possible with from&count and then using the returned meta.endTime as the From parameter of the next query.
///
/// Possible configurations without interval:
/// * exact search for one time frame: ?from=1606780899&to=1608825600
/// * one time frame until now: ?from=1606780899
/// * from chain start until now: no query parameters
///
/// # Example
/// ```rust
/// use midgard_rs::Midgard;
/// use midgard_rs::Interval;
///
/// # tokio_test::block_on(async {
/// // Create a new instance of Midgard
/// let mut midgard = Midgard::new();
/// // Get total value locked history
/// let tvl_history = midgard.get_total_value_locked_history(Some(Interval::Day), Some(10), None, None).await.unwrap();
/// assert!(!tvl_history.get_intervals().is_empty());
/// # });
/// ```
///
/// To get paginated responses, you can pass the `end_time` from the previous response to the next request.
/// ```rust
/// use midgard_rs::Midgard;
/// use midgard_rs::Interval;
///
/// # std::thread::sleep(std::time::Duration::from_secs(10));
/// # tokio_test::block_on(async {
/// // Create a new instance of Midgard
/// let mut midgard = Midgard::new();
/// // Get total value locked history
/// let tvl_history = midgard.get_total_value_locked_history(Some(Interval::Day), Some(10), None, None).await.unwrap();
/// assert!(!tvl_history.get_intervals().is_empty());
///
/// // Get the end time
/// let end_time = tvl_history.get_meta().get_end_time().timestamp() as u64;
/// let tvl_history = midgard.get_total_value_locked_history(Some(Interval::Day), Some(10), None, Some(end_time)).await.unwrap();
/// assert!(!tvl_history.get_intervals().is_empty());
/// # });
/// ```
///
/// # Errors
/// todo
pub async fn get_total_value_locked_history(&mut self, interval: Option<Interval>, count: Option<usize>, to: Option<u64>, from: Option<u64>) -> Result<TVLHistory> {
// Wait for rate limit timer
self.sleep_until_ok_to_call().await;
self.set_last_call(Utc::now());
api_get_total_value_locked_history(self.get_config().get_base_url(), interval, count, to, from).await
}
}
#[cfg(test)]
mod tests {
use serde_json::json;
use super::*;
#[tokio::test]
async fn test_get_depth_and_price_history() {
// Create a new instance of Midgard
let mut midgard = Midgard::new();
// Get depth & price history
let depth_history = midgard.get_depth_and_price_history("BTC.BTC", Some(Interval::Day), Some(10), None, None).await.unwrap();
println!("depth history: {}", json!(depth_history));
assert!(!depth_history.get_intervals().is_empty());
}
#[tokio::test]
async fn test_get_depth_and_price_history_pagination() {
// Create a new instance of Midgard
let mut midgard = Midgard::new();
// Get depth & price history
let depth_history = midgard.get_depth_and_price_history("BTC.BTC", Some(Interval::Day), Some(10), None, None).await.unwrap();
println!("depth history: {}", json!(depth_history));
assert!(!depth_history.get_intervals().is_empty());
// Get the end time
let end_time = depth_history.get_meta().get_end_time().timestamp() as u64;
let depth_history = midgard.get_depth_and_price_history("BTC.BTC", Some(Interval::Day), Some(10), None, Some(end_time)).await.unwrap();
println!("depth history: {}", json!(depth_history));
assert!(!depth_history.get_intervals().is_empty());
}
#[tokio::test]
async fn test_get_earnings_history() {
// Create a new instance of Midgard
let mut midgard = Midgard::new();
// Get earnings history
let earnings_history = midgard.get_earnings_history(Some(Interval::Day), Some(10), None, None).await.unwrap();
println!("earnings history: {}", json!(earnings_history));
assert!(!earnings_history.get_intervals().is_empty());
}
#[tokio::test]
async fn test_get_earnings_history_pagination() {
// Create a new instance of Midgard
let mut midgard = Midgard::new();
// Get earnings history
let earnings_history = midgard.get_earnings_history(Some(Interval::Day), Some(10), None, None).await.unwrap();
println!("earnings history: {}", json!(earnings_history));
assert!(!earnings_history.get_intervals().is_empty());
// Get the end time
let end_time = earnings_history.get_meta().get_end_time().timestamp() as u64;
let earnings_history = midgard.get_earnings_history(Some(Interval::Day), Some(10), None, Some(end_time)).await.unwrap();
println!("earnings history: {}", json!(earnings_history));
assert!(!earnings_history.get_intervals().is_empty());
}
#[tokio::test]
async fn test_get_liquidity_change_history() {
// Create a new instance of Midgard
let mut midgard = Midgard::new();
// Get liquidity change history
let liquidity_change_history = midgard.get_liquidity_change_history("BTC.BTC", Some(Interval::Day), Some(10), None, None).await.unwrap();
println!("liquidity change history: {}", json!(liquidity_change_history));
assert!(!liquidity_change_history.get_intervals().is_empty());
}
#[tokio::test]
async fn test_get_liquidity_change_history_pagination() {
// Create a new instance of Midgard
let mut midgard = Midgard::new();
// Get liquidity change history
let liquidity_change_history = midgard.get_liquidity_change_history("BTC.BTC", Some(Interval::Day), Some(10), None, None).await.unwrap();
println!("liquidity change history: {}", json!(liquidity_change_history));
assert!(!liquidity_change_history.get_intervals().is_empty());
// Get the end time
let end_time = liquidity_change_history.get_meta().get_end_time().timestamp() as u64;
let liquidity_change_history = midgard.get_liquidity_change_history("BTC.BTC", Some(Interval::Day), Some(10), None, Some(end_time)).await.unwrap();
println!("liquidity change history: {}", json!(liquidity_change_history));
assert!(!liquidity_change_history.get_intervals().is_empty());
}
#[tokio::test]
async fn test_get_savers_units_and_depth_history() {
// Create a new instance of Midgard
let mut midgard = Midgard::new();
// Get savers units and depth history
let savers_history = midgard.get_savers_units_and_depth_history("BTC.BTC", Some(Interval::Day), Some(10), None, None).await.unwrap();
println!("savers history: {}", json!(savers_history));
assert!(!savers_history.get_intervals().is_empty());
}
#[tokio::test]
async fn test_get_savers_units_and_depth_history_pagination() {
// Create a new instance of Midgard
let mut midgard = Midgard::new();
// Get savers units and depth history
let savers_history = midgard.get_savers_units_and_depth_history("BTC.BTC", Some(Interval::Day), Some(10), None, None).await.unwrap();
println!("savers history: {}", json!(savers_history));
assert!(!savers_history.get_intervals().is_empty());
// Get the end time
let end_time = savers_history.get_meta().get_end_time().timestamp() as u64;
let savers_history = midgard.get_savers_units_and_depth_history("BTC.BTC", Some(Interval::Day), Some(10), None, Some(end_time)).await.unwrap();
println!("savers history: {}", json!(savers_history));
assert!(!savers_history.get_intervals().is_empty());
}
#[tokio::test]
async fn test_get_swaps_history() {
// Create a new instance of Midgard
let mut midgard = Midgard::new();
// Get swaps history
let swaps_history = midgard.get_swaps_history(None, Some(Interval::Day), Some(10), None, None).await.unwrap();
println!("swaps history: {}", json!(swaps_history));
assert!(!swaps_history.get_intervals().is_empty());
}
#[tokio::test]
async fn test_get_swaps_history_pagination() {
// Create a new instance of Midgard
let mut midgard = Midgard::new();
// Get swaps history
let swaps_history = midgard.get_swaps_history(None, Some(Interval::Day), Some(10), None, None).await.unwrap();
println!("swaps history: {}", json!(swaps_history));
assert!(!swaps_history.get_intervals().is_empty());
// Get the end time
let end_time = swaps_history.get_meta().get_end_time().timestamp() as u64;
let swaps_history = midgard.get_swaps_history(None, Some(Interval::Day), Some(10), None, Some(end_time)).await.unwrap();
println!("swaps history: {}", json!(swaps_history));
assert!(!swaps_history.get_intervals().is_empty());
}
#[tokio::test]
async fn test_get_total_value_locked_history() {
// Create a new instance of Midgard
let mut midgard = Midgard::new();
// Get total value locked history
let tvl_history = midgard.get_total_value_locked_history(Some(Interval::Day), Some(10), None, None).await.unwrap();
println!("tvl history: {}", json!(tvl_history));
assert!(!tvl_history.get_intervals().is_empty());
}
#[tokio::test]
async fn test_get_total_value_locked_history_pagination() {
// Create a new instance of Midgard
let mut midgard = Midgard::new();
// Get total value locked history
let tvl_history = midgard.get_total_value_locked_history(Some(Interval::Day), Some(10), None, None).await.unwrap();
println!("tvl history: {}", json!(tvl_history));
assert!(!tvl_history.get_intervals().is_empty());
// Get the end time
let end_time = tvl_history.get_meta().get_end_time().timestamp() as u64;
let tvl_history = midgard.get_total_value_locked_history(Some(Interval::Day), Some(10), None, Some(end_time)).await.unwrap();
println!("tvl history: {}", json!(tvl_history));
assert!(!tvl_history.get_intervals().is_empty());
}
}