fmp-rust-sdk
fmp-rust-sdk is an asynchronous Rust client for the Financial Modeling Prep Stable API. Use it to retrieve market prices, company information, and financial data with typed query options and response models.
Features
- Typed API methods: company search, quotes, profiles, financial statements, metrics, historical prices, news, calendars, ETF holdings, and economic data.
- Environment and
.envconfiguration: supplyFMP_API_KEYand optionalFMP_PLANfrom your application's chosen configuration source. - Subscription awareness: configured plan metadata and endpoint access probes, with FMP remaining authoritative about permissions.
- HTTP request handling: shared connections, configurable timeouts, and bounded retries for transient failures.
- Useful errors: request context, HTTP status, and response details, with API credentials redacted from SDK diagnostics.
- Optional WebSockets: native market streams and legacy stock, crypto, and forex feeds for eligible Premium or Ultimate accounts with FMP-approved stream grants.
- Additional endpoint access: request other Stable endpoints with your own typed models, or retrieve text and binary responses.
Supported plans
The SDK supports FMP's personal pricing plans through FMP_PLAN:
| Plan | FMP_PLAN value |
Advisory API allowance |
|---|---|---|
| Free / Basic | free or basic |
250 requests per day |
| Starter | starter |
300 requests per minute |
| Premium | premium |
750 requests per minute |
| Ultimate | ultimate |
3,000 requests per minute |
These allowances follow FMP's published pricing; actual limits and dataset access depend on your account. See that page for current subscription prices.
Quick start
Add these dependencies to your project's Cargo.toml:
[]
= "0.1.1"
= { = "1", = ["macros", "rt-multi-thread"] }
Choose either environment variables or a .env file for FMP_API_KEY and FMP_PLAN. The API key is required; FMP_PLAN defaults to free when unset or blank.
Environment variables
Set your credentials in the terminal where you run your application:
Or in PowerShell:
$env:FMP_API_KEY = "your_fmp_api_key"
$env:FMP_PLAN = "free"
Put this in src/main.rs and run cargo run:
use ;
async
Project .env file
Create a .env file in your own project's root:
FMP_API_KEY=your_fmp_api_key
FMP_PLAN=free
Add .env to your project's .gitignore, then replace the client initialization above with:
let client = from_dotenv?;
Run cargo run from your project's root so the relative .env path resolves correctly. Client::from_dotenv reads the specified file without changing process environment variables. Client::from_env reads only the process environment; it does not automatically load .env.
Subscription plan
FMP_PLAN accepts the values in Supported plans. Both configuration methods default to the free plan (Plan::Basic) when this setting is unset or blank. For a paid account, set FMP_PLAN to the plan shown in your FMP dashboard, for example FMP_PLAN=premium.
This configures the SDK's plan metadata; FMP determines actual endpoint access. FMP does not provide a documented endpoint to identify the exact billing plan, and the SDK can probe access to specific endpoints.
Usage examples
Each example below belongs inside the async main function from the quick start, after creating client. Endpoint availability, symbols, and historical coverage depend on your FMP account's permissions.
Company search
use SearchOptions;
let options = SearchOptions ;
let companies = client.search_name.await?;
for company in companies
let symbols = client.search_symbol.await?;
println!;
let profiles = client.profile_by_cik.await?;
println!;
Quotes
let quotes = client.quote.await?;
for quote in quotes
let batch = client.batch_quote.await?;
println!;
let exchange = client.exchange_quotes.await?;
println!;
let changes = client.stock_price_change.await?;
println!;
quote also accepts supported ETF, index, crypto, forex, and commodity symbols. Dedicated methods such as crypto_quotes, forex_quotes, and etf_quotes retrieve quotes for an asset category.
Company information
let profiles = client.profile.await?;
println!;
let peers = client.stock_peers.await?;
println!;
let market_cap = client.market_capitalization.await?;
println!;
let float = client.shares_float.await?;
println!;
Financial statements, metrics, and ratios
use ;
let annual = StatementOptions ;
let quarterly = StatementOptions ;
let income = client.income_statement.await?;
println!;
let balance = client.balance_sheet_statement.await?;
println!;
let cash_flow = client.cash_flow_statement.await?;
println!;
let metrics = client.key_metrics.await?;
println!;
let ratios = client.ratios.await?;
println!;
let trailing = client.income_statement_ttm.await?;
println!;
Historical and intraday prices
use ;
let dates = DateRange ;
let daily = client.historical_prices.await?;
for bar in daily
let intraday = client
.intraday_prices
.await?;
println!;
News and earnings calendars
use ;
let news = client
.stock_news
.await?;
for article in news
let earnings = client
.earnings_calendar
.await?;
println!;
ETF holdings and market performance
let holdings = client.etf_holdings.await?;
for holding in holdings
let gainers = client.biggest_gainers.await?;
println!;
let losers = client.biggest_losers.await?;
println!;
let active = client.most_actives.await?;
println!;
let sectors = client.sector_performance.await?;
println!;
Analyst estimates and valuations
use ;
let estimates = client
.analyst_estimates
.await?;
println!;
let targets = client.price_target_consensus.await?;
println!;
let valuation = client.discounted_cash_flow.await?;
println!;
Configured plan and endpoint access
An access probe makes one real API request. It reports access to that endpoint and parameter combination separately from your configured FMP_PLAN.
use AccessOutcome;
println!;
let report = client.probe_access.await?;
match report.outcome
Invalid credentials, rate limits, and service failures return errors through ?; they do not identify a lower subscription plan.
WebSocket streaming
WebSocket support is available for eligible Premium and Ultimate plans. FMP's account guide lists WebSockets for these tiers. Actual access depends on FMP approval and the streams enabled for your account; setting FMP_PLAN or enabling the crate feature does not grant access by itself.
Enable the optional feature in Cargo.toml:
= { = "0.1.1", = ["websocket"] }
Configure only streams already approved for your account by FMP. A plan name alone does not grant streaming access. This example waits for one quote during feed hours, then unsubscribes and closes the connection:
use Duration;
use ;
let market: MarketStream = "fmp-us-equities-stream".parse?;
let entitlements = new?;
let configuration = new?;
let mut stream = client.connect_streams.await?;
stream.subscribe.await?;
loop
stream.unsubscribe.await?;
stream.close.await?;
See the crate documentation and runnable examples for more usage and legacy WebSocket authentication configuration.
Requires Rust 1.88 or later. This is an independent SDK; it is not affiliated with FMP.