A real-time stock market tracking application with Alpha Vantage API integration, featuring mock data fallback and elegant portfolio monitoring interface.
StockPortfolioMonitor is a financial tracking app that monitors stock prices in real-time using the Alpha Vantage API. The app demonstrates professional API integration, error handling with graceful fallback to mock data, and modern SwiftUI design patterns for displaying financial information.
- Real-Time Stock Prices: Live price updates via Alpha Vantage API
- Mock Data Fallback: 20 pre-configured popular stocks for offline/demo mode
- Pull-to-Refresh: Manual price updates
- Change Indicators: Visual up/down price change display
- Add/Remove Stocks: Portfolio customization by stock symbol
- Stock Limit Tracking: Monitor API usage limits
- Error Handling: Graceful degradation when API is unavailable
- Framework: SwiftUI
- Networking: URLSession with async/await
- API: Alpha Vantage Financial Data API
- iOS Version: iOS 15+
- Architecture: MVVM with StockService and StockListViewModel
- Concurrency: Swift async/await patterns
This project demonstrates:
- RESTful API integration
- Async/await networking patterns
- JSON decoding with Codable
- MVVM architecture
- Error handling strategies
- Mock data for testing/fallback
- Pull-to-refresh implementation
StockPortfolioMonitor/
├── Models/
│ └── Stock.swift # Stock data model
├── Services/
│ └── StockService.swift # API integration
├── ViewModels/
│ └── StockListViewModel.swift # Business logic
├── Views/
│ ├── ContentView.swift # Main stock list
│ └── StockRowView.swift # Individual stock display
└── StockPortfolioMonitorApp.swift
// Endpoint: https://www.alphavantage.co/query
// Function: GLOBAL_QUOTE
// Symbol: Stock ticker (e.g., AAPL, GOOGL)Pre-configured stocks for demo/offline mode:
- Tech: AAPL, GOOGL, MSFT, AMZN, META, TSLA
- Finance: JPM, BAC, GS
- Retail: WMT, HD
- Entertainment: DIS, NFLX
- Others: JNJ, PG, KO, PEP, NKE, NVDA, AMD
class StockService {
private let apiKey = "YOUR_API_KEY"
private let baseURL = "https://www.alphavantage.co/query"
func fetchStockPrice(symbol: String) async throws -> Stock {
// API call implementation
// JSON parsing
// Error handling
}
func getMockStock(symbol: String) -> Stock {
// Fallback mock data
}
}ViewModel handles business logic, API calls, and state management, keeping views clean and testable.
Modern Swift concurrency for clean asynchronous code without callback hell.
- RESTful API consumption
- Swift Concurrency (async/await)
- Codable protocol for JSON parsing
- MVVM architectural pattern
- Error handling and recovery
- Network state management
- Pull-to-refresh UI pattern
- Mock data strategies
struct Stock: Identifiable, Codable {
let id: UUID
let symbol: String
let price: Double
let change: Double
let changePercent: Double
}- Success: Display real-time data
- API Limit: Fallback to mock data
- Network Error: Show cached/mock data
- Invalid Symbol: Error message
- Personal stock portfolio tracking
- Financial app prototypes
- API integration learning
- Real-time data display patterns
- Investment monitoring
- Free Tier: 5 API calls per minute, 500 per day
- Rate Limiting: Implemented with graceful fallback
- Mock Mode: Allows unlimited testing
- Historical price charts with Charts framework
- Portfolio value calculation
- News integration for stock symbols
- Price alerts and notifications
- Multiple currency support
- Favorites/watchlist organization
- Detailed stock information view
- Performance analytics dashboard
- Get free API key from Alpha Vantage
- Replace
YOUR_API_KEYinStockService.swift - Build and run
Note: App works in mock mode without API key for demonstration purposes.
Author: Martynas Prascevicius Contact: mpcode@icloud.com Purpose: Learning project demonstrating API integration and financial data handling