Async stock market technical analysis tool with real-time streaming of S&P 500 indicators
async_streams is a high-performance async Rust application that fetches real-time stock market data from Yahoo Finance and calculates technical indicators for S&P 500 companies. The tool streams analysis data continuously, making it ideal for monitoring market trends and building trading strategies.
- π Real-time Data Streaming - Continuous updates every 30 seconds for S&P 500 stocks
- π Technical Indicators - SMA (Simple Moving Average), Min/Max prices, price differences
- β‘ Async Performance - Built with Tokio for concurrent API calls and efficient streaming
- πΎ CSV Output - Structured data export for analysis and visualization
- π Automatic Retry - Resilient error handling with exponential backoff
- π― Flexible Configuration - Command-line interface for custom symbol lists and date ranges
- Rust 2021 edition or later
- Internet connection for Yahoo Finance API access
git clone https://github.com/serle/async_streams.git
cd async_streams
cargo build --releaseStream technical indicators for S&P 500 stocks (requires sp500.txt file with symbols):
cargo run --releaseOutput appears both on console and in data.csv:
period start,symbol,price,change %,min,max,30d avg
2025-01-22T10:30:00-05:00,AAPL,$150.25,2.15%,$145.00,$152.50,$148.33
Analyze specific symbols over a date range:
# Analyze Apple stock for the last 2 weeks (default)
cargo run --release -- --symbols AAPL
# Multiple symbols
cargo run --release -- --symbols "AAPL,MSFT,GOOG,TSLA"
# Custom date range
cargo run --release -- --symbols "AAPL,MSFT" \
--from "2025-01-01 00:00:00 UTC" \
--to "2025-01-31 23:59:59 UTC"The tool calculates the following metrics for each stock:
| Indicator | Description |
|---|---|
| Price | Current/latest closing price |
| Change % | Percentage change from first to last price in period |
| Period Min | Lowest price in the analysis period |
| Period Max | Highest price in the analysis period |
| 30d SMA | 30-day Simple Moving Average |
The system uses a trait-based architecture for easy extensibility:
#[async_trait]
pub trait AsyncStockSignal {
type SignalType;
async fn calculate(&self, data: &[f64]) -> Option<Self::SignalType>;
}Available implementations:
MinPrice- Find minimum price in seriesMaxPrice- Find maximum price in seriesPriceDifference- Calculate absolute and relative price changesWindowedSMA- Calculate simple moving average over window
βββββββββββββββββββ
β Yahoo Finance β
β API β
ββββββββββ¬βββββββββ
β
ββββββΌβββββββββββββββββ
β Data Fetcher β
β (async/await) β
ββββββ¬βββββββββββββββββ
β
ββββββΌβββββββββββββββββ
β Signal Calculators β
β - MinPrice β
β - MaxPrice β
β - PriceDifference β
β - WindowedSMA β
ββββββ¬βββββββββββββββββ
β
ββββββΌβββββββββββββββββ
β CSV Writer β
β (data.csv) β
βββββββββββββββββββββββ
- Load S&P 500 symbol list from
sp500.txt - Every 30 seconds, spawn async tasks for each symbol
- Fetch closing prices from Yahoo Finance API
- Calculate technical indicators concurrently
- Stream results to console and CSV file
- Automatic retry on transient failures (up to 5 attempts)
Create a sp500.txt file with comma-separated stock symbols:
AAPL, MSFT, GOOGL, AMZN, META, TSLA, NVDA, JPM, V, WMT
Options:
-s, --symbols <SYMBOLS> Comma-separated stock symbols (default: AAPL,MSFT,UBER,GOOG)
-f, --from <FROM> Start date (default: 2 weeks ago)
-t, --to <TO> End date (default: now)
-h, --help Print help
-V, --version Print versionRun the comprehensive test suite:
# Run all tests
cargo test
# Test with Yahoo Finance API (requires internet)
cargo test -- --ignored
# Specific test
cargo test test_windowed_sma_calculateTest coverage includes:
- β Technical indicator calculations
- β Yahoo Finance API integration
- β Date range queries
- β Error handling and edge cases
- β Streaming signal generation
- tokio - Async runtime for concurrent operations
- tokio-stream - Stream utilities for interval-based updates
- yahoo_finance_api - Yahoo Finance data provider
- chrono - Date/time handling
- clap - Command-line argument parsing
- async-trait - Async trait support
- async-recursion - Recursive async functions for retry logic
- Concurrent API Calls - Fetches data for multiple symbols in parallel
- Efficient Streaming - Minimal memory footprint with async iterators
- Rate Limiting - 30-second intervals to respect API limits
- Resilient Retry - Exponential backoff for failed requests
period start,symbol,price,change %,min,max,30d avg
2025-01-22T10:30:00-05:00,AAPL,$150.25,2.15%,$145.00,$152.50,$148.33
2025-01-22T10:30:00-05:00,MSFT,$380.75,1.85%,$375.20,$385.00,$379.50
Real-time updates with colored formatting showing symbol, price movements, and technical indicators.
- π Algorithmic Trading - Feed data into trading algorithms
- π Market Monitoring - Track S&P 500 performance in real-time
- π Technical Analysis - Identify trends using moving averages
- π Risk Management - Monitor price volatility and ranges
- π± Alert Systems - Build notification systems for price movements
This project is licensed under the MIT License - see the LICENSE file for details.
Serle Shuman - serle.shuman@gmail.com
- Built with Rust π¦ for performance and reliability
- Powered by Yahoo Finance API
- Async runtime provided by Tokio