https://github.com/kweeuhree/stock-aggregator
This repository contains a Stock Market Aggregator script built with Go
https://github.com/kweeuhree/stock-aggregator
concurrency go gochannels optimized-performance
Last synced: over 1 year ago
JSON representation
This repository contains a Stock Market Aggregator script built with Go
- Host: GitHub
- URL: https://github.com/kweeuhree/stock-aggregator
- Owner: kweeuhree
- Created: 2025-02-12T15:33:16.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-20T21:39:48.000Z (over 1 year ago)
- Last Synced: 2025-02-20T22:29:55.016Z (over 1 year ago)
- Topics: concurrency, go, gochannels, optimized-performance
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# ๐ Stock Market Aggregator
This repository contains a **Stock Market Aggregator** CLI program built with Go.
## ๐งโ๐ป About the Project
The project is designed to collect **stock market data** from free APIs (MarketStack, FMPCloud, and FinHub) and aggregate the data to show the **average price** of stocks, given a user inputs a stock ticker into a prompt.
---
### ๐ฏ Project Goal
The main goal of this project is to implement **Go-native concurrency patterns** and apply them in a real-world scenario of fetching and processing stock data.
Testing goal is to keep testing coverage above 80%.
---
### ๐ท Screen Capture
---
### ๐ Project Breakdown
**Main Program** initializes the application, sets up logging, and controls the flow between data fetching and aggregation.
- Loads environment variables (using the godotenv package).
- Initializes logging for information and error messages.
- Creates instances of the Fetcher and Aggregator modules.
- Fetches stock data by calling the Fetcher's Fetch function.
- Passes the fetched data to the Aggregator to aggregate the stock prices.
**Data Fetching** retrieves stock data from free stock market APIs, concurrently.
- Fetches stock data using multiple free APIs (such as FMP Cloud).
- Each URL request is handled concurrently using Go's goroutines, ensuring efficient data fetching.
- Errors are logged if there are any issues with the API requests.
- The Fetch method of the Fetcher returns the raw data for further processing.
**Data Aggregation** aggregates the fetched stock data.
- Receives the fetched stock data from the Fetcher.
- For now, the method only logs that aggregation is attempted (to be expanded in future development).
**Utility functions**
- Converting a slice of interfaces into a slice of maps
- Rounding a float64 to two decimals
- Pretty printing a JSON object to improve readabilty
---
### ๐งช Testing
Built-in `testing` library is used for unit and integration tests.
Current coverage: 85.9% of statements of fetcher package.
---
### ๐ Code Snippets I am excited about
RequesterParser struct allows for modularity and easy testing

Owner-consumer pattern in fetch function for improved modularity

For-select pattern for receiving channel values

Dynamic routing of values to the respective slices
