A high-performance financial data API built with Rust and Actix-Web, providing real-time stock quotes, historical data, financial statements, news, and more from Yahoo Finance.
This is a Cargo workspace containing:
finance-query-core- Reusable library crate for Yahoo Finance data fetching (crates.io)- Root crate - REST API and WebSocket server built with Actix-Web
- π High Performance: Built with Rust and Actix-Web for maximum throughput
- π Comprehensive Data: Stock quotes, historical prices, financials, earnings, news, and more
- π Real-time WebSockets: Live updates for quotes, indices, movers, and news
- π― Type-Safe: Leverages Rust's type system for reliability
- π Rate Limiting: Built-in IP-based rate limiting with Redis
- πΎ Caching: Redis-based caching for improved performance
- π CORS Enabled: Ready for frontend integration
- π¦ Modular: Core functionality available as a standalone library
Add finance-query-core to your project:
[dependencies]
finance-query-core = "0.1.0"use finance_query_core::{YahooFinanceClient, Quote};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = YahooFinanceClient::new();
let quotes = client.fetch_quotes(&["AAPL", "MSFT"]).await?;
for quote in quotes {
println!("{}: ${}", quote.symbol, quote.regular_market_price);
}
Ok(())
}See the finance-query-core README for detailed library documentation.
- Rust 1.70+ (Rust 2024 edition)
- Redis (optional, for caching and rate limiting)
# Clone the repository
git clone https://github.com/jbradleynh/finance-query-rust.git
cd finance-query-rust
# For development
./start.sh
# Or manually
cargo run --release
# Checking for errors after making changes
cargo checkThe API will be available at:
- Development:
http://localhost:8080 - Production:
https://api.tradstry.com
All environment variables are optional. The application will run with sensible defaults if not provided.
| Variable | Description | Default |
|---|---|---|
REDIS_URL |
External Redis connection string (e.g., Sevalla Redis) | None |
RATE_LIMIT_PER_DAY |
Daily request limit per IP | 10000 |
PROXY_URL |
Proxy server URL for HTTP requests | None |
RUST_LOG |
Logging level (trace/debug/info/warn/error) | info |
GET /health- Comprehensive health checkGET /ping- Basic health check
GET /v1/quotes?symbols=AAPL,MSFT- Get stock quotesGET /v1/simple-quotes?symbols=AAPL- Simplified quotesGET /v1/historical/{symbol}- Historical price dataGET /v1/search?q=apple- Search for symbols
The historical data endpoint returns a JSON object with a data field containing Unix timestamp keys (as strings) mapping to price data objects:
{
"data": {
"1754659800": {
"open": 220.8300018310547,
"high": 231.0,
"low": 219.25,
"close": 229.3500061035156,
"volume": 113854000,
"adj_close": 228.86814880371097
},
"1754487000": {
"open": 205.6300048828125,
"high": 215.3800048828125,
"low": 205.58999633789065,
"close": 213.25,
"volume": 108483100,
"adj_close": 212.80197143554688
}
}
}Query Parameters:
range- Time range:1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,maxinterval- Data interval:1m,5m,15m,30m,1h,1d,1wk,1mo
Example:
curl "https://api.tradstry.com/v1/historical/AAPL?range=1y&interval=1d"GET /v1/indices- Market indicesGET /v1/actives- Most active stocksGET /v1/gainers- Top gainersGET /v1/losers- Top losersGET /v1/sectors- Sector performance
GET /v1/financials/{symbol}- Financial statementsGET /v1/earnings/{symbol}/calls- Earnings callsGET /v1/earnings/{symbol}/transcript- Earnings transcriptsGET /v1/holders/{symbol}/major- Major holdersGET /v1/analysis/{symbol}/recommendations- Analyst recommendations
GET /v1/news- Financial news
WS /v1/ws/quotes- Real-time quotesWS /v1/ws/indices- Real-time indicesWS /v1/ws/movers- Real-time moversWS /v1/ws/news- Real-time newsWS /v1/ws/profile/{symbol}- Real-time profile updates
See CURL_EXAMPLES.md for detailed API usage examples.
# Build the image (i don't use docker for testing personally)
docker build -t finance-query-rust:latest .
# Run with Docker Compose
docker-compose up -dSee DOCKER.md for detailed Docker deployment instructions.
- Connect your GitHub repository to Railway
- Railway will auto-detect the Rust project
- Set environment variables in Railway dashboard:
REDIS_URL(if using Redis)RATE_LIMIT_PER_DAY(optional)RUST_LOG(optional)
The application will automatically build and deploy.
- API Server: MIT License - see the LICENSE file
- finance-query-core: Apache-2.0 License - see finance-query-core/LICENSE
Contributions are welcome! Please feel free to submit issues or pull requests.
- finance-query-core - The standalone library on crates.io