A high-performance C++ library for retrieving financial data from Yahoo Finance, designed as a native C++ alternative to the Python yfinance library.
- Fast, native C++ implementation (significantly faster than Python)
- Low memory footprint
- Comprehensive financial data access (prices, fundamentals, earnings, etc.)
- Thread-safe design
- Robust error handling and retry logic
- Full session management with proper cookie/crumb handling
- Both static (.a) and shared (.so) library formats
This library requires the following external dependencies:
- nlohmann/json - JSON parsing
- libcurl - HTTP client functionality
- CMake - Build system (minimum version 3.15)
- A C++17 compatible compiler
sudo apt-get update
sudo apt-get install cmake libcurl4-openssl-dev nlohmann-json3-dev build-essentialbrew install cmake nlohmann-json curlmkdir build
cd build
cmake ..
make -j$(nproc)This will create both:
- Static library:
libyfinance_cpp.a - Shared library:
libyfinance_cpp.so
#include "yfconvert.h"
#include "ticker.h"
int main() {
try {
yfconvert::initialize();
// Create a ticker object
yfconvert::Ticker apple("AAPL");
// Get company info
auto info = apple.get_info();
std::cout << "Company: " << info["longName"] << std::endl;
// Get historical data
auto history = apple.history(30, "1d"); // Last 30 days, daily
// Process data...
yfconvert::cleanup();
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
return 0;
}To compile your program with the library:
g++ -std=c++17 your_program.cpp -lyfinance_cpp -lcurl -o your_program -L/path/to/libThis library aims to provide equivalent functionality to the original yfinance Python library:
- Basic ticker data (price, volume, etc.)
- Historical price data
- Company information
- Financial statements
- Earnings data
- Dividends and splits
- Institutional holders
- Options chains
- Screener functionality (planned)
The C++ implementation provides significant performance improvements over the Python version:
- Up to 5-10x faster execution for data retrieval
- Lower memory usage
- No Python interpreter overhead
- Direct system calls without GIL limitations
The library implements comprehensive error handling:
- Network timeouts and retries
- HTTP error status codes
- JSON parsing errors
- Invalid ticker symbols
- Rate limiting detection
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
- Original Python yfinance library: ranaroussi
- C++ Conversion: Created by yfinance_cpp team
This is an unofficial library for educational and research purposes. It is not affiliated with Yahoo Finance or Yahoo Inc. Please review Yahoo's terms of service before using this library in production. The authors are not responsible for any misuse of this library or violations of Yahoo's terms of service.
Yahoo, Y!Finance, and Yahoo! Finance are registered trademarks of Yahoo, Inc.