How jkabutaro/usstock-csvdownloader works
This project is a command-line tool written in .NET (C#) designed for batch downloading US stock price data in CSV format from Yahoo Finance and other sources (e.g., SBI Securities). It includes features such as parallel downloads, data validation, error handling with retry mechanisms using Polly, caching via SQLite, and multiple symbol source integrations (S&P 500, NY Dow, Buffett, etc.).
Main Components
• Command Line Interface & Entry Point: The project’s main entry (Program.cs) handles command-line arguments and initializes processing.
• Options & Configuration: The Options directory contains classes (e.g., DownloadOptions, RetryOptions) for user-specified settings and configuration parameters.
• Services Layer: This directory is central to the application’s functionality. It includes:
• StockDataService, StockDownloadManager, various cache services (e.g., BuffettCacheService, IndexCacheService, NYDCacheService, SP500CacheService).
• Specific stock data fetchers (like SBIStockFetcher and the YahooFinance related services).
• Other service helpers such as ProgressManager and the SymbolListExportService.
• Models: Contains data transfer objects (StockData, StockSymbol, etc.) and serializer contexts that are used for both data handling and CSV generation.
• Exception Handling: A dedicated directory for custom exceptions (DataParsingException, StockDataExceptions) representing error states.
• Utilities: The Utils directory provides helper functions like CacheManager, PathUtils, logger extensions, and runtime/environment checkers (e.g., DotNetRuntimeChecker, WindowsVersionChecker).
• Tests: There is a full suite of tests under USStockDownloader.Tests, covering all major services and components.
Relationships and Interactions
• The CLI receives user input and parses command-line options, which are then mapped into Options classes.
• The Services layer handles business logic—for example, the StockDownloadManager coordinates data fetching by invoking specific services (YahooFinance, SBIStockFetcher, etc.) and utilizes the caching services to store retrieved data.
• Exception handling is deeply integrated. Custom exceptions get thrown and caught across service boundaries, while error logging is managed via utilities.
• The Utils and helpers are used throughout to support operational logic, such as checking system requirements at startup, managing logs, and handling file paths.
• Output components (CSV creation and SQLite caching) interact with both the models (data structure) and the file system.
Architectural Patterns and Design Principles
• Modular Design: Each functionality (data fetching, caching, options configuration, and logging) resides in its own module.
• Separation of Concerns: Services, Models, Options, and Utils are clearly separated, making unit testing and maintenance easier.
• Error Handling & Resilience: Use of Polly (for retries with exponential backoff) is a notable pattern used for robustness.
• Test-Driven: The presence of an extensive test suite implies adherence to testing best practices.
Technologies and Frameworks
• .NET 9.0 Runtime, Windows-specific features (e.g., WindowsVersionChecker).
• Polly library for retry policies.
• SQLite for caching data.
• Standard C# and .NET libraries for HTTP requests (likely HttpClient) wrapped by HttpClientFactoryWrapper.
• GitHub Actions workflows (dotnet.yml) for continuous integration/deployment.
Key Elements
• Use clear labels for each component (e.g., "Entry Point (Program.cs)", "Command Line Options", "StockDownloadManager", "YahooFinance Service", "Cache Manager / SQLite").
• Annotations such as “Retry (Polly)” near the HTTP and data fetching services to emphasize the built-in error handling mechanism.