Skip to content

Commit

Permalink
complete splits endpoint implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
reubenwong97 committed Oct 20, 2023
1 parent 45d7ffa commit 62036b7
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 20 deletions.
36 changes: 18 additions & 18 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,36 @@ pub struct PaginationInfo {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct EodDataItem {
/// Exact date/time the given data was collected in ISO-8601 format.
date: DateTime<Utc>,
pub date: DateTime<Utc>,
/// Stock ticker symbol of the current data object.
symbol: String,
pub symbol: String,
/// Exchange MIC identification associated with the current data object.
exchange: String,
pub exchange: String,
/// Split factor used to adjust prices when a company splits, reverse splits or pays a
/// distribution.
split_factor: f64,
pub split_factor: f64,
/// Distribution of earnings to shareholders.
dividend: f64,
pub dividend: f64,
/// Raw opening price of the given stock ticker.
open: f64,
pub open: f64,
/// Raw high price of the given stock ticker.
high: f64,
pub high: f64,
/// Raw low price of the given stock ticker.
low: f64,
pub low: f64,
/// Raw closing price of the given stock ticker.
close: f64,
pub close: f64,
/// Raw volume of the given stock ticker.
volume: f64,
pub volume: f64,
/// Adjusted opening price of the given stock ticker.
adj_open: f64,
pub adj_open: f64,
/// Adjusted high price of the given stock ticker.
adj_high: f64,
pub adj_high: f64,
/// Adjusted low price of the given stock ticker.
adj_low: f64,
pub adj_low: f64,
/// Adjusted closing price of the given stock ticker.
adj_close: f64,
pub adj_close: f64,
/// Adjusted volume of the given stock ticker.
adj_volume: f64,
pub adj_volume: f64,
}

/// Rust representation of the JSON response from `eod` marketstack endpoint.
Expand All @@ -65,11 +65,11 @@ pub struct EodData {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SplitsDataItem {
/// Exact date/time the given data was collected in ISO-8601 format.
date: NaiveDate,
pub date: NaiveDate,
/// Split factor for that symbol on the date.
split_factor: f64,
pub split_factor: f64,
/// Stock ticker symbol of the current data object.
symbol: String,
pub symbol: String,
}

/// Rust representation of the JSON response from `splits` marketstack endpoint.
Expand Down
65 changes: 63 additions & 2 deletions tests/splits.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,66 @@
use marketstack::api::common::SortOrder;
use chrono::NaiveDate;

use marketstack::api::{splits, AsyncQuery, Query};
use marketstack::{AsyncMarketstack, EodData, Marketstack};
use marketstack::{AsyncMarketstack, Marketstack, SplitsData};

mod setup;

#[test]
#[ignore]
fn test_splits() {
let api_key = setup::setup_key();
let client = Marketstack::new_insecure("api.marketstack.com", api_key).unwrap();

let endpoint = splits::Splits::builder()
.symbol("AAPL")
.limit(3)
.unwrap()
.build()
.unwrap();
let splits_result: SplitsData = endpoint.query(&client).unwrap();

assert_eq!(splits_result.pagination.limit, 3);
assert_eq!(splits_result.pagination.offset, 0);

assert_eq!(splits_result.data.len(), 3);
}

#[tokio::test]
#[ignore]
async fn test_async_splits() {
let api_key = setup::setup_key();
let client = AsyncMarketstack::new_insecure("api.marketstack.com", api_key)
.await
.unwrap();

let endpoint = splits::Splits::builder()
.limit(3)
.unwrap()
.symbol("AAPL")
.build()
.unwrap();
let eod_result: SplitsData = endpoint.query_async(&client).await.unwrap();

assert_eq!(eod_result.pagination.limit, 3);
assert_eq!(eod_result.pagination.offset, 0);

assert_eq!(eod_result.data.len(), 3);
}

#[test]
#[ignore]
fn test_splits_date() {
let api_key = setup::setup_key();
let client = Marketstack::new_insecure("api.marketstack.com", api_key).unwrap();

let endpoint = splits::Splits::builder()
.symbol("AAPL")
.date_from(NaiveDate::from_ymd_opt(2020, 8, 29).unwrap())
.date_to(NaiveDate::from_ymd_opt(2020, 9, 2).unwrap())
.build()
.unwrap();
let splits_result: SplitsData = endpoint.query(&client).unwrap();

assert_eq!(splits_result.data.len(), 1);
assert_eq!(splits_result.data[0].split_factor, 4.0);
}

0 comments on commit 62036b7

Please sign in to comment.