espin086 / NewsWaveMetrics

is a powerful tool for analyzing news sentiment on both national and local stories, allowing users to correlate these stories with their own uploaded metrics, starting with stock market price data. Stay ahead of the curve and make informed decisions with SentimentSync.
MIT License
1 stars 0 forks source link

Implement Feature to Fetch and Store Stock Data in SQLite Database #1

Closed espin086 closed 4 months ago

espin086 commented 5 months ago

Summary We need to implement a new feature in our project that involves fetching stock data from a financial data API and storing it into a SQLite database. The data should include the following fields for each stock: Date, Ticker, Open Price, High Price, Low Price, Closing Price, and Volume.

Detailed Description The goal of this feature is to have an automated process that can retrieve daily stock data for a predefined list of tickers and store this information in a SQLite database. This will allow us to perform historical data analysis and backtesting of trading strategies within our application.

Requirements:

Data Fields: The stock data should include the following information for each record: Date: The date of the trading session. Ticker: The stock symbol. Open Price: The price at which the stock first traded upon the opening of the exchange. High Price: The highest price at which the stock traded during the trading session. Low Price: The lowest price at which the stock traded during the trading session. Closing Price: The price at which the stock last traded upon the close of the exchange. Volume: The number of shares or contracts traded in a security or an entire market during a given period. Database Schema: The SQLite database should have a table named stock_data with columns corresponding to the data fields mentioned above.

Data Source: Please identify and integrate a reliable financial data API that provides the necessary stock data. Consider using APIs like Alpha Vantage, Yahoo Finance, or another free API that meets our data requirements. Data Update Frequency: The feature should be capable of fetching and updating the stock data in the database on a daily basis.

Error Handling: Implement error handling for cases where the API is unavailable or returns incomplete data. Documentation: Include documentation on how to set up and use this feature, including any necessary API keys or configurations.

Acceptance Criteria

The feature fetches daily stock data for the specified tickers. The stock data is accurately stored in the SQLite database according to the schema. The feature handles errors gracefully and logs any issues encountered during the data fetching process. Documentation is provided for setting up and using the feature. Please provide an estimate for the time required to implement this feature and any potential challenges or considerations we should be aware of.

ZaibyS commented 4 months ago

@espin086 Today, I conducted research and determined that utilizing the Alpha Vantage API is a suitable solution, given that its output encompasses all the necessary data fields. I have a couple of inquiries:

  1. Is there a predefined list of tickers, can you specify the ones or should I use any random ones for testing purposes?
  2. Regarding historical data, we have two options with the API: retrieving the latest 100 data points or obtaining the complete time series spanning over 20 years of historical data for a specific ticker. Which option do you think would be more suitable?
  3. To update the daily stock data, we need to manually call the API to ensure that the data is refreshed daily.

I plan to resolve this issue by Thursday and conduct end-to-end testing on Friday.

espin086 commented 4 months ago

@ZaibyS - let’s use the yfinance python library instead, here are instructions on how to do this:

https://towardsdatascience.com/how-to-get-stock-data-using-python-c0de1df17e75

2 - There is no predefined list of tikcers, you will need to make the function able to accept a singlt ticker at a time and load all data into SQLlite. You can try DIS, VTSAX, TSLA, AAPL, and NVDA please if you need some to test.

3 - We want data going back no more than 5 years so please look at the link above on how to do this.

ZaibyS commented 4 months ago

@espin086 I've resolved this task by individually fetching data for each ticker. The data retrieval spans from the current date back to five years ago. Subsequently, the acquired data is uploaded to the database. If a search is performed for a specific ticker, and we already have data in the database for that ticker up to tomorrow, the process will append a new row for the current date as well. I plan to work on documenting this task tomorrow and I will start working on the next task in parallel.

image