3 releases
| 0.1.2 | Jul 23, 2019 |
|---|---|
| 0.1.1 | Jul 21, 2019 |
| 0.1.0 | Jul 19, 2019 |
#501 in Finance
Used in 2 crates
47KB
666 lines
Crate fin_model
The purpose of this API is to construct a comprehensive data model for company and market financial information in a coherent and idiomatic manner, not of a specific service provider's API.
This model can then be populated using requests described with traits and implemented by a given service provider. Thus, clients can use the common data model with Rust-native types and idioms but switch in different providers for different data types, markets, or qualities of service.
This library only provides types and traits that can be implemented
by a Provider that executes requests for financial data such as
price quotes, analyst data, or company information. In the model
we use the term request trait to indicate a trait that contains
functions that make a request for data and which use the common
RequestResult response.
Note: in the model we use the term request trait to indicate a trait that contains functions that make a request for data and which use the common
RequestResultresponse.
Modules
::analysiscore analyst recommendations,Ratings,PriceTarget, andEPSConsensus.::classificationa type,Code<T>, and trait,ClassificationScheme<T>used to model classification schemes.::companycompany information, income and balance sheets.::marketa type,Market, and trait,MarketRegistryused to model registries for market/exchange information.::providerthe core trait implemented by providers of the request traits::quotemarket quotes,Quote,QuotePrice,PriceRange, andPriceRangeSeries.::reportingcore types for reporting functions,FinancialPeriodandFiscalPeriod.::requestresult and error types for requests.::symboltypes for market and security symbols.
A common subset of the types declared in the modules above can be
imported from the ::prelude module.
Example
The following uses the FetchPriceRangeSeries trait implemented by the
provider to retrieve the last three months price information for the
given stock symbol.
fn get_stock_price_data(provider: Provider, stock_symbol: Symbol) {
match provider.last(stock_symbol, SeriesInterval::ThreeMonths) {
Err(e) => {
println!("Call failed: {:?}", e);
}
Ok(series) => {
let mut table = Table::new();
table.add_row(row!["Date", "Open", "Low", "High", "Close", "Volume"]);
for range in series.series {
table.add_row(row![
range.date.date(),
range.data.open,
range.data.low,
range.data.high,
range.data.close,
match range.data.volume {
None => "N/A".to_string(),
Some(v) => v.to_formatted_string(&locale),
}
]);
}
table.printstd();
}
}
}
Dependencies
~3–4.5MB
~73K SLoC