A PHP-based web application for visualizing historical stock market data (OHLCV - Open, High, Low, Close, Volume) with user authentication and persistent data storage.
Stock App provides a clean, intuitive interface for analyzing stock price movements over time. The application fetches stock data from the Tiingo API, caches it in a MariaDB database, and renders interactive candlestick charts using Plotly.js.
- User Authentication: Secure login and registration system with session management
- Stock Data Visualization: Interactive candlestick/OHLC charts powered by Plotly.js
- Unified Indicator Selector: Single dropdown for managing SMA, EMA, and RSI overlays (SMA defaults: 50 and 200)
- RSI Indicator: Selectable RSI overlays (9, 14, 21) rendered in a dedicated lower pane with 30/70 guides
- MACD Overview Pane: A narrow MACD panel below the main candlestick graph showing histogram, MACD, and signal lines
- Persistent User Drawings: Logged-in users can draw trend lines and have them saved per ticker
- Ticker Favorites: Logged-in users can save an unlimited list of favorite tickers and quickly switch symbols from the sidebar
- Intelligent Data Caching: Automatically detects gaps in historical data and fetches missing periods from Tiingo API
- Date Range Selection: Query stocks for custom date ranges with validation
- Persistent Storage: MariaDB backend for efficient data management
- Responsive UI: Mobile-friendly interface with clean, modern styling
- Language: PHP 8+ (with strict type declarations)
- Database: MariaDB
- API Provider: Tiingo (stock market data)
- Data Access: PDO with prepared statements
- HTML5
- CSS3
- JavaScript: Plotly.js for interactive charting
- Containerization: Docker & Docker Compose
- Code Quality: PHP-CS-Fixer for consistent code formatting
- Testing: PHPUnit (configured in composer.json)
- Docker 20.10+
- Docker Compose 1.29+
- Tiingo API key (free tier: https://www.tiingo.com)
git clone https://github.com/FreeCap23/stock-app.git
cd stock-appmake
This will ask for a Tiingo API key, then will build the container and run it.
- Web UI: http://localhost:8080
- PhpMyAdmin: http://localhost:8081
- Enter a stock symbol (e.g.,
AAPL) - Select start and end dates
- Choose chart type (Candlestick or OHLC)
- Use the Indicators dropdown to select SMA, EMA, and RSI periods (SMA defaults: 50 and 200)
- Click "Load Chart"
- The app fetches missing data from Tiingo and displays an interactive chart
- If logged in, use the chart drawing tools and your lines will be restored for that ticker
make test # Run PHPUnit testsCREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL
);CREATE TABLE daily_ohlcv (
id INT AUTO_INCREMENT PRIMARY KEY,
symbol VARCHAR(10) NOT NULL,
date DATE NOT NULL,
open DECIMAL(10, 4),
high DECIMAL(10, 4),
low DECIMAL(10, 4),
close DECIMAL(10, 4),
volume BIGINT,
UNIQUE KEY unique_symbol_date (symbol, date)
);CREATE TABLE user_favorites (
user_id INT NOT NULL,
symbol VARCHAR(6) NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (user_id, symbol)
);Stock data is fetched from Tiingo's daily OHLCV endpoint:
GET https://api.tiingo.com/tiingo/daily/{ticker}/prices
Key Features:
- Parameterized requests
- Automatic caching to reduce API calls
- Exception handling for network failures
- Custom date range support
- Passwords hashed with
password_hash() - Session regeneration after login
- Server-side session validation
- All user inputs sanitized with
htmlspecialchars() - Prepared statements prevent SQL injection
- Date inputs validated with
DateTime::createFromFormat()
For issues or questions, please open an issue on GitHub.
- Tiingo — stock market data provider
- Plotly.js — interactive charting library
- PHP-CS-Fixer — code quality automation