For more details about this crate and examples, please check out the documentation.
use marketstack::eod::Eod;
use marketstack::Marketstack;
use marketstack::EodData;
use marketstack::{self, Query};
// Create the http client. If you are a paid user, use `Marketstack::new()`.
let client = Marketstack::new_insecure("api.marketstack.com", "private-token").unwrap();
// Create endpoint to query end of day data for AAPL. Corresponds to `eod` endpoint.
let endpoint = Eod::builder().symbol("AAPL").build().unwrap();
// Call the endpoint and retrieve data from Marketstack. Data is deserialized
// for you into a Rust type: `EodData`.
let eod_data: 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::builder().symbol("AAPL").limit(5).unwrap().build().unwrap();
This library implements an interface to communicate with the Marketstack API. Not all endpoints are implemented (some are paid users only of which I am not), but pull requests are welcome.
This API binding is based off Marketstack's v1 API.
The endpoints that are supported all live under the api
module. Each endpoint may be constructed conveniently using a "builder" pattern (in this case, the derive_builder
crate makes implementing this very ergonomic) to provide supported fields. To use an endpoint, you may query it using the Query
trait.
All endpoints return data types of the caller's choosing that implement serde
's Deserialize
trait. Callers should define their own structures for obtaining data from the API, though most have already been implemented for the caller. However, this provides flexibility to allow the user to adapt to newer releases of Marketstack, or to easily implement data queried from endpoints that have yet to be implemented by this crate. The user does not need to wait for this crate to implement any endpoints.
This crate evolved out of a need from a personal project to pull data from an affordable / free data provider. I noticed that one had not been created and therefore implemented this myself. While I have begun using it, I have not yet extensively tested it and certain paid endpoints could not be implemented as I did not have access and could not discern their structure from the documentation.
Therefore, I would caution users against using this for production-level projects. That said, feel free to raise issues, create pull requests or fork this repo.
This crate's design is inspired by the helpful work of the maintainers of the Gitlab
crate, as well as the illuminating blog post by Ben Boeckel.