Crates.io | financeapi |
lib.rs | financeapi |
version | 0.1.1 |
source | src |
created_at | 2024-03-16 14:10:42.976945 |
updated_at | 2024-03-16 17:56:23.301155 |
description | A Rust API for financeapi.net |
homepage | |
repository | https://github.com/carlocaione/financeapi |
max_upload_size | |
id | 1175658 |
size | 49,657 |
This crate provides a simple set of APIs to interface with financeapi.net to retrieve financial data for stocks, ETFs, mutual funds, etc...
To be able to use this API the user needs to register and get an API key from financeapi.net.
Currently only the following modules are available:
/v6/finance/quote
(Real time quote data for stocks, ETFs, mutuals funds, etc...)/v6/finance/autocomplete
(Get auto complete stock suggestions)The crate is using reqwest
with async
features. In a blocking /
synchronous context these functions must be called using block_on
or
equivalent (see example).
// Here goes your API key
let connector = FinanceapiConnector::new("...");
// v6/finance/quote
let quote = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(connector.quote("AAPL"))
.unwrap_or_else(|e| panic!("ERROR: {}", e));
println!(
"AAPL ({}) is currently at {} {}",
quote.long_name.unwrap_or_default(),
quote.regular_market_price.unwrap_or_default(),
quote.financial_currency.unwrap_or_default()
);
let symbol = "VWCE";
// v6/finance/autocomplete
let search = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(connector.autocomplete(symbol))
.unwrap_or_else(|e| panic!("ERROR: {}", e));
println!("\nFound {} results for {}", search.len(), symbol);
for (i, v) in search.iter().enumerate() {
println!("{}: {} ({})", i, v.symbol, v.name);
}