StockViewer is an iOS application built with Swift and SwiftUI that provides users with real-time forex exchange rates, stock market data, news sentiment analysis, and the latest information on top-traded stocks. The app leverages both AlphaVantage and Polygon.io APIs to retrieve this data efficiently.
Features
Running the Application
Usage
Project Structure
API Services
License
- Get real-time sentiment analysis for stocks using AlphaVantage's NEWS_SENTIMENT feature.
- View a list of top gainers and losers using AlphaVantage's TOP_GAINERS_LOSERS function.
- Retrieve the previous closing price for a specific stock using the Polygon.io API.
- Fetch detailed historical stock data via Polygon.io’s TICKER DETAIL function.
- Search for stock tickers using AlphaVantage’s SYMBOL_SEARCH function.
- Check if the stock market is currently open or closed using AlphaVantage’s MARKET_STATUS function.
- Convert between two currencies using services from both the Polygon.io and AlphaVantage APIs.
-
Clone the repository:
git clone https://github.com/Ebullioscopic/StockViewer.git cd StockViewer
-
Open the project in Xcode:
open StockViewer.xcodeproj
-
Install dependencies via Swift Package Manager (SPM), which will automatically resolve and install upon opening the project.
To use this app, you must configure API keys for both AlphaVantage and Polygon.io APIs.
-
Create an
APIKeys.plist
file in your project folder. -
Add the following content to
APIKeys.plist
:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>POLYGON_API_KEY</key> <string>Your Polygon API Key</string> <key>API_kEY</key> <string>Your AlphaVantage API Key</string> </dict> </plist>
-
Replace the placeholder text with your actual API keys from:
- In the Project Navigator, right-click on the
Resources
folder (or create one if it doesn’t exist). - Select Add Files to "StockViewer" and add the newly created
APIKeys.plist
. - Ensure that the plist file is included in the correct target (
StockViewer
).
To run the app:
- Select a target device or simulator in Xcode.
- Build and run the project using
Cmd + R
or click the Play button.
- Select two currencies and input an amount to convert between them.
- The app supports conversion via both Polygon.io and AlphaVantage APIs, with fallback mechanisms in place.
- Check the latest sentiment analysis for stocks by navigating to the News Sentiment section.
- Currently, it displays sentiment for Apple Inc. (AAPL), but this can be adjusted for other stock tickers.
- View daily top-gaining and top-losing stocks using the TOP_GAINERS_LOSERS function from AlphaVantage.
- Enter a stock symbol to fetch the previous closing price from Polygon.io.
- Use keywords to search for stock symbols via the SYMBOL_SEARCH function of AlphaVantage.
- Check whether the market is open or closed via AlphaVantage's MARKET_STATUS function.
-
View Layer:
ForexView.swift
: Handles the UI for forex exchange rate conversions.StockDetailView.swift
: Displays detailed stock information.TopTradedView.swift
: Shows top gainers and losers.
-
ViewModel Layer:
ForexViewModel.swift
: Manages the logic for forex conversions.StockViewModel.swift
: Fetches and handles stock data, top-traded stocks, and ticker details.
-
Service Layer:
StockService.swift
: Contains methods for fetching data from AlphaVantage
and Polygon.io APIs.
The app relies on two APIs for stock market and financial data:
- AlphaVantage API: Provides forex data, news sentiment, top-traded stocks, stock symbol search, and market status.
- Polygon.io API: Supplies detailed stock data and previous closing prices.
- Invalid API Key: Double-check that your API keys are correctly added to the
APIKeys.plist
file. - Network Errors: Ensure your device is connected to the internet and that the API services are not down.
- Invalid URL: Ensure that the currency codes or stock symbols in your requests are valid.
This project is licensed under the MIT License. See the LICENSE file for details.