Skip to content

Commit

Permalink
Rename data::v2::last_quote to last_quotes
Browse files Browse the repository at this point in the history
This change renames the data::v2::last_quote module to last_quotes to
better reflect what it can be used for. Types contained in it are
renamed accordingly.
  • Loading branch information
d-e-s-o committed Nov 15, 2022
1 parent 012f843 commit 1ab9c71
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Unreleased
----------
- Added support for historic trade retrieval via `data::v2::trades`
- Adjusted `data::v2::last_quote` module to work with multiple symbols
and renamed it to `last_quotes`


0.25.1
Expand Down
28 changes: 14 additions & 14 deletions src/data/v2/last_quote.rs → src/data/v2/last_quotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::Str;

/// A GET request to be made to the /v2/stocks/quotes/latest endpoint.
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct LastQuoteReq {
pub struct LastQuotesReq {
/// The symbols to retrieve the last quote for.
#[serde(rename = "symbols", serialize_with = "string_slice_to_str")]
pub symbols: Vec<String>,
Expand All @@ -31,25 +31,25 @@ pub struct LastQuoteReq {
}


/// A helper for initializing [`LastQuoteReq`] objects.
/// A helper for initializing [`LastQuotesReq`] objects.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[allow(missing_copy_implementations)]
pub struct LastQuoteReqInit {
/// See `LastQuoteReq::feed`.
pub struct LastQuotesReqInit {
/// See `LastQuotesReq::feed`.
pub feed: Option<Feed>,
#[doc(hidden)]
pub _non_exhaustive: (),
}

impl LastQuoteReqInit {
/// Create a [`LastQuoteReq`] from a `LastQuoteReqInit`.
impl LastQuotesReqInit {
/// Create a [`LastQuotesReq`] from a `LastQuotesReqInit`.
#[inline]
pub fn init<I, S>(self, symbols: I) -> LastQuoteReq
pub fn init<I, S>(self, symbols: I) -> LastQuotesReq
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
LastQuoteReq {
LastQuotesReq {
symbols: symbols.into_iter().map(S::into).collect(),
feed: self.feed,
}
Expand Down Expand Up @@ -83,7 +83,7 @@ pub struct Quote {
EndpointNoParse! {
/// The representation of a GET request to the
/// /v2/stocks/quotes/latest endpoint.
pub Get(LastQuoteReq),
pub Get(LastQuotesReq),
Ok => Vec<(String, Quote)>, [
/// The last quotes were retrieved successfully.
/* 200 */ OK,
Expand Down Expand Up @@ -216,7 +216,7 @@ mod tests {
let api_info = ApiInfo::from_env().unwrap();
let client = Client::new(api_info);

let req = LastQuoteReqInit::default().init(["SPY"]);
let req = LastQuotesReqInit::default().init(["SPY"]);
let quotes = client.issue::<Get>(&req).await.unwrap();
assert_eq!(quotes.len(), 1);
assert_eq!(quotes[0].0, "SPY");
Expand All @@ -232,7 +232,7 @@ mod tests {
let api_info = ApiInfo::from_env().unwrap();
let client = Client::new(api_info);

let req = LastQuoteReqInit::default().init(["MSFT", "SPY", "AAPL"]);
let req = LastQuotesReqInit::default().init(["MSFT", "SPY", "AAPL"]);
let quotes = client.issue::<Get>(&req).await.unwrap();
assert_eq!(quotes.len(), 3);

Expand All @@ -251,7 +251,7 @@ mod tests {
let api_info = ApiInfo::from_env().unwrap();
let client = Client::new(api_info);

let req = LastQuoteReqInit {
let req = LastQuotesReqInit {
feed: Some(Feed::SIP),
..Default::default()
}
Expand All @@ -274,7 +274,7 @@ mod tests {
let api_info = ApiInfo::from_env().unwrap();
let client = Client::new(api_info);

let req = LastQuoteReqInit::default().init(["ABC123"]);
let req = LastQuotesReqInit::default().init(["ABC123"]);
let err = client.issue::<Get>(&req).await.unwrap_err();
match err {
RequestError::Endpoint(GetError::InvalidInput(_)) => (),
Expand All @@ -289,7 +289,7 @@ mod tests {
let api_info = ApiInfo::from_env().unwrap();
let client = Client::new(api_info);

let req = LastQuoteReqInit::default().init(["SPY", "NOSUCHSYMBOL"]);
let req = LastQuotesReqInit::default().init(["SPY", "NOSUCHSYMBOL"]);
let quotes = client.issue::<Get>(&req).await.unwrap();
assert_eq!(quotes.len(), 1);
}
Expand Down
4 changes: 2 additions & 2 deletions src/data/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ mod unfold;

/// Definitions for retrieval of market data bars.
pub mod bars;
/// Functionality for retrieval of the most recent quote.
pub mod last_quote;
/// Functionality for retrieval of most recent quotes.
pub mod last_quotes;
/// Functionality for retrieving historic quotes.
pub mod quotes;
/// Definitions for real-time streaming of market data.
Expand Down
2 changes: 1 addition & 1 deletion src/data/v2/quotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::util::vec_from_str;
use crate::Str;

/// A quote as returned by the /v2/stocks/<symbol>/quotes endpoint.
pub use super::last_quote::Quote;
pub use super::last_quotes::Quote;


/// A collection of quotes as returned by the API. This is one page of
Expand Down

0 comments on commit 1ab9c71

Please sign in to comment.