Skip to content

Ebullioscopic/StockViewer

Repository files navigation

StockViewer

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.

Navigation

Features
Installation
Running the Application
Usage
Project Structure
API Services
Troubleshooting
Contributors
License

Features

  • 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.

Installation

Steps to Set Up:

  1. Clone the repository:

    git clone https://github.com/Ebullioscopic/StockViewer.git
    cd StockViewer
  2. Open the project in Xcode:

    open StockViewer.xcodeproj
  3. Install dependencies via Swift Package Manager (SPM), which will automatically resolve and install upon opening the project.

Setting Up API Keys

To use this app, you must configure API keys for both AlphaVantage and Polygon.io APIs.

  1. Create an APIKeys.plist file in your project folder.

  2. 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>
  3. Replace the placeholder text with your actual API keys from:

Adding APIKeys.plist to Xcode

  1. In the Project Navigator, right-click on the Resources folder (or create one if it doesn’t exist).
  2. Select Add Files to "StockViewer" and add the newly created APIKeys.plist.
  3. Ensure that the plist file is included in the correct target (StockViewer).

Running the Application

To run the app:

  1. Select a target device or simulator in Xcode.
  2. Build and run the project using Cmd + R or click the Play button.

Usage

  • 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.

Project Structure

  • 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.

API Services

The app relies on two APIs for stock market and financial data:

  1. AlphaVantage API: Provides forex data, news sentiment, top-traded stocks, stock symbol search, and market status.
  2. Polygon.io API: Supplies detailed stock data and previous closing prices.

Troubleshooting

Common Issues

  1. Invalid API Key: Double-check that your API keys are correctly added to the APIKeys.plist file.
  2. Network Errors: Ensure your device is connected to the internet and that the API services are not down.
  3. Invalid URL: Ensure that the currency codes or stock symbols in your requests are valid.

Contributors

Contributors

License

This project is licensed under the MIT License. See the LICENSE file for details.