Module marketstack::api
source · Expand description
API endpoint structures.
The types in this module are meant to aid in constructing the appropriate calls using type-safe Rust idioms.
All endpoints use the builder pattern and have their members as private so that there are no API implications of adding new members for additional query parameters in future Marketstack releases.
Example
use serde::{Deserialize, Serialize};
use marketstack::Marketstack;
use marketstack::api::{self, Query};
use marketstack::api::eod;
use marketstack::{PaginationInfo, EodDataItem};
// The return type of an `EodData`. Note that Marketstack may contain more information, but you can
// define your structure to only fetch what is needed.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct EodData {
pub pagination: PaginationInfo,
pub data: Vec<EodDataItem>,
}
// Create the client.
let client = Marketstack::new("api.marketstack.com", "private-token").unwrap();
// OR create an insecure token (if on the Free plan).
let client = Marketstack::new_insecure("api.marketstack.com", "private-token").unwrap();
// Create a simple endpoint. This one gets the "eod" for the AAPL symbol.
let endpoint = eod::Eod::builder().symbol("AAPL").build().unwrap();
// Call the endpoint. The return type decides how to represent the value.
let eod_date: EodData = endpoint.query(&client).unwrap();
// Some endpoints support pagination. Since Marketstack does pagination through query
// params, we simply specify them in the endpoint builder.
// Note that there are limits defined, and therefore, limit(5) is fallible and returns
// a Result.
let pageable_endpoint = eod::Eod::builder().symbol("AAPL").limit(5).unwrap().build().unwrap();
Re-exports
pub use self::paged::PageLimit;
Modules
- API types common to many endpoints.
- Implementation of the
currencies
API endpoint. - Implementation of the
dividends
API endpoint. - Endpoint prelude
- Implemented endpoints for
eod
,eod/latest
andeod/[date]
. - Pagination related types and functions.
- Implementation of the
splits
API endpoint. - Implemented for
tickers
and associated endpoints. - Implementation of the
timezones
API endpoint.
Structs
- A structure for form parameters.
- A query modifier that ignores the data returned from an endpoint.
- A structure for query parameters.
- A query modifier that returns the raw data from the endpoint.
Enums
- Errors which may occur when using API endpoints.
- Errors which may occur when creating form data.
Traits
- A trait representing an asynchronous client which can communicate with a Marketstack instance.
- A trait which represents an asynchronous query which may be made to a Marketstack client.
- A trait representing a client which can communicate with a Marketstack instance.
- A trait for providing the necessary information for a single REST API endpoint.
- A trait representing a parameter value.
- A trait which represents a query which may be made to a Marketstack client.
- A trait representing a client which can communicate with a Marketstack instance via REST.
Functions
- Ignore the resulting data from an endpoint.
- Return the raw data from the endpoint.